alex-kalanis /
pohoda
| 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 | * partnerIdentity?: Type\Address, |
||
| 21 | * myIdentity?: Type\MyAddress, |
||
| 22 | * } $data |
||
| 23 | */ |
||
| 24 | abstract class AbstractHeader extends AbstractPart |
||
| 25 | { |
||
| 26 | use Common\AddParameterTrait; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | 54 | public function setData(array $data): parent |
|
| 32 | { |
||
| 33 | // process partner identity |
||
| 34 | 54 | if (isset($data['partnerIdentity'])) { |
|
| 35 | 43 | $parentIdentity = new Type\Address($this->namespacesPaths, $this->sanitizeEncoding, $this->normalizerFactory); |
|
| 36 | 43 | $parentIdentity->setDirectionalVariable($this->useOneDirectionalVariables)->setResolveOptions($this->resolveOptions)->setData($data['partnerIdentity']); |
|
| 37 | 43 | $data['partnerIdentity'] = $parentIdentity; |
|
| 38 | } |
||
| 39 | |||
| 40 | // process my identity |
||
| 41 | 54 | if (isset($data['myIdentity'])) { |
|
| 42 | 27 | $myIdentity = new Type\MyAddress($this->namespacesPaths, $this->sanitizeEncoding, $this->normalizerFactory); |
|
| 43 | 27 | $myIdentity->setDirectionalVariable($this->useOneDirectionalVariables)->setResolveOptions($this->resolveOptions)->setData($data['myIdentity']); |
|
| 44 | 27 | $data['myIdentity'] = $myIdentity; |
|
| 45 | } |
||
| 46 | |||
| 47 | 54 | return parent::setData($data); |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritdoc} |
||
| 52 | */ |
||
| 53 | 38 | public function getXML(): \SimpleXMLElement |
|
| 54 | { |
||
| 55 | 38 | if (is_null($this->namespace)) { |
|
| 56 | 1 | throw new \LogicException('Namespace not set.'); |
|
| 57 | } |
||
| 58 | |||
| 59 | 37 | if (is_null($this->nodePrefix)) { |
|
| 60 | 1 | throw new \LogicException('Node name prefix not set.'); |
|
| 61 | } |
||
| 62 | |||
| 63 | 36 | $xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Header', '', $this->namespace($this->namespace)); |
|
| 64 | |||
| 65 | 36 | $this->addElements($xml, \array_merge($this->elements, ['parameters']), $this->namespace); |
|
| 66 | |||
| 67 | 36 | return $xml; |
|
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * {@inheritdoc} |
||
| 72 | */ |
||
| 73 | 8 | protected function configureOptions(Common\OptionsResolver $resolver): void |
|
| 74 | { |
||
| 75 | // available options |
||
| 76 | 8 | $resolver->setDefined($this->elements); |
|
| 77 | } |
||
| 78 | } |
||
| 79 |