HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/otto-das.komma.pro/app/Components/Component/ComponentSaveState.php
<?php


namespace App\Components\Component;


use App\Components\ComponentArea\ComponentAreaService;

/**
 * Class ComponentSaveState
 *
 * Represents data that can be saved and loaded for a DynamicGroup.
 * must work the same as its javascript twin.
 *
 * @package App\Components\Components
 */
class ComponentSaveState implements \JsonSerializable
{
    /** @var string */
    private $version;

    /** @var integer */
    private $id;

    /** @var integer */
    private $componentTypeId;

    /** @var array */
    private $data;

    /** @var array */
    private $componentableData;

    /** @var int */
    private $sortOrder;

    public function __construct()
    {
        $this->version = ComponentAreaService::SAVE_VERSION;
        $this->id = null;
        $this->componentTypeId = null;
        $this->data = [];
        $this->componentableData = [];
        $this->sortOrder = null;
    }

    /**
     * Specify data which should be serialized to JSON
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
     * @return mixed data which can be serialized by <b>json_encode</b>,
     * which is a value of any type other than a resource.
     * @since 5.4.0
     */
    public function jsonSerialize()
    {
        return [
          'id' => $this->id,
          'version' => $this->version,
          'componentTypeId' => $this->componentTypeId,
          'data' => $this->data,
          'componentableData' => $this->componentableData,
          'sortOrder' => $this->sortOrder,
        ];
    }

    /**
     * Create an instance using the data from an array
     *
     * @param array $dataArray
     * @return ComponentSaveState
     */
    public static function fromArray(array $dataArray)
    {
        if(
            (!isset($dataArray['id']) || !is_numeric($dataArray['id'])) ||
            (!isset($dataArray['version']) || !is_string($dataArray['version'])) ||
            (!isset($dataArray['componentTypeId']) || !is_numeric($dataArray['componentTypeId'])) ||
            (!isset($dataArray['data']) || !is_array($dataArray['data'])) ||
            (!isset($dataArray['componentableData']) || !is_array($dataArray['componentableData'])) ||
            (!isset($dataArray['sortOrder']) || !is_numeric($dataArray['sortOrder']))
        ) throw new \InvalidArgumentException('ComponentSaveState:fromArray The given data string was not valid since its valid json must contain these properties: id (integer), version (string), componentTypeId (integer), data (array), componentableData (array), sortOrder (integer). Actual: '.print_r($dataArray, true));

        $instance = new self;

        $instance->setId($dataArray['id']);
        $instance->setVersion($dataArray['version']);
        $instance->setComponentTypeId($dataArray['componentTypeId']);
        $instance->setData($dataArray['data']);
        $instance->setAttributeableData($dataArray['componentableData']);
        $instance->setSortOrder($dataArray['sortOrder']);

        return $instance;
    }

    /**
     * @return string
     */
    public function getVersion(): string
    {
        return $this->version;
    }

    /**
     * @param string $version
     * @return ComponentSaveState
     */
    public function setVersion(string $version): ComponentSaveState
    {
        $this->version = $version;
        return $this;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @param int $id
     * @return ComponentSaveState
     */
    public function setId(int $id): ComponentSaveState
    {
        $this->id = $id;
        return $this;
    }

    /**
     * @return int
     */
    public function getComponentTypeId(): int
    {
        return $this->componentTypeId;
    }

    /**
     * @param int $dynamicGroupTypeId
     * @return ComponentSaveState
     */
    public function setComponentTypeId(int $dynamicGroupTypeId): ComponentSaveState
    {
        $this->componentTypeId = $dynamicGroupTypeId;
        return $this;
    }

    /**
     * @return array
     */
    public function getData(): array
    {
        return $this->data;
    }

    /**
     * @param array $data
     * @return ComponentSaveState
     */
    public function setData(array $data): ComponentSaveState
    {
        $this->data = $data;
        return $this;
    }

    /**
     * @return array
     */
    public function getComponentableData(): array
    {
        return $this->componentableData;
    }

    /**
     * @param array $data
     * @return ComponentSaveState
     */
    public function setAttributeableData(array $data): ComponentSaveState
    {
        $this->componentableData = $data;
        return $this;
    }

    /**
     * @return int
     */
    public function getSortOrder(): int
    {
        return $this->sortOrder;
    }

    /**
     * @param int $sortOrder
     * @return ComponentSaveState
     */
    public function setSortOrder(int $sortOrder): ComponentSaveState
    {
        $this->sortOrder = $sortOrder;
        return $this;
    }
}