calc/src/Option/Parser/Base.php
2020-06-11 17:20:18 +02:00

48 lines
1.3 KiB
PHP

<?php
namespace PSC\Library\Calc\Option\Parser;
class Base
{
/** @var \PSC\Library\Calc\Option\Type\Base $element */
protected $element;
/** @var \SimpleXMLElement $node */
protected $node;
public function __construct(\SimpleXMLElement $node)
{
$this->node = $node;
}
protected function parse()
{
$this->element->setId((string)$this->node['id']);
$this->element->setName((string)$this->node['name']);
if(isset($this->node['default'])) {
$this->element->setDefault((string)$this->node['default']);
}
if(isset($this->node['require'])) {
$this->element->setRequire($this->getBoolean($this->node['require']));
}
if(isset($this->node['help'])) {
$this->element->setHelp((string)$this->node['help']);
}
if(isset($this->node['exportAjax']) && (string)$this->node['exportAjax'] == 1) {
$this->element->setIsAjaxExport(true);
}
if(isset($this->node['displayOnly']) && (string)$this->node['displayOnly'] == 1) {
$this->element->setIsDisplayOnly(true);
}
}
private function getBoolean($value)
{
if((string)$value == 'true' || (string)$value == '1') {
return true;
}
return false;
}
}