json <-> xml
This commit is contained in:
parent
f7e6247427
commit
ef25403e42
File diff suppressed because one or more lines are too long
8
bin/console
Executable file
8
bin/console
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
$application = new PSC\Library\Calc\ConsoleApplication();
|
||||
$application->build();
|
||||
$application->run();
|
||||
@ -17,10 +17,13 @@
|
||||
"doctrine/orm": "^2.5",
|
||||
"azuyalabs/yasumi": "^2.5",
|
||||
"bitandblack/colors": "2.13.0",
|
||||
"symfony/cache": "^6.4"
|
||||
"symfony/cache": "^6.4",
|
||||
"spatie/array-to-xml": "^3.4",
|
||||
"symfony/console": "^7.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9",
|
||||
"phpunit/php-code-coverage": "^9"
|
||||
"phpunit/phpunit": "^12",
|
||||
"phpunit/php-code-coverage": "^12",
|
||||
"brianium/paratest": "^7"
|
||||
}
|
||||
}
|
||||
|
||||
1277
composer.lock
generated
1277
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -9,8 +9,9 @@ use PSC\Library\Calc\PreCalc\PreCalc;
|
||||
|
||||
class Article
|
||||
{
|
||||
/** @var string $name */
|
||||
protected $name;
|
||||
protected string $name;
|
||||
|
||||
protected string $uuid;
|
||||
|
||||
protected string $comment = "";
|
||||
|
||||
@ -22,12 +23,13 @@ class Article
|
||||
|
||||
protected PreCalc $preCalc;
|
||||
|
||||
public function __construct($name)
|
||||
public function __construct($name, $uuid = "")
|
||||
{
|
||||
$this->options = new \ArrayIterator();
|
||||
$this->displayGroups = new \ArrayIterator();
|
||||
$this->preCalc = new PreCalc();
|
||||
$this->setName($name);
|
||||
$this->setUUID($uuid);
|
||||
}
|
||||
|
||||
public function setPreCalc(PreCalc $preCalc)
|
||||
@ -80,22 +82,26 @@ class Article
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getUUID(): ?string
|
||||
{
|
||||
return $this->uuid;
|
||||
}
|
||||
|
||||
public function setUUID(?string $uuid): void
|
||||
{
|
||||
$this->uuid = $uuid;
|
||||
}
|
||||
|
||||
public function getOptionById($id): ?Base
|
||||
{
|
||||
if($id === false) {
|
||||
@ -171,4 +177,28 @@ class Article
|
||||
}
|
||||
return $temp;
|
||||
}
|
||||
|
||||
public function generateXML(): array
|
||||
{
|
||||
$options = $this->options;
|
||||
$tmp = ['option' => function () use ($options) {
|
||||
$xml_options = [];
|
||||
foreach ($options as $option) {
|
||||
$xml_options[] = $option->generateXML();
|
||||
}
|
||||
|
||||
return $xml_options;
|
||||
}];
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
public function generateJson(): array
|
||||
{
|
||||
$tmp = [];
|
||||
foreach($this->options as $option) {
|
||||
$tmp[] = $option->generateJson();
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
74
src/Command/Convert.php
Normal file
74
src/Command/Convert.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Command;
|
||||
|
||||
use PSC\Library\Calc\Engine;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(name: 'app:convert')]
|
||||
class Convert extends Command {
|
||||
|
||||
public function __construct(private string $from = "", private string $to = "")
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setDescription('Convert beetween formats.')
|
||||
->setHelp('converts between formats')
|
||||
->addArgument('from', InputArgument::REQUIRED, 'from file')
|
||||
->addArgument('to', InputArgument::REQUIRED, 'to file')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$output->writeln([
|
||||
'Convert',
|
||||
'============',
|
||||
'',
|
||||
]);
|
||||
|
||||
$output->writeln('From: '.$input->getArgument('from'));
|
||||
$output->writeln('To: '.$input->getArgument('to'));
|
||||
|
||||
$from = $input->getArgument('from');
|
||||
$to = $input->getArgument('to');
|
||||
|
||||
if(!file_exists($from)) {
|
||||
$io->error("from file not found");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if(file_exists($to)) {
|
||||
$helper = $this->getHelper('question');
|
||||
$question = new ConfirmationQuestion('To File exists continue?', false, '/^(y|j)/i');
|
||||
|
||||
if (!$helper->ask($input, $output, $question)) {
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
$engine = new Engine();
|
||||
if(strpos($from, "xml") !== false) {
|
||||
$engine->loadString(file_get_contents($from));
|
||||
}else{
|
||||
$engine->loadJson(file_get_contents($from));
|
||||
}
|
||||
|
||||
if(strpos($to, "xml") !== false) {
|
||||
file_put_contents($to, $engine->generateXML());
|
||||
}else{
|
||||
file_put_contents($to, $engine->generateJson());
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
13
src/ConsoleApplication.php
Normal file
13
src/ConsoleApplication.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc;
|
||||
|
||||
use PSC\Library\Calc\Command\Convert;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
class ConsoleApplication extends Application {
|
||||
|
||||
public function build(): void
|
||||
{
|
||||
$this->add(new Convert());
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc;
|
||||
|
||||
use Spatie\ArrayToXml\ArrayToXml;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use PSC\Library\Calc\Calc\Calc;
|
||||
use PSC\Library\Calc\Calc\CalcValues;
|
||||
@ -15,11 +16,11 @@ use PSC\Library\Calc\Option\Type\Text;
|
||||
class Engine
|
||||
{
|
||||
|
||||
/** @var \SimpleXMLElement $xml */
|
||||
protected $xml;
|
||||
protected ?\SimpleXMLElement $xml = null;
|
||||
|
||||
/** @var \ArrayIterator $articles */
|
||||
protected $articles;
|
||||
protected ?array $json = null;
|
||||
|
||||
protected \ArrayIterator $articles;
|
||||
|
||||
/** @var PaperContainer $paperContainer */
|
||||
protected $paperContainer;
|
||||
@ -83,22 +84,24 @@ class Engine
|
||||
|
||||
protected $savedCalcValues = [];
|
||||
|
||||
/**
|
||||
* Load XML From String
|
||||
*
|
||||
* @param $string XML String
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function loadString($string)
|
||||
public function loadJson($string): bool
|
||||
{
|
||||
$this->articles = new \ArrayIterator();
|
||||
$this->json = json_decode($string, true);
|
||||
$this->activeArticle = false;
|
||||
$this->calcVariables = [];
|
||||
$this->variables = [];
|
||||
return $this->parse();
|
||||
}
|
||||
|
||||
public function loadString($string): bool
|
||||
{
|
||||
$this->articles = new \ArrayIterator();
|
||||
$this->xml = simplexml_load_string($string);
|
||||
$this->activeArticle = false;
|
||||
$this->calcVariables = [];
|
||||
$this->variables = [];
|
||||
$this->parse();
|
||||
return true;
|
||||
return $this->parse();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,11 +115,19 @@ class Engine
|
||||
if($this->templates) {
|
||||
$parser->setTemplates($this->templates);
|
||||
}
|
||||
foreach ($this->xml as $article) {
|
||||
$this->articles->append($parser->parse($article));
|
||||
if($this->xml) {
|
||||
foreach ($this->xml as $article) {
|
||||
$this->articles->append($parser->parseXML($article));
|
||||
|
||||
}
|
||||
}elseif($this->json){
|
||||
foreach ($this->json as $article) {
|
||||
$this->articles->append($parser->parseJson($article));
|
||||
}
|
||||
}
|
||||
|
||||
$this->dirty = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -654,4 +665,27 @@ class Engine
|
||||
$calcFormel = new Calc($this, $this->article);
|
||||
$this->price = $calcFormel->calc();
|
||||
}
|
||||
|
||||
public function generateXML(): string
|
||||
{
|
||||
|
||||
$tmp = ['artikel' => array_merge([
|
||||
'name' => $this->getArticle()->getName(),
|
||||
'uuid' => $this->getArticle()->getUUID(),
|
||||
'kommentar' => ''
|
||||
], $this->getArticle()->generateXML())];
|
||||
|
||||
return ArrayToXml::convert($tmp, 'kalkulation');
|
||||
}
|
||||
|
||||
public function generateJson(): string
|
||||
{
|
||||
|
||||
$obj = new \stdClass();
|
||||
$obj->uuid = $this->getArticle()->getUUID();
|
||||
$obj->name = $this->getArticle()->getName();
|
||||
$obj->options = $this->getArticle()->generateJson();
|
||||
|
||||
return json_encode([$obj]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,21 +9,48 @@
|
||||
|
||||
namespace PSC\Library\Calc\General\Parser;
|
||||
|
||||
use PSC\Library\Calc\General\Type\Edge as PSCEdge;
|
||||
|
||||
|
||||
class Edge
|
||||
{
|
||||
/** @var \SimpleXMLElement $node */
|
||||
protected $node;
|
||||
protected \SimpleXMLElement $node;
|
||||
|
||||
public function __construct($node)
|
||||
protected array $json;
|
||||
|
||||
public function fromXML(\SimpleXMLElement $node): void
|
||||
{
|
||||
$this->node = $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \PSC\Library\Calc\General\Type\Edge
|
||||
*/
|
||||
public function parse()
|
||||
public function fromJson(array $json): void
|
||||
{
|
||||
$this->json = $json;
|
||||
}
|
||||
|
||||
public function parseJson(): PSCEdge
|
||||
{
|
||||
$edge = new \PSC\Library\Calc\General\Type\Edge();
|
||||
if (isset($this->json['formula'])) {
|
||||
$edge->setFormel((string)$this->json['formula']);
|
||||
}
|
||||
if (isset($this->json['calcValue'])) {
|
||||
$edge->setCalcValue((string)$this->json['calcValue']);
|
||||
}
|
||||
|
||||
$this->parseCondition($edge, trim($this->json['value']));
|
||||
if (isset($this->json['dependencys']) && count($this->json['dependencys']) > 0) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromJson($this->json['dependencys']);
|
||||
$edge->setEdgesCollectionContainer($edgeCollectionContainerParser->parseJson());
|
||||
}
|
||||
|
||||
return $edge;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function parseXML(): PSCEdge
|
||||
{
|
||||
$edge = new \PSC\Library\Calc\General\Type\Edge();
|
||||
if (isset($this->node->attributes()->formel)) {
|
||||
@ -72,8 +99,9 @@ class Edge
|
||||
if (isset($this->node->attributes()->value) && $this->node->children()) {
|
||||
$this->parseCondition($edge, trim((string) $this->node->attributes()->value));
|
||||
if ($this->node->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
|
||||
$edge->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromXML($this->node);
|
||||
$edge->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
} else {
|
||||
$this->parseCondition($edge, trim((string) $this->node));
|
||||
|
||||
@ -1,29 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: thomas
|
||||
* Date: 09.04.18
|
||||
* Time: 15:58
|
||||
*/
|
||||
|
||||
namespace PSC\Library\Calc\General\Parser;
|
||||
|
||||
use PSC\Library\Calc\General\Type\EdgeCollection as PSCEdgeCollection;
|
||||
|
||||
|
||||
class EdgeCollection
|
||||
{
|
||||
/** @var \SimpleXMLElement $node */
|
||||
protected $node;
|
||||
protected \SimpleXMLElement $node;
|
||||
|
||||
public function __construct($node)
|
||||
protected array $json;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function fromJson(array $json)
|
||||
{
|
||||
$this->json = $json;
|
||||
}
|
||||
|
||||
|
||||
public function fromXML(\SimpleXMLElement $node)
|
||||
{
|
||||
$this->node = $node;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \PSC\Library\Calc\General\Type\EdgeCollection
|
||||
*/
|
||||
public function parse()
|
||||
public function parseJson(): PSCEdgeCollection
|
||||
{
|
||||
$collection = new \PSC\Library\Calc\General\Type\EdgeCollection();
|
||||
$collection->setName((string)$this->json['relation']);
|
||||
|
||||
if(isset($this->json['formula'])) {
|
||||
$collection->setFormel((string)$this->json['formula']);
|
||||
}
|
||||
|
||||
foreach($this->json['borders'] as $border) {
|
||||
$edgeParser = new Edge();
|
||||
$edgeParser->fromJson($border);
|
||||
$edge = $edgeParser->parseJson();
|
||||
|
||||
$collection->append($edge);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function parseXML(): PSCEdgeCollection
|
||||
{
|
||||
$collection = new \PSC\Library\Calc\General\Type\EdgeCollection();
|
||||
|
||||
@ -36,12 +58,13 @@ class EdgeCollection
|
||||
}
|
||||
|
||||
foreach($this->node->grenze as $row) {
|
||||
$edgeParser = new Edge($row);
|
||||
$edge = $edgeParser->parse();
|
||||
$edgeParser = new Edge();
|
||||
$edgeParser->fromXML($row);
|
||||
$edge = $edgeParser->parseXML();
|
||||
|
||||
$collection->append($edge);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,22 +10,48 @@ namespace PSC\Library\Calc\General\Parser;
|
||||
|
||||
class EdgeCollectionContainer
|
||||
{
|
||||
/** @var \SimpleXMLElement $node */
|
||||
protected $node;
|
||||
protected \SimpleXMLElement $node;
|
||||
|
||||
public function __construct($node)
|
||||
protected array $json;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function fromJson(array $json) {
|
||||
$this->json = $json;
|
||||
}
|
||||
|
||||
public function fromXML(\SimpleXMLElement $node) {
|
||||
$this->node = $node;
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseJson()
|
||||
{
|
||||
$container = new \PSC\Library\Calc\General\Type\EdgeCollectionContainer();
|
||||
|
||||
foreach($this->json as $row) {
|
||||
$collectionParser = new EdgeCollection();
|
||||
$collectionParser->fromJson($row);
|
||||
$collection = $collectionParser->parseJson();
|
||||
|
||||
$container->append($collection);
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
public function parseXML()
|
||||
{
|
||||
$container = new \PSC\Library\Calc\General\Type\EdgeCollectionContainer();
|
||||
|
||||
foreach($this->node->children() as $key => $row) {
|
||||
$collectionParser = new EdgeCollection($row);
|
||||
|
||||
$collection = $collectionParser->parse();
|
||||
if($key == 'opt') {
|
||||
continue;
|
||||
}
|
||||
$collectionParser = new EdgeCollection();
|
||||
$collectionParser->fromXML($row);
|
||||
$collection = $collectionParser->parseXML();
|
||||
$collection->setName($key);
|
||||
|
||||
$container->append($collection);
|
||||
@ -33,4 +59,4 @@ class EdgeCollectionContainer
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,5 +383,60 @@ class Edge
|
||||
{
|
||||
$this->edgesCollectionContainer = $edgesCollectionContainer;
|
||||
}
|
||||
}
|
||||
|
||||
public function generateXML(): array
|
||||
{
|
||||
$tmp = [];
|
||||
if($this->formel != "") {
|
||||
$tmp['formel'] = $this->formel;
|
||||
}
|
||||
|
||||
if($this->pauschale != 0) {
|
||||
$tmp['pauschale'] = $this->pauschale;
|
||||
}
|
||||
|
||||
if($this->calcValue != "") {
|
||||
$tmp['calc_value'] = $this->calcValue;
|
||||
}
|
||||
|
||||
if($this->edgesCollectionContainer->count() > 0) {
|
||||
$tmp = [
|
||||
'_attributes' => array_merge([
|
||||
'value' => $this->from . '-' . ($this->to != 0 ? $this->to : '')
|
||||
], $tmp),
|
||||
];
|
||||
|
||||
foreach($this->edgesCollectionContainer as $col) {
|
||||
$tmp[$col->getName()] = $col->generateXML();
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
return [
|
||||
'_attributes' => $tmp,
|
||||
'_value' => $this->from . '-' . ($this->to != 0 ? $this->to : '')
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function generateJson(): object
|
||||
{
|
||||
$obj = new \stdClass();
|
||||
$obj->calcValue = $this->calcValue;
|
||||
$obj->flatRate = $this->pauschale!=0 ? $this->pauschale : "";
|
||||
$obj->formula = $this->formel;
|
||||
if($this->region) {
|
||||
$obj->value = $this->from . '-' . ($this->to != 0 ? $this->to : '');
|
||||
}else{
|
||||
$obj->value = implode(array: $this->values, separator: ',');
|
||||
}
|
||||
|
||||
$obj->dependencys = [];
|
||||
foreach($this->edgesCollectionContainer as $col) {
|
||||
$obj->dependencys[] = $col->generateJson();
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,5 +41,31 @@ class EdgeCollection extends \ArrayIterator
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
public function generateJson(): object
|
||||
{
|
||||
$obj = new \stdClass();
|
||||
$obj->relation = $this->getName();
|
||||
$obj->formula = $this->getFormel();
|
||||
$obj->borders = array_reduce((array)$this, function($result, $e) {
|
||||
$result[] = $e->generateJson();
|
||||
return $result;
|
||||
}, []);
|
||||
|
||||
}
|
||||
return $obj;
|
||||
|
||||
}
|
||||
public function generateXML(): array
|
||||
{
|
||||
$borders = (array)$this;
|
||||
$tmp = ['grenze' => function () use ($borders) {
|
||||
$xml_options = [];
|
||||
foreach ($borders as $border) {
|
||||
$xml_options[] = $border->generateXML();
|
||||
}
|
||||
|
||||
return $xml_options;
|
||||
}];
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,44 +13,73 @@ use PSC\Library\Calc\Option\Parser\Textarea;
|
||||
|
||||
class Parser
|
||||
{
|
||||
protected $node;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function getOptByType(\SimpleXMLElement $node)
|
||||
public function getOptByJsonType(int $type, ?string $mode = null)
|
||||
{
|
||||
$this->node = $node;
|
||||
|
||||
$obj = false;
|
||||
switch(strtolower((string)$node['type'])) {
|
||||
switch($type) {
|
||||
case 1:
|
||||
$obj = new Hidden();
|
||||
break;
|
||||
case 2:
|
||||
$obj = new Input();
|
||||
break;
|
||||
case 3:
|
||||
$obj = new Select();
|
||||
break;
|
||||
case 4:
|
||||
$obj = new Text();
|
||||
break;
|
||||
case 5:
|
||||
$obj = new Textarea();
|
||||
break;
|
||||
case 6:
|
||||
$obj = new Headline();
|
||||
break;
|
||||
case 7:
|
||||
$obj = new Checkbox();
|
||||
break;
|
||||
case 8:
|
||||
$obj = new Radio();
|
||||
break;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function getOptByType(string $type, ?string $mode = null)
|
||||
{
|
||||
$obj = false;
|
||||
switch(strtolower($type)) {
|
||||
case 'input':
|
||||
$obj = new Input($node);
|
||||
$obj = new Input();
|
||||
break;
|
||||
case 'select':
|
||||
$obj = new Select($node);
|
||||
$obj = new Select($mode);
|
||||
break;
|
||||
case 'radio':
|
||||
$obj = new Radio($node);
|
||||
$obj = new Radio();
|
||||
break;
|
||||
case 'checkbox':
|
||||
$obj = new Checkbox($node);
|
||||
$obj = new Checkbox();
|
||||
break;
|
||||
case 'headline':
|
||||
$obj = new Headline($node);
|
||||
$obj = new Headline();
|
||||
break;
|
||||
case 'text':
|
||||
$obj = new Text($node);
|
||||
$obj = new Text();
|
||||
break;
|
||||
case 'textarea':
|
||||
$obj = new Textarea($node);
|
||||
$obj = new Textarea();
|
||||
break;
|
||||
case 'hidden':
|
||||
$obj = new Hidden($node);
|
||||
$obj = new Hidden();
|
||||
break;
|
||||
case 'template':
|
||||
$obj = new Template($node);
|
||||
$obj = new Template();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Option\Parser;
|
||||
|
||||
use PSC\Library\Calc\Option\Type\Base as PSCBase;
|
||||
use SimpleXMLElement;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
|
||||
class Base
|
||||
@ -8,18 +10,51 @@ class Base
|
||||
/** @var \PSC\Library\Calc\Option\Type\Base $element */
|
||||
protected $element;
|
||||
|
||||
/** @var \SimpleXMLElement $node */
|
||||
protected $node;
|
||||
protected ?SimpleXMLElement $node;
|
||||
|
||||
protected ?array $json;
|
||||
|
||||
protected FilesystemAdapter $cache;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
$this->node = $node;
|
||||
$this->cache = new FilesystemAdapter();
|
||||
}
|
||||
|
||||
protected function parse()
|
||||
public function fromXML(\SimpleXMLElement $node) {
|
||||
$this->node = $node;
|
||||
}
|
||||
|
||||
public function fromJson(array $json) {
|
||||
$this->json = $json;
|
||||
}
|
||||
|
||||
public function toJson(): array {
|
||||
|
||||
}
|
||||
|
||||
public function toXML(): \SimpleXMLElement {
|
||||
|
||||
}
|
||||
|
||||
public function parseJson(): PSCBase
|
||||
{
|
||||
$this->element->setId((string)$this->json['id']);
|
||||
$this->element->setName((string)$this->json['name']);
|
||||
|
||||
if(isset($this->json['default'])) {
|
||||
$this->element->setDefault((string)$this->json['default']);
|
||||
}
|
||||
if(isset($this->json['required'])) {
|
||||
$this->element->setRequire($this->json['required']);
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function parseXML(): PSCBase
|
||||
{
|
||||
$this->element->setId((string)$this->node['id']);
|
||||
$this->element->setName((string)$this->node['name']);
|
||||
@ -55,6 +90,7 @@ class Base
|
||||
$this->element->setDisplayGroup((string)$this->node['display_group']);
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
private function getBoolean($value)
|
||||
|
||||
@ -3,6 +3,7 @@ namespace PSC\Library\Calc\Option\Parser;
|
||||
|
||||
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||
use PSC\Library\Calc\Option\Parser\Checkbox\Opt;
|
||||
use PSC\Library\Calc\Option\Type\Checkbox as PSCCheckbox;
|
||||
use PSC\Library\Calc\PaperContainer;
|
||||
use PSC\Library\Calc\Tests\Mock\Paper;
|
||||
|
||||
@ -11,24 +12,19 @@ class Checkbox extends Base
|
||||
|
||||
protected $element;
|
||||
|
||||
/** @var \SimpleXMLElement $node */
|
||||
protected $node;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Checkbox();
|
||||
|
||||
parent::__construct($node);
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseXML(): PSCCheckbox
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseXML();
|
||||
|
||||
if(isset($this->node->grenzen) && $this->node->grenzen->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node->grenzen);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->parseXML($this->node->grenzen);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
|
||||
$this->parseModeNormal();
|
||||
@ -44,4 +40,4 @@ class Checkbox extends Base
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,11 +21,12 @@ class Opt
|
||||
$this->element->setLabel((string)$this->node['name']);
|
||||
|
||||
if($this->node->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromXML($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,21 +2,21 @@
|
||||
namespace PSC\Library\Calc\Option\Parser;
|
||||
|
||||
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||
use PSC\Library\Calc\Option\Type\Headline as PSCHeadline;
|
||||
|
||||
class Headline extends Base
|
||||
{
|
||||
|
||||
protected $element;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Headline();
|
||||
parent::__construct($node);
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseXML(): PSCHeadline
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseXML();
|
||||
|
||||
if($this->node->data) {
|
||||
$this->element->setValue((string)$this->node->data);
|
||||
@ -32,8 +32,9 @@ class Headline extends Base
|
||||
}
|
||||
|
||||
if($this->node->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromXML($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
|
||||
@ -2,28 +2,43 @@
|
||||
namespace PSC\Library\Calc\Option\Parser;
|
||||
|
||||
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||
use PSC\Library\Calc\Option\Type\Hidden as PSCHidden;
|
||||
|
||||
class Hidden extends Base
|
||||
{
|
||||
|
||||
protected $element;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Hidden();
|
||||
parent::__construct($node);
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseJSON(): PSCHidden
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseJson();
|
||||
|
||||
if($this->node->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
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(): PSCHidden
|
||||
{
|
||||
parent::parseXML();
|
||||
|
||||
if($this->node->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromXML($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,20 +3,36 @@ namespace PSC\Library\Calc\Option\Parser;
|
||||
|
||||
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||
use PSC\Library\Calc\Option\Type\Input as PSCInput;
|
||||
use SimpleXMLElement;
|
||||
|
||||
class Input extends Base
|
||||
{
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Input();
|
||||
parent::__construct($node);
|
||||
}
|
||||
|
||||
public function parse(): PSCInput
|
||||
public function parseJson(): PSCInput
|
||||
{
|
||||
parent::parse();
|
||||
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']);
|
||||
@ -34,8 +50,9 @@ class Input extends Base
|
||||
}
|
||||
|
||||
if($this->node->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromXML($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
|
||||
@ -4,6 +4,7 @@ namespace PSC\Library\Calc\Option\Parser;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||
use PSC\Library\Calc\Option\Parser\Radio\Opt;
|
||||
use PSC\Library\Calc\Option\Type\Radio as PSCRadio;
|
||||
use PSC\Library\Calc\PaperContainer;
|
||||
use PSC\Library\Calc\Tests\Mock\Paper;
|
||||
|
||||
@ -12,20 +13,14 @@ class Radio extends Base
|
||||
|
||||
protected $element;
|
||||
|
||||
/** @var \SimpleXMLElement $node */
|
||||
protected $node;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Radio();
|
||||
|
||||
parent::__construct($node);
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseXML(): PSCRadio
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseXML();
|
||||
|
||||
if(isset($this->node->grenzen) && $this->node->grenzen->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node->grenzen);
|
||||
@ -44,5 +39,4 @@ class Radio extends Base
|
||||
$this->element->addOption($optParser->parse());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,8 +22,9 @@ class Opt
|
||||
$this->element->setLabel((string)$this->node['name']);
|
||||
|
||||
if($this->node->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromXML($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
|
||||
@ -11,19 +11,19 @@ class Row extends Base
|
||||
|
||||
protected $element;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node, private $paperContainer, private $paperRepository, private $templates)
|
||||
public function __construct(private $paperContainer, private $paperRepository, private $templates)
|
||||
{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Row();
|
||||
parent::__construct($node);
|
||||
}
|
||||
|
||||
public function parse(): PSCBase
|
||||
public function parseXML(): PSCBase
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseXML();
|
||||
|
||||
foreach($this->node->children() as $key => $node) {
|
||||
$p = new Column($node, $this->paperContainer, $this->paperRepository, $this->templates);
|
||||
$element = $p->parse();
|
||||
$p = new Column($this->paperContainer, $this->paperRepository, $this->templates);
|
||||
$p->fromXML($node);
|
||||
$element = $p->parseXML();
|
||||
$this->element->addColumn($element);
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ namespace PSC\Library\Calc\Option\Parser\Row;
|
||||
use PSC\Library\Calc\Option\Parser;
|
||||
use PSC\Library\Calc\Option\Parser\Base;
|
||||
use PSC\Library\Calc\Option\Parser\Row;
|
||||
use PSC\Library\Calc\Option\Type\Row\Column as PSCColumn;
|
||||
use PSC\Library\Calc\Option\Type\Select;
|
||||
use PSC\Library\Calc\Option\Type\Template;
|
||||
|
||||
@ -11,45 +12,46 @@ class Column extends Base
|
||||
{
|
||||
private Parser $optionParser;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node, private $paperContainer, private $paperRepository, private $templates)
|
||||
public function __construct(private $paperContainer, private $paperRepository, private $templates)
|
||||
|
||||
{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Row\Column();
|
||||
$this->node = $node;
|
||||
$this->optionParser = new \PSC\Library\Calc\Option\Parser($paperContainer, $paperRepository, $templates);
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseXML(): PSCColumn
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseXML();
|
||||
|
||||
foreach ($this->node->children() as $key => $option) {
|
||||
if($key == 'option') {
|
||||
$obj = $this->optionParser->getOptByType($option);
|
||||
$obj = $this->optionParser->getOptByType($option['type'], $option['mode']?? null);
|
||||
if($obj) {
|
||||
|
||||
$obj->fromXML($option);
|
||||
if($obj instanceof Select) {
|
||||
$obj->setPaperContainer($this->paperContainer);
|
||||
$obj->setPaperRepository($this->paperRepository);
|
||||
}
|
||||
if($obj instanceof Template) {
|
||||
$element = $obj->parse();
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$default = $element->getDefault();
|
||||
$node = $this->templates->xpath('//option[@id="' . $element->getSelect() . '"]');
|
||||
$obj = $this->optionParser->getOptByType($node[0]);
|
||||
$element = $obj->parse();
|
||||
$obj = $this->optionParser->getOptByType($node[0]['type'], $node[0]['mode']?? null);
|
||||
$obj->fromXML($node[0]);
|
||||
$element = $obj->parseXML();
|
||||
if($default != "") {
|
||||
$element->setDefault($default);
|
||||
}
|
||||
}else{
|
||||
$element = $obj->parse();
|
||||
$element = $obj->parseXML();
|
||||
}
|
||||
$this->element->addOption($element);
|
||||
}
|
||||
}elseif($key == 'row') {
|
||||
$obj = new Row($option, $this->paperContainer, $this->paperRepository, $this->templates);
|
||||
$element = $obj->parse();
|
||||
$obj = new Row($this->paperContainer, $this->paperRepository, $this->templates);
|
||||
$obj->fromXML($option);
|
||||
$element = $obj->parseXML();
|
||||
$this->element->addOption($element);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,97 +7,135 @@ use Doctrine\Persistence\ObjectRepository;
|
||||
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||
use PSC\Library\Calc\Option\Parser\Select\Opt;
|
||||
use PSC\Library\Calc\Option\Parser\Select\DeliveryOpt;
|
||||
use PSC\Library\Calc\Option\Type\Select as PSCSelect;
|
||||
use PSC\Library\Calc\PaperContainer;
|
||||
use PSC\Library\Calc\Tests\Mock\Paper;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
||||
class Select extends Base
|
||||
{
|
||||
|
||||
protected $element;
|
||||
|
||||
/** @var \SimpleXMLElement $node */
|
||||
protected $node;
|
||||
|
||||
/** @var PaperContainer */
|
||||
protected $paperContainer;
|
||||
|
||||
/** @var ObjectRepository */
|
||||
protected $paperRepository;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct(?string $mode = null)
|
||||
{
|
||||
if(isset($node['mode']) && (string)$node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
||||
parent::__construct();
|
||||
|
||||
if($mode != null && $mode == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\PaperDbSelect();
|
||||
}elseif(isset($node['mode']) && (string)$node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery) {
|
||||
}elseif($mode != null && $mode == \PSC\Library\Calc\Option\Type\Select::$modeDelivery) {
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\DeliverySelect();
|
||||
}elseif(isset($node['mode']) && (string)$node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeColorDb) {
|
||||
}elseif($mode != null && $mode == \PSC\Library\Calc\Option\Type\Select::$modeColorDb) {
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\ColorDBSelect();
|
||||
}else{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Select();
|
||||
}
|
||||
|
||||
parent::__construct($node);
|
||||
}
|
||||
public function parseJson(): PSCSelect
|
||||
{
|
||||
parent::parseJson();
|
||||
|
||||
if(isset($this->json['dependencys']) && count($this->json['dependencys']) > 0) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromJson($this->json['dependencys']);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseJson());
|
||||
}
|
||||
|
||||
if(isset($this->json['mode']) && (string)$this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
||||
$this->parseModePapierDbJson();
|
||||
}elseif(isset($this->json['mode']) && (string)$this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery) {
|
||||
$this->parseModeDeliveryJson();
|
||||
}elseif(isset($this->json['mode']) && (string)$this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeColorDb) {
|
||||
$this->parseModeColorDbJson();
|
||||
}else{
|
||||
$this->parseModeNormalJson();
|
||||
}
|
||||
|
||||
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseXML(): PSCSelect
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseXML();
|
||||
|
||||
if(isset($this->node->grenzen) && $this->node->grenzen->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node->grenzen);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromXML($this->node->grenzen);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
|
||||
if(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) {
|
||||
$this->parseModePapierDb();
|
||||
$this->parseModePapierDbXML();
|
||||
}elseif(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery) {
|
||||
$this->parseModeDelivery();
|
||||
$this->parseModeDeliveryXML();
|
||||
}elseif(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeColorDb) {
|
||||
$this->parseModeColorDb();
|
||||
$this->parseModeColorDbXML();
|
||||
}else{
|
||||
$this->parseModeNormal();
|
||||
$this->parseModeNormalXML();
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
private function parseModeDelivery()
|
||||
private function parseModeDeliveryXML()
|
||||
{
|
||||
foreach ($this->node->opt as $opt) {
|
||||
$optParser = new DeliveryOpt($opt);
|
||||
$this->element->addOption($optParser->parse());
|
||||
$optParser = new DeliveryOpt();
|
||||
$optParser->fromXML($opt);
|
||||
$this->element->addOption($optParser->parseXML());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function parseModePapierDb()
|
||||
private function parseModeDeliveryJson()
|
||||
{
|
||||
$this->element->setNewPaperObject($this->getPaperRepository()->getNewObject());
|
||||
/** @var PaperContainer\Container $container */
|
||||
$container = $this->getPaperContainer()->getContainerById((string)$this->node['container']);
|
||||
foreach ($this->json['options'] as $opt) {
|
||||
$optParser = new DeliveryOpt();
|
||||
$optParser->fromJson($opt);
|
||||
$this->element->addOption($optParser->parseJson());
|
||||
}
|
||||
|
||||
if($container) {
|
||||
/** @var PaperContainer\Item $papier */
|
||||
|
||||
foreach ($container->getItems() as $papier) {
|
||||
/** @var Paper $paper */
|
||||
$paper = $this->getPaperRepository()->findOneBy(array('artNr' => $papier->getId()));
|
||||
}
|
||||
|
||||
if($paper) {
|
||||
$optPapier = new \PSC\Library\Calc\Option\Type\Select\PaperOpt();
|
||||
$optPapier->setId($paper->getArtNr());
|
||||
$optPapier->setLabel($paper->getDescription1());
|
||||
$optPapier->setPaper($paper);
|
||||
$optPapier->setValue($papier->getValue());
|
||||
$optPapier->setEdgesCollectionContainer($papier->getEdgesCollectionContainer());
|
||||
$this->element->addOption($optPapier);
|
||||
|
||||
private function parseModePapierDbXML()
|
||||
{
|
||||
if($this->getPaperRepository()) {
|
||||
$this->element->setNewPaperObject($this->getPaperRepository()->getNewObject());
|
||||
/** @var PaperContainer\Container $container */
|
||||
$container = $this->getPaperContainer()->getContainerById((string)$this->node['container']);
|
||||
|
||||
if($container) {
|
||||
/** @var PaperContainer\Item $papier */
|
||||
|
||||
foreach ($container->getItems() as $papier) {
|
||||
/** @var Paper $paper */
|
||||
$paper = $this->getPaperRepository()->findOneBy(array('artNr' => $papier->getId()));
|
||||
|
||||
if($paper) {
|
||||
$optPapier = new \PSC\Library\Calc\Option\Type\Select\PaperOpt();
|
||||
$optPapier->setId($paper->getArtNr());
|
||||
$optPapier->setLabel($paper->getDescription1());
|
||||
$optPapier->setPaper($paper);
|
||||
$optPapier->setValue($papier->getValue());
|
||||
$optPapier->setEdgesCollectionContainer($papier->getEdgesCollectionContainer());
|
||||
$this->element->addOption($optPapier);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$this->element->setContainer((string)$this->node['container']);
|
||||
}
|
||||
}
|
||||
|
||||
private function parseModeColorDb(): void
|
||||
private function parseModeColorDbXML(): void
|
||||
{
|
||||
$colorSystem = (string)$this->node['container'];
|
||||
|
||||
@ -137,14 +175,26 @@ class Select extends Base
|
||||
$this->element->addOptions($value);
|
||||
}
|
||||
|
||||
private function parseModeNormal()
|
||||
private function parseModeNormalXML()
|
||||
{
|
||||
foreach ($this->node->opt as $opt) {
|
||||
$optParser = new Opt($opt);
|
||||
$this->element->addOption($optParser->parse());
|
||||
$optParser = new Opt();
|
||||
$optParser->fromXML($opt);
|
||||
$this->element->addOption($optParser->parseXML());
|
||||
}
|
||||
}
|
||||
|
||||
private function parseModeNormalJson()
|
||||
{
|
||||
foreach ($this->json['options'] as $opt) {
|
||||
$optParser = new Opt();
|
||||
$optParser->fromJson($opt);
|
||||
$this->element->addOption($optParser->parseJson());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return PaperContainer
|
||||
*/
|
||||
|
||||
@ -7,15 +7,37 @@ use PSC\Library\Calc\Option\Parser\Base;
|
||||
class DeliveryOpt extends Opt
|
||||
{
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Select\DeliveryOpt();
|
||||
$this->node = $node;
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseJson()
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseJson();
|
||||
|
||||
if(isset($this->json['info'])) {
|
||||
$this->element->setInfo((string)$this->json['info']);
|
||||
}
|
||||
if(isset($this->json['country'])) {
|
||||
$this->element->setCountry((string)$this->json['country']);
|
||||
}
|
||||
if(isset($this->json['dateFormat'])) {
|
||||
$this->element->setDateFormat((string)$this->json['dateFormat']);
|
||||
}
|
||||
if(isset($this->json['maxTime'])) {
|
||||
$this->element->setMaxTime((int)$this->json['maxTime']);
|
||||
}
|
||||
if(isset($this->json['workDays'])) {
|
||||
$this->element->setWorkDays((int)$this->json['workDays']);
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
public function parseXML()
|
||||
{
|
||||
parent::parseXML();
|
||||
|
||||
if(isset($this->node['info'])) {
|
||||
$this->element->setInfo((string)$this->node['info']);
|
||||
@ -33,9 +55,7 @@ class DeliveryOpt extends Opt
|
||||
$this->element->setWorkDays((int)$this->node['workDays']);
|
||||
}
|
||||
|
||||
$this->element->setLabel((string)$this->node['name']);
|
||||
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,24 +9,49 @@ class Opt
|
||||
|
||||
protected $element;
|
||||
protected \SimpleXMLElement $node;
|
||||
protected array $json;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Select\Opt();
|
||||
}
|
||||
|
||||
public function fromJson(array $json): void
|
||||
{
|
||||
$this->json = $json;
|
||||
}
|
||||
|
||||
public function fromXML(\SimpleXMLElement $node): void
|
||||
{
|
||||
$this->node = $node;
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseJson()
|
||||
{
|
||||
$this->element->setId((string)$this->json['id']);
|
||||
$this->element->setLabel((string)$this->json['name']);
|
||||
|
||||
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()
|
||||
{
|
||||
$this->element->setId((string)$this->node['id']);
|
||||
$this->element->setLabel((string)$this->node['name']);
|
||||
|
||||
if($this->node->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromXML($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Option\Parser;
|
||||
|
||||
use PSC\Library\Calc\Option\Type\Template as PSCTemplate;
|
||||
|
||||
class Template extends Base
|
||||
{
|
||||
|
||||
protected $element;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Template();
|
||||
parent::__construct($node);
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseXML(): PSCTemplate
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseXML();
|
||||
|
||||
if($this->node['select']) {
|
||||
$this->element->setSelect((string)$this->node['select']);
|
||||
@ -22,4 +23,4 @@ class Template extends Base
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,21 +2,35 @@
|
||||
namespace PSC\Library\Calc\Option\Parser;
|
||||
|
||||
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
|
||||
use PSC\Library\Calc\Option\Type\Text as PSCText;
|
||||
|
||||
class Text extends Base
|
||||
{
|
||||
|
||||
protected $element;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Text();
|
||||
parent::__construct($node);
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseJSON(): PSCText
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseJson();
|
||||
|
||||
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(): PSCText
|
||||
{
|
||||
parent::parseXML();
|
||||
|
||||
if($this->node->data) {
|
||||
$this->element->setValue((string)$this->node->data);
|
||||
@ -27,8 +41,9 @@ class Text extends Base
|
||||
}
|
||||
|
||||
if($this->node->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromXML($this->node);
|
||||
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
|
||||
return $this->element;
|
||||
|
||||
@ -1,22 +1,23 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Option\Parser;
|
||||
|
||||
use PSC\Library\Calc\Option\Type\Textarea as PSCTextarea;
|
||||
|
||||
class Textarea extends Base
|
||||
{
|
||||
|
||||
protected $element;
|
||||
|
||||
public function __construct(\SimpleXMLElement $node)
|
||||
public function __construct()
|
||||
{
|
||||
$this->element = new \PSC\Library\Calc\Option\Type\Textarea();
|
||||
parent::__construct($node);
|
||||
}
|
||||
|
||||
public function parse()
|
||||
public function parseXML(): PSCTextarea
|
||||
{
|
||||
parent::parse();
|
||||
parent::parseXML();
|
||||
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,4 +339,36 @@ class Base
|
||||
'valid' => $this->isValid()
|
||||
];
|
||||
}
|
||||
|
||||
public function generateJson(): \stdClass
|
||||
{
|
||||
$obj = new \stdClass();
|
||||
$obj->id = $this->getId();
|
||||
$obj->name = $this->getName();
|
||||
$obj->default = $this->getDefault()?? "";
|
||||
$obj->dependencys = [];
|
||||
|
||||
foreach($this->edgesCollectionContainer as $col) {
|
||||
$obj->dependencys[] = $col->generateJson();
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function generateXML(): array
|
||||
{
|
||||
$tmp = [
|
||||
'_attributes' => [
|
||||
'id' => $this->getId(),
|
||||
'name' => $this->getName(),
|
||||
'type' => ucfirst($this->getType()),
|
||||
]
|
||||
];
|
||||
|
||||
foreach($this->edgesCollectionContainer as $col) {
|
||||
$tmp[$col->getName()] = $col->generateXML();
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,4 +19,14 @@ class ColorDBSelect extends Select
|
||||
$this->colorSystem = $colorSystem;
|
||||
}
|
||||
|
||||
public function generateJson(): \stdClass
|
||||
{
|
||||
$obj = parent::generateJson();
|
||||
$obj->mode = 'colordb';
|
||||
$obj->container = $this->container;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -3,5 +3,14 @@ namespace PSC\Library\Calc\Option\Type;
|
||||
|
||||
class DeliverySelect extends Select
|
||||
{
|
||||
public function generateJson(): \stdClass
|
||||
{
|
||||
$obj = parent::generateJson();
|
||||
$obj->mode = 'delivery';
|
||||
$obj->container = $this->container;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,12 @@ namespace PSC\Library\Calc\Option\Type;
|
||||
|
||||
class Hidden extends Base
|
||||
{
|
||||
|
||||
public $type = 'hidden';
|
||||
|
||||
}
|
||||
public function generateJson(): \stdClass
|
||||
{
|
||||
$obj = parent::generateJson();
|
||||
$obj->type = 1;
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,4 +52,25 @@ class Input extends Base
|
||||
{
|
||||
$this->placeHolder = $placeHolder;
|
||||
}
|
||||
|
||||
public function generateXML(): array
|
||||
{
|
||||
return array_merge_recursive([
|
||||
'_attributes' => [
|
||||
'placeholder' => $this->getPlaceHolder(),
|
||||
'default' => $this->getDefault(),
|
||||
'require' => $this->isRequire()?'true':'false',
|
||||
]
|
||||
]
|
||||
, parent::generateXML());
|
||||
}
|
||||
|
||||
public function generateJson(): \stdClass
|
||||
{
|
||||
$obj = parent::generateJson();
|
||||
$obj->placeHolder = $this->placeHolder;
|
||||
$obj->required = $this->isRequire();
|
||||
$obj->type = 2;
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,4 +174,13 @@ class PaperDbSelect extends Select
|
||||
$this->newPaperObject = $newPaperObject;
|
||||
}
|
||||
|
||||
public function generateJson(): \stdClass
|
||||
{
|
||||
$obj = parent::generateJson();
|
||||
$obj->mode = 'paperdb';
|
||||
$obj->container = $this->container;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -137,4 +137,46 @@ class Select extends Base
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
public function generateXML(): array
|
||||
{
|
||||
$options = $this->options;
|
||||
$tmp = ['opt' => function () use ($options) {
|
||||
$xml_options = [];
|
||||
foreach ($options as $option) {
|
||||
$xml_options[] = $option->generateXML();
|
||||
}
|
||||
|
||||
return $xml_options;
|
||||
}];
|
||||
|
||||
if($this->isRequire()) {
|
||||
$tmp['_attributes'] = [
|
||||
'require' => $this->isRequire()?'true':'false'
|
||||
];
|
||||
}
|
||||
|
||||
return array_merge_recursive([
|
||||
'_attributes' => [
|
||||
'default' => $this->getDefault(),
|
||||
]
|
||||
]
|
||||
, parent::generateXML(), $tmp);
|
||||
}
|
||||
|
||||
public function generateJson(): \stdClass
|
||||
{
|
||||
$obj = parent::generateJson();
|
||||
if($this->isRequire()) {
|
||||
$obj->required = $this->isRequire();
|
||||
}
|
||||
$obj->type = 3;
|
||||
$obj->options = [];
|
||||
$obj->mode = 'normal';
|
||||
|
||||
foreach($this->options as $opt) {
|
||||
$obj->options[] = $opt->generateJson();
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,4 +95,35 @@ class Opt
|
||||
{
|
||||
$this->edgesCollectionContainer = new EdgeCollectionContainer();
|
||||
}
|
||||
}
|
||||
|
||||
public function generateXML(): array
|
||||
{
|
||||
$tmp = [
|
||||
'_attributes' => [
|
||||
'id' => $this->id,
|
||||
'name' => $this->label,
|
||||
]
|
||||
];
|
||||
|
||||
foreach($this->edgesCollectionContainer as $col) {
|
||||
$tmp[$col->getName()] = $col->generateXML();
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
public function generateJson(): \stdClass
|
||||
{
|
||||
$obj = new \stdClass();
|
||||
$obj->id = $this->id;
|
||||
$obj->name = $this->label;
|
||||
|
||||
$obj->dependencys = [];
|
||||
|
||||
foreach($this->edgesCollectionContainer as $col) {
|
||||
$obj->dependencys[] = $col->generateJson();
|
||||
}
|
||||
|
||||
|
||||
return $obj;
|
||||
}}
|
||||
|
||||
@ -6,4 +6,11 @@ class Text extends Base
|
||||
|
||||
public $type = 'text';
|
||||
|
||||
}
|
||||
public function generateJson(): \stdClass
|
||||
{
|
||||
$obj = parent::generateJson();
|
||||
$obj->type = 4;
|
||||
return $obj;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -28,8 +28,9 @@ class PaperContainer
|
||||
$item->setValue((float)$paper['value']);
|
||||
}
|
||||
if(isset($paper->grenzen)) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($paper->grenzen);
|
||||
$item->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer();
|
||||
$edgeCollectionContainerParser->fromXML($paper->grenzen);
|
||||
$item->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML());
|
||||
}
|
||||
|
||||
$container->addItem($item);
|
||||
@ -57,4 +58,4 @@ class PaperContainer
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,11 +25,45 @@ class Parser
|
||||
{
|
||||
}
|
||||
|
||||
public function parse(\SimpleXMLElement $node): Article
|
||||
public function parseJson(array $json): Article
|
||||
{
|
||||
$optionParser = new \PSC\Library\Calc\Option\Parser($this->paperContainer, $this->paperRepository, $this->templates);
|
||||
$this->article = new Article($json['name'], $json['uuid']?? null);
|
||||
|
||||
foreach ($json['options'] as $option) {
|
||||
$obj = $optionParser->getOptByJsonType($option['type'], $option['mode']?? null);
|
||||
if($obj) {
|
||||
$obj->fromJson($option);
|
||||
if($obj instanceof Select) {
|
||||
$obj->setPaperContainer($this->getPaperContainer());
|
||||
$obj->setPaperRepository($this->getPaperRepository());
|
||||
}
|
||||
if($obj instanceof Template) {
|
||||
$element = $obj->parseJson();
|
||||
|
||||
$default = $element->getDefault();
|
||||
$node = $this->templates->xpath('//option[@id="' . $element->getSelect() . '"]');
|
||||
$obj = $optionParser->getOptByType($node[0]);
|
||||
$element = $obj->parseJson();
|
||||
if($default != "") {
|
||||
$element->setDefault($default);
|
||||
}
|
||||
}else{
|
||||
$element = $obj->parseJson();
|
||||
}
|
||||
$this->article->addOption($element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->article;
|
||||
}
|
||||
|
||||
public function parseXML(\SimpleXMLElement $node): Article
|
||||
{
|
||||
$optionParser = new \PSC\Library\Calc\Option\Parser($this->paperContainer, $this->paperRepository, $this->templates);
|
||||
|
||||
$this->article = new Article((string)$node->name);
|
||||
$this->article = new Article((string)$node->name, (string)$node->uuid?? null);
|
||||
|
||||
if(isset($node->kommentar)) {
|
||||
$this->article->setComment((string)$node->kommentar);
|
||||
@ -56,31 +90,33 @@ class Parser
|
||||
|
||||
foreach ($node->children() as $key => $option) {
|
||||
if($key == 'option') {
|
||||
$obj = $optionParser->getOptByType($option);
|
||||
$obj = $optionParser->getOptByType($option['type'], $option['mode']?? null);
|
||||
if($obj) {
|
||||
|
||||
$obj->fromXML($option);
|
||||
if($obj instanceof Select) {
|
||||
$obj->setPaperContainer($this->getPaperContainer());
|
||||
$obj->setPaperRepository($this->getPaperRepository());
|
||||
}
|
||||
if($obj instanceof Template) {
|
||||
$element = $obj->parse();
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$default = $element->getDefault();
|
||||
$node = $this->templates->xpath('//option[@id="' . $element->getSelect() . '"]');
|
||||
$obj = $optionParser->getOptByType($node[0]);
|
||||
$element = $obj->parse();
|
||||
$obj = $optionParser->getOptByType($node[0]['type']);
|
||||
$obj->fromXML($node[0]);
|
||||
$element = $obj->parseXML();
|
||||
if($default != "") {
|
||||
$element->setDefault($default);
|
||||
}
|
||||
}else{
|
||||
$element = $obj->parse();
|
||||
$element = $obj->parseXML();
|
||||
}
|
||||
$this->article->addOption($element);
|
||||
}
|
||||
}elseif($key == 'row') {
|
||||
$obj = new Row($option, $this->paperContainer, $this->paperRepository, $this->templates);
|
||||
$element = $obj->parse();
|
||||
$obj = new Row($this->paperContainer, $this->paperRepository, $this->templates);
|
||||
$obj->fromXML($option);
|
||||
$element = $obj->parseXML();
|
||||
$this->article->addOption($element);
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ class ColumnTest extends TestCase
|
||||
$this->engine = null;
|
||||
}
|
||||
|
||||
public function tesRowColumn()
|
||||
public function testRowColumn()
|
||||
{
|
||||
$row1 = $this->engine->getArticle()->getOptionById('row1');
|
||||
$col2 = $this->engine->getArticle()->getOptionById('row1')->getColumnById('col2');
|
||||
@ -34,7 +34,7 @@ class ColumnTest extends TestCase
|
||||
}
|
||||
|
||||
|
||||
public function tesTextOption()
|
||||
public function testTextOption()
|
||||
{
|
||||
$textOption = $this->engine->getArticle()->getOptionById('text3');
|
||||
self::assertInstanceOf(Text::class, $textOption);
|
||||
|
||||
41
tests/Json/FromJsonTest.php
Normal file
41
tests/Json/FromJsonTest.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Tests\Json;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PSC\Library\Calc\Engine;
|
||||
use PSC\Library\Calc\Option\Type\Input;
|
||||
use PSC\Library\Calc\PaperContainer\Container;
|
||||
|
||||
class FromJsonTest extends TestCase
|
||||
{
|
||||
public function testFromJson()
|
||||
{
|
||||
$engine1 = new Engine();
|
||||
self::assertTrue($engine1->loadJson(file_get_contents(__DIR__ .'/from.json')));
|
||||
self::assertCount(1, $engine1->getArticles());
|
||||
self::assertInstanceOf(Input::class, $engine1->getArticle()->getOptionById('auflage'));
|
||||
|
||||
$engine2 = new Engine();
|
||||
self::assertTrue($engine2->loadString(file_get_contents(__DIR__ .'/from.xml')));
|
||||
self::assertCount(1, $engine2->getArticles());
|
||||
self::assertInstanceOf(Input::class, $engine2->getArticle()->getOptionById('auflage'));
|
||||
self::assertSame(1011.42, $engine1->getPrice());
|
||||
|
||||
self::assertSame($engine1->getPrice(), $engine2->getPrice());
|
||||
|
||||
self::assertEqualsCanonicalizing($engine1->getArticle(), $engine2->getArticle());
|
||||
$tempXML = tempnam(sys_get_temp_dir(), 'calc');
|
||||
$tempJson = tempnam(sys_get_temp_dir(), 'calc');
|
||||
file_put_contents($tempXML, $engine1->generateXML());
|
||||
file_put_contents($tempJson, $engine2->generateJson());
|
||||
|
||||
self::assertJsonFileEqualsJsonFile(__DIR__.'/from.json', $tempJson);
|
||||
self::assertXmlFileEqualsXmlFile(__DIR__.'/from.xml', $tempXML);
|
||||
|
||||
self::assertCount(5, $engine1->getArticle()->getOptionById('farbigkeit')->getOptions());
|
||||
self::assertCount(5, $engine2->getArticle()->getOptionById('farbigkeit')->getOptions());
|
||||
|
||||
@unlink($tempXML);
|
||||
@unlink($tempJson);
|
||||
}
|
||||
}
|
||||
1
tests/Json/from.json
Normal file
1
tests/Json/from.json
Normal file
@ -0,0 +1 @@
|
||||
[{"uuid":"df2df718-b28e-482d-bf0c-67d246f05d32","name":"Test Artikel","options":[{"id":"auflage","type":2,"dependencys":[],"placeHolder":"Placeholder","default":"100","name":"Auflage","required":false},{"id":"seiten_umschlag","type":2,"dependencys":[],"placeHolder":"Placeholder","default":"2","name":"Seiten Umschlag","required":false},{"id":"seiten_anzahl_inhalt","type":2,"dependencys":[{"formula":"","relation":"auflage","borders":[{"formula":"$Vauflage$V*0.12","calcValue":"","flatRate":"","value":"1-10","dependencys":[{"formula":"","relation":"seiten_umschlag","borders":[{"formula":"$Vseiten_umschlag$V*0.24","calcValue":"","flatRate":"","value":"1-2","dependencys":[]},{"formula":"$Vseiten_umschlag$V*0.23","calcValue":"","flatRate":"","value":"3-","dependencys":[]}]}]},{"formula":"$Vauflage$V*0.11","calcValue":"","flatRate":"","value":"11-","dependencys":[{"formula":"","relation":"seiten_umschlag","borders":[{"formula":"$Vseiten_umschlag$V*0.21","calcValue":"","flatRate":"","value":"1-2","dependencys":[]},{"formula":"$Vseiten_umschlag$V*0.20","calcValue":"","flatRate":"","value":"3-","dependencys":[]}]}]}]}],"placeHolder":"Placeholder","default":"10","name":"Seiten Anzahl Inhalt","required":true},{"id":"farbigkeit","mode":"normal","type":3,"dependencys":[],"default":"10","options":[{"id":"10","name":"1/0 farbig","dependencys":[{"formula":"","relation":"auflage","borders":[{"formula":"","calcValue":"","flatRate":"","value":"1-101","dependencys":[]}]}]},{"id":"11","name":"1/1 farbig","dependencys":[]},{"id":"20","name":"2/0 farbig","dependencys":[]},{"id":"21","name":"2/1 farbig","dependencys":[]},{"id":"22","name":"2/2 farbig","dependencys":[{"formula":"","relation":"auflage","borders":[{"formula":"","calcValue":"","flatRate":"","value":"11-50","dependencys":[]}]}]}],"name":"Farbigkeit"},{"id":"calc","type":1,"dependencys":[{"formula":"","relation":"auflage","borders":[{"formula":"$Vauflage$V*$Vseiten_anzahl_inhalt$V","calcValue":"","flatRate":"","value":"1-","dependencys":[]}]}],"default":"","name":"calc"}]}]
|
||||
52
tests/Json/from.xml
Normal file
52
tests/Json/from.xml
Normal file
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<kalkulation>
|
||||
<artikel>
|
||||
<name>Test Artikel</name>
|
||||
<uuid>df2df718-b28e-482d-bf0c-67d246f05d32</uuid>
|
||||
<kommentar></kommentar>
|
||||
|
||||
<option id="auflage" name="Auflage" type="Input" placeholder="Placeholder" default="100" require="false"></option>
|
||||
|
||||
<option id="seiten_umschlag" name="Seiten Umschlag" type="Input" default="2" require="false" placeholder="Placeholder"></option>
|
||||
|
||||
<option id="seiten_anzahl_inhalt" name="Seiten Anzahl Inhalt" type="Input" default="10" require="true" placeholder="Placeholder">
|
||||
<auflage>
|
||||
<grenze formel="$Vauflage$V*0.12" value="1-10">
|
||||
<seiten_umschlag>
|
||||
<grenze formel="$Vseiten_umschlag$V*0.24">1-2</grenze>
|
||||
<grenze formel="$Vseiten_umschlag$V*0.23">3-</grenze>
|
||||
</seiten_umschlag>
|
||||
</grenze>
|
||||
<grenze formel="$Vauflage$V*0.11" value="11-">
|
||||
<seiten_umschlag>
|
||||
<grenze formel="$Vseiten_umschlag$V*0.21">1-2</grenze>
|
||||
<grenze formel="$Vseiten_umschlag$V*0.20">3-</grenze>
|
||||
</seiten_umschlag>
|
||||
</grenze>
|
||||
</auflage>
|
||||
</option>
|
||||
|
||||
<option id="farbigkeit" name="Farbigkeit" type="Select" default="10">
|
||||
<opt id="10" name="1/0 farbig">
|
||||
<auflage>
|
||||
<grenze>1-101</grenze>
|
||||
</auflage>
|
||||
</opt>
|
||||
<opt id="11" name="1/1 farbig"></opt>
|
||||
<opt id="20" name="2/0 farbig"></opt>
|
||||
<opt id="21" name="2/1 farbig"></opt>
|
||||
<opt id="22" name="2/2 farbig">
|
||||
<auflage>
|
||||
<grenze>11-50</grenze>
|
||||
</auflage>
|
||||
</opt>
|
||||
</option>
|
||||
<option id="calc" name="calc" type="Hidden">
|
||||
<auflage>
|
||||
<grenze formel="$Vauflage$V*$Vseiten_anzahl_inhalt$V">1-</grenze>
|
||||
</auflage>
|
||||
</option>
|
||||
|
||||
</artikel>
|
||||
</kalkulation>
|
||||
|
||||
@ -10,9 +10,10 @@ class ContainerTest extends TestCase
|
||||
{
|
||||
$node = simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Edges/collections.xml'));
|
||||
|
||||
$containerParser = new EdgeCollectionContainer($node);
|
||||
$containerParser = new EdgeCollectionContainer();
|
||||
$containerParser->fromXML($node);
|
||||
/** @var \PSC\Library\Calc\General\Type\EdgeCollectionContainer $container */
|
||||
$container = $containerParser->parse();
|
||||
$container = $containerParser->parseXML();
|
||||
|
||||
$this->assertCount(2, $container);
|
||||
|
||||
|
||||
@ -10,10 +10,10 @@ class SimpleTest extends TestCase
|
||||
{
|
||||
$node = simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Edges/simple.xml'));
|
||||
|
||||
$edgeParser = new Edge($node->grenze[2]);
|
||||
|
||||
$edgeParser = new Edge();
|
||||
$edgeParser->fromXML($node->grenze[2]);
|
||||
/** @var \PSC\Library\Calc\General\Type\Edge $edge */
|
||||
$edge = $edgeParser->parse();
|
||||
$edge = $edgeParser->parseXML();
|
||||
$this->assertEquals(12, $edge->getPreis());
|
||||
$this->assertEquals(10, $edge->getPauschale());
|
||||
$this->assertEquals('$Vmaschwertjuengerfuenf$V/1000*0.900', $edge->getFormel());
|
||||
@ -27,10 +27,11 @@ class SimpleTest extends TestCase
|
||||
{
|
||||
$node = simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Edges/simple.xml'));
|
||||
|
||||
$edgeParser = new Edge($node->grenze[1]);
|
||||
$edgeParser = new Edge();
|
||||
$edgeParser->fromXML($node->grenze[1]);
|
||||
|
||||
/** @var \PSC\Library\Calc\General\Type\Edge $edge */
|
||||
$edge = $edgeParser->parse();
|
||||
$edge = $edgeParser->parseXML();
|
||||
$this->assertEquals(12, $edge->getPreis());
|
||||
$this->assertEquals(10, $edge->getPauschale());
|
||||
$this->assertEquals('$Vmaschwertjuengerfuenf$V/1000*0.900', $edge->getFormel());
|
||||
@ -44,10 +45,11 @@ class SimpleTest extends TestCase
|
||||
{
|
||||
$node = simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Edges/simple.xml'));
|
||||
|
||||
$edgeParser = new Edge($node->grenze[0]);
|
||||
$edgeParser = new Edge();
|
||||
$edgeParser->fromXML($node->grenze[0]);
|
||||
|
||||
/** @var \PSC\Library\Calc\General\Type\Edge $edge */
|
||||
$edge = $edgeParser->parse();
|
||||
$edge = $edgeParser->parseXML();
|
||||
$this->assertEquals(12, $edge->getPreis());
|
||||
$this->assertEquals(10, $edge->getPauschale());
|
||||
$this->assertEquals('$Vmaschwertjuengerfuenf$V/1000*0.900', $edge->getFormel());
|
||||
@ -62,10 +64,11 @@ class SimpleTest extends TestCase
|
||||
{
|
||||
$node = simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Edges/simple.xml'));
|
||||
|
||||
$edgeParser = new Edge($node->grenze[3]);
|
||||
$edgeParser = new Edge();
|
||||
$edgeParser->fromXML($node->grenze[3]);
|
||||
|
||||
/** @var \PSC\Library\Calc\General\Type\Edge $edge */
|
||||
$edge = $edgeParser->parse();
|
||||
$edge = $edgeParser->parseXML();
|
||||
$this->assertEquals(12, $edge->getPreis());
|
||||
$this->assertEquals(10, $edge->getPauschale());
|
||||
$this->assertEquals('$Vmaschwertjuengerfuenf$V/1000*0.900', $edge->getFormel());
|
||||
|
||||
@ -3,20 +3,16 @@ namespace PSC\Library\Calc\Tests\Option\Type;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PSC\Library\Calc\Option\Parser;
|
||||
use PSC\Library\Calc\Option\Type\Checkbox;
|
||||
use PSC\Library\Calc\Option\Type\Input;
|
||||
use PSC\Library\Calc\PaperContainer\Container;
|
||||
|
||||
class CheckboxTest extends TestCase
|
||||
{
|
||||
public function testIfCorrectType()
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Checkbox $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/checkbox.xml')));
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/checkbox.xml'))['type']);
|
||||
|
||||
/** @var Checkbox $element */
|
||||
$element = $obj->parse();
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/checkbox.xml')));
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Checkbox', $element);
|
||||
}
|
||||
|
||||
@ -12,10 +12,9 @@ class InputTest extends TestCase
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Input $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/input.xml')));
|
||||
|
||||
/** @var Input $element */
|
||||
$element = $obj->parse();
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/input.xml'))['type']);
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/input.xml')));
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Input', $element);
|
||||
}
|
||||
@ -24,10 +23,10 @@ class InputTest extends TestCase
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Input $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/input.xml')));
|
||||
|
||||
/** @var Input $element */
|
||||
$element = $obj->parse();
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/input.xml'))['type']);
|
||||
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/input.xml')));
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Input', $element);
|
||||
$this->assertTrue($element->isRequire());
|
||||
|
||||
@ -12,11 +12,9 @@ class RadioboxTest extends TestCase
|
||||
public function testIfCorrectType()
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Checkbox $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/radiobox.xml')));
|
||||
|
||||
/** @var Checkbox $element */
|
||||
$element = $obj->parse();
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/radiobox.xml'))['type']);
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/radiobox.xml'))['type']);
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Radio', $element);
|
||||
}
|
||||
|
||||
@ -13,12 +13,10 @@ class SelectTest extends TestCase
|
||||
public function testIfCorrectType()
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Select $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/select.xml')));
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/select.xml'))['type'], simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/select.xml'))['mode']);
|
||||
$obj->setPaperContainer(new PaperContainer());
|
||||
|
||||
/** @var Select $element */
|
||||
$element = $obj->parse();
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/select.xml')));
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Select', $element);
|
||||
}
|
||||
@ -26,12 +24,10 @@ class SelectTest extends TestCase
|
||||
public function testIfCorrectAttributes()
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Select $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/select.xml')));
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/select.xml'))['type']);
|
||||
$obj->setPaperContainer(new PaperContainer());
|
||||
|
||||
/** @var Select $element */
|
||||
$element = $obj->parse();
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/select.xml')));
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Select', $element);
|
||||
$this->assertTrue($element->isRequire());
|
||||
@ -71,12 +67,13 @@ class SelectTest extends TestCase
|
||||
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Select $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectPaperDB.xml')));
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectPaperDB.xml'))['type'], simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectPaperDB.xml'))['mode']);
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectPaperDB.xml')));
|
||||
$obj->setPaperContainer($paperContainer);
|
||||
$obj->setPaperRepository($repository);
|
||||
|
||||
/** @var Select $element */
|
||||
$element = $obj->parse();
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Select', $element);
|
||||
|
||||
@ -86,11 +83,9 @@ class SelectTest extends TestCase
|
||||
public function testIfSelectWithColorModePantoneReturnsCorrectOpt()
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Select $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectColorDBPantone.xml')));
|
||||
|
||||
/** @var Select $element */
|
||||
$element = $obj->parse();
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectColorDBPantone.xml'))['type'], simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectColorDBPantone.xml'))['mode']);
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectColorDBPantone.xml')));
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Select', $element);
|
||||
$this->assertEquals(1354, $element->getOptions()->count());
|
||||
@ -99,11 +94,10 @@ class SelectTest extends TestCase
|
||||
public function testIfSelectWithColorModeReturnsCorrectOpt()
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Select $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectColorDBHKS.xml')));
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectColorDBHKS.xml'))['type'], simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectColorDBHKS.xml'))['mode']);
|
||||
|
||||
/** @var Select $element */
|
||||
$element = $obj->parse();
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/Select/selectColorDBHKS.xml')));
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Select', $element);
|
||||
$this->assertEquals(86, $element->getOptions()->count());
|
||||
|
||||
@ -12,10 +12,10 @@ class TextTest extends TestCase
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Input $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/text.xml')));
|
||||
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/text.xml'))['type']);
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/text.xml')));
|
||||
/** @var Input $element */
|
||||
$element = $obj->parse();
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Text', $element);
|
||||
}
|
||||
@ -24,10 +24,10 @@ class TextTest extends TestCase
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Input $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/text.xml')));
|
||||
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/text.xml'))['type']);
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/text.xml')));
|
||||
/** @var Input $element */
|
||||
$element = $obj->parse();
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Text', $element);
|
||||
$this->assertEquals('testtext', $element->getDefault());
|
||||
|
||||
@ -11,11 +11,9 @@ class TextareaTest extends TestCase
|
||||
public function testIfCorrectType()
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Input $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/textarea.xml')));
|
||||
|
||||
/** @var Input $element */
|
||||
$element = $obj->parse();
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/textarea.xml'))['type']);
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/textarea.xml')));
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Textarea', $element);
|
||||
}
|
||||
@ -23,11 +21,9 @@ class TextareaTest extends TestCase
|
||||
public function testIfCorrectAttributes()
|
||||
{
|
||||
$parser = new Parser();
|
||||
/** @var Parser\Input $obj */
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/textarea.xml')));
|
||||
|
||||
/** @var Input $element */
|
||||
$element = $obj->parse();
|
||||
$obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/textarea.xml'))['type']);
|
||||
$obj->fromXML(simplexml_load_string(file_get_contents(__DIR__ . '/../../TestFiles/Option/textarea.xml')));
|
||||
$element = $obj->parseXML();
|
||||
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Option\Type\Textarea', $element);
|
||||
$this->assertEquals('testtext', $element->getDefault());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user