calc/src/Option/Parser/Input.php
2025-06-24 11:57:42 +02:00

62 lines
1.8 KiB
PHP

<?php
namespace PSC\Library\Calc\Option\Parser;
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
use PSC\Library\Calc\Option\Type\Input as PSCInput;
class Input extends Base
{
public function __construct()
{
$this->element = new \PSC\Library\Calc\Option\Type\Input();
}
public function parseJson(): PSCInput
{
parent::parseJson();
if(isset($this->json['placeHolder'])) {
$this->element->setPlaceHolder((string)$this->json['placeHolder']);
}
if(isset($this->json['dependencys']) && count($this->json['dependencys']) > 0) {
$edgeCollectionContainerParser = new EdgeCollectionContainer();
$edgeCollectionContainerParser->fromJson($this->json['dependencys']);
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseJson());
}
return $this->element;
}
public function parseXML(): PSCInput
{
parent::parseXML();
if(isset($this->node['min'])) {
$this->element->setMinValue((int)$this->node['min']);
}
if(isset($this->node['max'])) {
$this->element->setMaxValue((int)$this->node['max']);
}
if(isset($this->node['pattern'])) {
$this->element->setPattern((string)$this->node['pattern']);
}
if(isset($this->node['placeholder'])) {
$this->element->setPlaceHolder((string)$this->node['placeholder']);
}
if($this->node->children()) {
$edgeCollectionContainerParser = new EdgeCollectionContainer();
$edgeCollectionContainerParser->fromXML($this->node);
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
}
return $this->element;
}
}