|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of riesenia/pohoda package. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the MIT License |
|
7
|
|
|
* (c) RIESENIA.com |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Riesenia\Pohoda\Document; |
|
13
|
|
|
|
|
14
|
|
|
use Riesenia\Pohoda\Common; |
|
15
|
|
|
use Riesenia\Pohoda\Type; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @property array{ |
|
19
|
|
|
* parameters?: iterable<Type\Parameter>, |
|
20
|
|
|
* homeCurrency?: Type\CurrencyItem, |
|
21
|
|
|
* foreignCurrency?: Type\CurrencyItem, |
|
22
|
|
|
* stockItem?: Type\StockItem, |
|
23
|
|
|
* } $data |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract class AbstractItem extends AbstractPart |
|
26
|
|
|
{ |
|
27
|
|
|
use Common\AddParameterTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
16 |
|
public function setData(array $data): parent |
|
33
|
|
|
{ |
|
34
|
|
|
// process home currency |
|
35
|
16 |
|
if (isset($data['homeCurrency'])) { |
|
36
|
12 |
|
$homeCurrency = new Type\CurrencyItem($this->dependenciesFactory); |
|
37
|
12 |
|
$homeCurrency |
|
38
|
12 |
|
->setDirectionalVariable($this->useOneDirectionalVariables) |
|
39
|
12 |
|
->setResolveOptions($this->resolveOptions) |
|
40
|
12 |
|
->setData($data['homeCurrency']); |
|
41
|
12 |
|
$data['homeCurrency'] = $homeCurrency; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// process foreign currency |
|
45
|
16 |
|
if (isset($data['foreignCurrency'])) { |
|
46
|
1 |
|
$foreignCurrency = new Type\CurrencyItem($this->dependenciesFactory); |
|
47
|
1 |
|
$foreignCurrency |
|
48
|
1 |
|
->setDirectionalVariable($this->useOneDirectionalVariables) |
|
49
|
1 |
|
->setResolveOptions($this->resolveOptions) |
|
50
|
1 |
|
->setData($data['foreignCurrency']); |
|
51
|
1 |
|
$data['foreignCurrency'] = $foreignCurrency; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// process stock item |
|
55
|
16 |
|
if (isset($data['stockItem'])) { |
|
56
|
7 |
|
$stockItem = new Type\StockItem($this->dependenciesFactory); |
|
57
|
7 |
|
$stockItem |
|
58
|
7 |
|
->setDirectionalVariable($this->useOneDirectionalVariables) |
|
59
|
7 |
|
->setResolveOptions($this->resolveOptions) |
|
60
|
7 |
|
->setData($data['stockItem']); |
|
61
|
7 |
|
$data['stockItem'] = $stockItem; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
16 |
|
return parent::setData($data); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
14 |
|
public function getXML(): \SimpleXMLElement |
|
71
|
|
|
{ |
|
72
|
14 |
|
if (is_null($this->namespace)) { |
|
73
|
1 |
|
throw new \LogicException('Namespace not set.'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
13 |
|
if (is_null($this->nodePrefix)) { |
|
77
|
1 |
|
throw new \LogicException('Node name prefix not set.'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
12 |
|
$xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Item', '', $this->namespace($this->namespace)); |
|
81
|
|
|
|
|
82
|
12 |
|
$this->addElements($xml, \array_merge($this->elements, ['parameters']), $this->namespace); |
|
83
|
|
|
|
|
84
|
12 |
|
return $xml; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* {@inheritdoc} |
|
89
|
|
|
*/ |
|
90
|
9 |
|
protected function configureOptions(Common\OptionsResolver $resolver): void |
|
91
|
|
|
{ |
|
92
|
|
|
// available options |
|
93
|
9 |
|
$resolver->setDefined($this->elements); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|