File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/Dynamic/ComponentArea/ComponentAreaSaveState.php
<?php
namespace App\Komma\Dynamic\ComponentArea;
use App\Komma\Dynamic\Component\ComponentSaveState;
/**
* Class DynamicGroupsSectionSaveState
*
* Represents data that can be saved and loaded for a component area.
* the same as its javascript twin.
*/
class ComponentAreaSaveState implements \JsonSerializable
{
/**
* @var ComponentSaveState[]
*/
private $componentSaveStates;
public function __construct()
{
$this->componentSaveStates = [];
}
/**
* 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 $this->componentSaveStates;
}
/**
* @param string $json
* @return ComponentAreaSaveState
*/
public static function fromJsonString(string $json)
{
$dataArray = json_decode($json, true);
if ($dataArray === null) {
throw new \InvalidArgumentException('DynamicGroupsSectionSaveState:fromString The given data string could not be decoded since it was no json string: '.$json);
}
$instance = new self;
$componentAreaCount = count($dataArray);
for ($index = 0; $index < $componentAreaCount; $index++) {
$currentDynamicGroupSaveStateArray = $dataArray[$index];
$currentDynamicGroupSaveState = ComponentSaveState::fromArray($currentDynamicGroupSaveStateArray);
$instance->componentSaveStates[] = $currentDynamicGroupSaveState;
}
return $instance;
}
/**
* @param ComponentSaveState $dynamicGroupSaveState
*/
public function addComponentSaveState(ComponentSaveState $dynamicGroupSaveState)
{
$this->componentSaveStates[] = $dynamicGroupSaveState;
}
/**
* @param int $index
* @return ComponentSaveState|mixed
*/
public function getComponentSaveStateAt(int $index)
{
return $this->componentSaveStates[$index];
}
/**
* @return int
*/
public function getComponentsCount()
{
return count($this->componentSaveStates);
}
/**
* @return ComponentSaveState[]|array
*/
public function getComponentSaveStates()
{
return $this->componentSaveStates;
}
}