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; |
13
|
|
|
|
14
|
|
|
use Riesenia\Pohoda\Common\OptionsResolver; |
15
|
|
|
|
16
|
|
|
class Storage extends AbstractAgenda |
17
|
|
|
{ |
18
|
1 |
|
public function getImportRoot(): string |
19
|
|
|
{ |
20
|
1 |
|
return 'lst:itemStorage'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Add substorage. |
25
|
|
|
* |
26
|
|
|
* @param self $storage |
27
|
|
|
* |
28
|
|
|
* @return $this |
29
|
|
|
*/ |
30
|
1 |
|
public function addSubstorage(self $storage): self |
31
|
|
|
{ |
32
|
1 |
|
if (!isset($this->data['subStorages']) |
33
|
1 |
|
|| !( |
34
|
1 |
|
is_array($this->data['subStorages']) |
35
|
1 |
|
|| (is_object($this->data['subStorages']) && is_a($this->data['subStorages'], \ArrayAccess::class)) |
36
|
1 |
|
) |
37
|
|
|
) { |
38
|
1 |
|
$this->data['subStorages'] = []; |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
$this->data['subStorages'][] = $storage; |
42
|
|
|
|
43
|
1 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
2 |
|
public function getXML(): \SimpleXMLElement |
50
|
|
|
{ |
51
|
2 |
|
$xml = $this->createXML()->addChild('str:storage', '', $this->namespace('str')); |
52
|
2 |
|
$xml->addAttribute('version', '2.0'); |
53
|
|
|
|
54
|
2 |
|
$this->storageXML($xml); |
55
|
|
|
|
56
|
2 |
|
return $xml; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Attach storage to XML element. |
61
|
|
|
* |
62
|
|
|
* @param \SimpleXMLElement $xml |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
2 |
|
public function storageXML(\SimpleXMLElement $xml): void |
67
|
|
|
{ |
68
|
2 |
|
$storage = $xml->addChild('str:itemStorage', '', $this->namespace('str')); |
69
|
2 |
|
$storage->addAttribute('code', strval($this->data['code'])); |
70
|
|
|
|
71
|
2 |
|
if (isset($this->data['name'])) { |
72
|
1 |
|
$storage->addAttribute('name', strval($this->data['name'])); |
73
|
|
|
} |
74
|
|
|
|
75
|
2 |
|
if (isset($this->data['subStorages']) && is_iterable($this->data['subStorages'])) { |
76
|
1 |
|
$subStorages = $storage->addChild('str:subStorages', '', $this->namespace('str')); |
77
|
|
|
|
78
|
1 |
|
foreach ($this->data['subStorages'] as $subStorage) { |
79
|
|
|
/** @var self $subStorage */ |
80
|
1 |
|
$subStorage->storageXML($subStorages); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
1 |
|
protected function configureOptions(OptionsResolver $resolver): void |
89
|
|
|
{ |
90
|
|
|
// available options |
91
|
1 |
|
$resolver->setDefined(['code', 'name']); |
92
|
|
|
|
93
|
|
|
// validate / format options |
94
|
1 |
|
$resolver->setRequired('code'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|