|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace kalanis\Pohoda\PrintRequest; |
|
6
|
|
|
|
|
7
|
|
|
use kalanis\Pohoda\AbstractAgenda; |
|
8
|
|
|
use kalanis\Pohoda\Common; |
|
9
|
|
|
|
|
10
|
|
|
class Parameters extends AbstractAgenda |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* {@inheritdoc} |
|
14
|
|
|
*/ |
|
15
|
3 |
|
public function setData(Common\Dtos\AbstractDto $data): parent |
|
16
|
|
|
{ |
|
17
|
3 |
|
$parameterFactory = $this->dependenciesFactory->getParametersFactory(); |
|
18
|
3 |
|
$parameterInstances = $this->dependenciesFactory->getParameterInstances(); |
|
19
|
|
|
|
|
20
|
3 |
|
foreach ($parameterInstances->getKeys() as $key) { |
|
21
|
|
|
// add instance to data |
|
22
|
3 |
|
if (isset($data->{$key})) { |
|
23
|
3 |
|
$data->{$key} = $parameterFactory |
|
24
|
3 |
|
->getByClassName($parameterInstances->getByKey($key)) |
|
25
|
3 |
|
->setDirectionalVariable($this->useOneDirectionalVariables) |
|
26
|
3 |
|
->setResolveOptions($this->resolveOptions) |
|
27
|
3 |
|
->setData($data->{$key}); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
// skip undefined - that which stays as AbstractDto class |
|
32
|
3 |
|
$dataKeys = array_keys((array) $data); |
|
33
|
3 |
|
foreach ($dataKeys as $dataKey) { |
|
34
|
3 |
|
if (is_a($data->{$dataKey}, Common\Dtos\AbstractDto::class)) { |
|
35
|
1 |
|
unset($data->{$dataKey}); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
3 |
|
$this->data = $this->resolveOptions ? $data : new Common\Dtos\EmptyDto(); // necessary due having dynamic properties |
|
40
|
3 |
|
return parent::setData($data); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
2 |
|
public function getXML(): \SimpleXMLElement |
|
47
|
|
|
{ |
|
48
|
2 |
|
$xml = $this->createXML()->addChild('prn:parameters', '', $this->namespace('prn')); |
|
49
|
|
|
|
|
50
|
2 |
|
$this->addElements($xml, $this->getDataElements(), 'prn'); |
|
51
|
|
|
|
|
52
|
2 |
|
return $xml; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
3 |
|
protected function getDataElements(bool $withAttributes = false): array |
|
56
|
|
|
{ |
|
57
|
3 |
|
return array_keys((array) $this->data); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @{inheritDoc} |
|
62
|
|
|
*/ |
|
63
|
3 |
|
protected function getDefaultDto(): Common\Dtos\AbstractDto |
|
64
|
|
|
{ |
|
65
|
3 |
|
return new ParametersDto(); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|