1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of riesenia/pohoda package. |
4
|
|
|
* |
5
|
|
|
* Licensed under the MIT License |
6
|
|
|
* (c) RIESENIA.com |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace Riesenia\Pohoda; |
12
|
|
|
|
13
|
|
|
use Riesenia\Pohoda\Common\OptionsResolver; |
14
|
|
|
use Symfony\Component\OptionsResolver\Options; |
15
|
|
|
|
16
|
|
|
class ListStock extends AbstractAgenda |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
3 |
|
public function getXML(): \SimpleXMLElement |
22
|
|
|
{ |
23
|
3 |
|
$xml = $this->createXML()->addChild($this->data['namespace'] . ':list' . $this->data['type'], '', $this->namespace(strval($this->data['namespace']))); |
24
|
3 |
|
$xml->addAttribute('version', '2.0'); |
25
|
|
|
|
26
|
3 |
|
if ($this->data['timestamp']) { |
27
|
3 |
|
$date = $this->data['timestamp']; |
28
|
3 |
|
if (is_object($date) && is_a($date, \DateTimeInterface::class)) { |
29
|
3 |
|
$date = $date->format('Y-m-d\TH:i:s'); |
30
|
|
|
} |
31
|
3 |
|
$xml->addAttribute('dateTimeStamp', strval($date)); |
32
|
|
|
} |
33
|
|
|
|
34
|
3 |
|
if ($this->data['validFrom']) { |
35
|
3 |
|
$dateFrom = $this->data['validFrom']; |
36
|
3 |
|
if (is_object($dateFrom) && is_a($dateFrom, \DateTimeInterface::class)) { |
37
|
3 |
|
$dateFrom = $dateFrom->format('Y-m-d'); |
38
|
|
|
} |
39
|
3 |
|
$xml->addAttribute('dateValidFrom', strval($dateFrom)); |
40
|
|
|
} |
41
|
|
|
|
42
|
3 |
|
if ($this->data['state']) { |
43
|
3 |
|
$xml->addAttribute('state', strval($this->data['state'])); |
44
|
|
|
} |
45
|
|
|
|
46
|
3 |
|
return $xml; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
3 |
|
protected function configureOptions(OptionsResolver $resolver): void |
53
|
|
|
{ |
54
|
|
|
// available options |
55
|
1 |
|
$resolver->setDefined(['type', 'namespace', 'timestamp', 'validFrom', 'state']); |
56
|
|
|
|
57
|
|
|
// validate / format options |
58
|
1 |
|
$resolver->setRequired('type'); |
59
|
1 |
|
$resolver->setNormalizer('type', $this->normalizerFactory->getClosure('list_request_type')); |
60
|
1 |
|
$resolver->setDefault('namespace', function (Options $options) { |
61
|
3 |
|
if ('Stock' == $options['type']) { |
62
|
1 |
|
return 'lStk'; |
63
|
|
|
} |
64
|
|
|
|
65
|
2 |
|
if ('AddressBook' == $options['type']) { |
66
|
1 |
|
return 'lAdb'; |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
return 'lst'; |
70
|
1 |
|
}); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|