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; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @property array{ |
||
| 16 | * name: string, |
||
| 17 | * description?: string, |
||
| 18 | * parameterType: string, |
||
| 19 | * parameterSettings?: IntParam\Settings, |
||
| 20 | * } $data |
||
| 21 | */ |
||
| 22 | class IntParam extends AbstractAgenda |
||
| 23 | { |
||
| 24 | /** @var string[] */ |
||
| 25 | protected array $elements = [ |
||
| 26 | 'name', |
||
| 27 | 'description', |
||
| 28 | 'parameterType', |
||
| 29 | 'parameterSettings', |
||
| 30 | ]; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | 3 | public function setData(array $data): parent |
|
| 36 | { |
||
| 37 | // prepare empty parameter list for list |
||
| 38 | 3 | if ('listValue' == $data['parameterType']) { |
|
| 39 | 1 | $data['parameterSettings'] = ['parameterList' => []]; |
|
| 40 | } |
||
| 41 | |||
| 42 | // process settings |
||
| 43 | 3 | if (isset($data['parameterSettings'])) { |
|
| 44 | 3 | $parameterSettings = new IntParam\Settings($this->dependenciesFactory); |
|
| 45 | 3 | $parameterSettings |
|
| 46 | 3 | ->setDirectionalVariable($this->useOneDirectionalVariables) |
|
| 47 | 3 | ->setResolveOptions($this->resolveOptions) |
|
| 48 | 3 | ->setData($data['parameterSettings']); |
|
| 49 | 3 | $data['parameterSettings'] = $parameterSettings; |
|
| 50 | } |
||
| 51 | |||
| 52 | 3 | return parent::setData($data); |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 53 | } |
||
| 54 | |||
| 55 | 1 | public function getImportRoot(): string |
|
| 56 | { |
||
| 57 | 1 | return 'lst:intParamDetail'; |
|
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritdoc} |
||
| 62 | */ |
||
| 63 | 2 | public function getXML(): \SimpleXMLElement |
|
| 64 | { |
||
| 65 | 2 | $xml = $this->createXML()->addChild('ipm:intParamDetail', '', $this->namespace('ipm')); |
|
| 66 | 2 | $xml->addAttribute('version', '2.0'); |
|
| 67 | |||
| 68 | 2 | $param = $xml->addChild('ipm:intParam'); |
|
| 69 | 2 | $this->addElements($param, $this->elements, 'ipm'); |
|
| 70 | |||
| 71 | 2 | return $xml; |
|
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * {@inheritdoc} |
||
| 76 | */ |
||
| 77 | 1 | protected function configureOptions(Common\OptionsResolver $resolver): void |
|
| 78 | { |
||
| 79 | // available options |
||
| 80 | 1 | $resolver->setDefined($this->elements); |
|
| 81 | |||
| 82 | // validate / format options |
||
| 83 | 1 | $resolver->setRequired('name'); |
|
| 84 | 1 | $resolver->setRequired('parameterType'); |
|
| 85 | 1 | $resolver->setAllowedValues('parameterType', ['textValue', 'currencyValue', 'booleanValue', 'numberValue', 'integerValue', 'datetimeValue', 'unit', 'listValue']); |
|
| 86 | } |
||
| 87 | } |
||
| 88 |