1 | <?php |
||
24 | final class LiipImagineSerializableField implements Annotation |
||
25 | { |
||
26 | /** |
||
27 | * @var string $filter LiipImagine Filter |
||
28 | */ |
||
29 | private $filter; |
||
30 | |||
31 | /** |
||
32 | * @var string $vichUploaderField Field |
||
33 | */ |
||
34 | private $vichUploaderField; |
||
35 | |||
36 | /** |
||
37 | * @var string $virtualField Virtual Field |
||
38 | */ |
||
39 | private $virtualField; |
||
40 | |||
41 | /** |
||
42 | * @var array $options Options |
||
43 | */ |
||
44 | private $options; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * Constructor |
||
49 | * |
||
50 | * @param array $options Options |
||
51 | * |
||
52 | * @throws \Exception |
||
53 | */ |
||
54 | public function __construct(array $options) |
||
55 | { |
||
56 | $this->options = $options; |
||
57 | |||
58 | if (!array_key_exists('value', $this->options) && !array_key_exists('filter', $this->options)) { |
||
59 | throw new \LogicException(sprintf('Either "value" or "filter" option must be set.')); |
||
60 | } |
||
61 | |||
62 | if ($this->checkOption('value', true)) { |
||
63 | $this->setFilter($options['value']); |
||
64 | } elseif ($this->checkOption('filter', true)) { |
||
65 | $this->setFilter($this->options['filter']); |
||
66 | } |
||
67 | |||
68 | if ($this->checkOption('vichUploaderField', false)) { |
||
69 | $this->setVichUploaderField($this->options['vichUploaderField']); |
||
70 | } |
||
71 | |||
72 | if ($this->checkOption('virtualField', false)) { |
||
73 | $this->setVirtualField($this->options['virtualField']); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getFilter() |
||
84 | |||
85 | /** |
||
86 | * @param string $filter |
||
87 | * @return $this |
||
88 | */ |
||
89 | public function setFilter($filter) |
||
95 | |||
96 | /** |
||
97 | * @return string |
||
98 | */ |
||
99 | public function getVichUploaderField() |
||
103 | |||
104 | /** |
||
105 | * @param string $vichUploaderField |
||
106 | * @return $this |
||
107 | */ |
||
108 | public function setVichUploaderField($vichUploaderField) |
||
114 | |||
115 | /** |
||
116 | * @return string |
||
117 | */ |
||
118 | public function getVirtualField() |
||
122 | |||
123 | /** |
||
124 | * @param string $virtualField |
||
125 | * @return $this |
||
126 | */ |
||
127 | public function setVirtualField($virtualField) |
||
133 | |||
134 | /** |
||
135 | * @param string $optionName |
||
136 | * @param bool $canBeArray |
||
137 | * @return bool |
||
138 | * @throws \Exception |
||
139 | */ |
||
140 | private function checkOption($optionName, $canBeArray) |
||
154 | } |
||
155 |