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\Type; |
13
|
|
|
|
14
|
|
|
use Riesenia\Pohoda\AbstractAgenda; |
15
|
|
|
use Riesenia\Pohoda\Common; |
16
|
|
|
use Riesenia\Pohoda\ValueTransformer\SanitizeEncoding; |
17
|
|
|
|
18
|
|
|
class Address extends AbstractAgenda |
19
|
|
|
{ |
20
|
|
|
use Common\SetNamespaceTrait; |
21
|
|
|
|
22
|
|
|
/** @var string[] */ |
23
|
|
|
protected array $refElements = ['extId']; |
24
|
|
|
|
25
|
|
|
/** @var string[] */ |
26
|
|
|
protected array $elements = ['id', 'extId', 'address', 'addressLinkToAddress', 'shipToAddress']; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
53 |
|
public function __construct( |
32
|
|
|
Common\NamespacesPaths $namespacesPaths, |
33
|
|
|
SanitizeEncoding $sanitizeEncoding, |
34
|
|
|
string $companyRegistrationNumber, |
35
|
|
|
bool $resolveOptions = true, |
36
|
|
|
Common\OptionsResolver\Normalizers\NormalizerFactory $normalizerFactory = new Common\OptionsResolver\Normalizers\NormalizerFactory(), |
37
|
|
|
) { |
38
|
|
|
// init attributes |
39
|
53 |
|
$this->elementsAttributesMapper = [ |
40
|
53 |
|
'addressLinkToAddress' => new Common\ElementAttributes('address', 'linkToAddress'), |
41
|
53 |
|
]; |
42
|
|
|
|
43
|
53 |
|
parent::__construct($namespacesPaths, $sanitizeEncoding, $companyRegistrationNumber, $resolveOptions, $normalizerFactory); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
53 |
|
public function setData(array $data): parent |
50
|
|
|
{ |
51
|
|
|
// process address |
52
|
53 |
|
if (isset($data['address'])) { |
53
|
22 |
|
$address = new AddressType($this->namespacesPaths, $this->sanitizeEncoding, $this->companyRegistrationNumber, $this->resolveOptions, $this->normalizerFactory); |
54
|
22 |
|
$data['address'] = $address->setDirectionalVariable($this->useOneDirectionalVariables)->setData($data['address']); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// process shipping address |
58
|
53 |
|
if (isset($data['shipToAddress'])) { |
59
|
1 |
|
$shipTo = new ShipToAddressType($this->namespacesPaths, $this->sanitizeEncoding, $this->companyRegistrationNumber, $this->resolveOptions, $this->normalizerFactory); |
60
|
1 |
|
$data['shipToAddress'] = $shipTo->setDirectionalVariable($this->useOneDirectionalVariables)->setData($data['shipToAddress']); |
61
|
|
|
} |
62
|
|
|
|
63
|
53 |
|
return parent::setData($data); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
1 |
|
protected function configureOptions(Common\OptionsResolver $resolver): void |
70
|
|
|
{ |
71
|
|
|
// available options |
72
|
1 |
|
$resolver->setDefined($this->elements); |
73
|
|
|
|
74
|
|
|
// validate / format options |
75
|
1 |
|
$resolver->setNormalizer('id', $this->normalizerFactory->getClosure('int')); |
76
|
1 |
|
$resolver->setNormalizer('addressLinkToAddress', $this->normalizerFactory->getClosure('bool')); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|