1 | <?php |
||
31 | class PropertyParser |
||
32 | { |
||
33 | /** |
||
34 | * |
||
35 | * @var \Mcustiel\SimpleRequest\Interfaces\ValidatorInterface[] |
||
36 | */ |
||
37 | private $validators; |
||
38 | /** |
||
39 | * |
||
40 | * @var \Mcustiel\SimpleRequest\Interfaces\FilterInterface[] |
||
41 | */ |
||
42 | private $filters; |
||
43 | /** |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | private $name; |
||
48 | /** |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $type; |
||
53 | /** |
||
54 | * |
||
55 | * @var RequestBuilder |
||
56 | */ |
||
57 | private $requestBuilder; |
||
58 | |||
59 | /** |
||
60 | * Class constructor. Initialized with the property name. |
||
61 | * |
||
62 | * @param string $name |
||
63 | */ |
||
64 | 86 | public function __construct($name, RequestBuilder $requestBuilder) |
|
72 | |||
73 | /** |
||
74 | * Adds a validator to the parser. |
||
75 | * |
||
76 | * @param \Mcustiel\SimpleRequest\Interfaces\ValidatorInterface $validator |
||
77 | */ |
||
78 | 85 | public function addValidator(ValidatorInterface $validator) |
|
82 | |||
83 | /** |
||
84 | * Adds a filter to the parser. |
||
85 | * |
||
86 | * @param \Mcustiel\SimpleRequest\Interfaces\FilterInterface $filter |
||
87 | */ |
||
88 | 12 | public function addFilter(FilterInterface $filter) |
|
92 | |||
93 | /** |
||
94 | * Returns the name of the property. |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | 88 | public function getName() |
|
102 | |||
103 | /** |
||
104 | * |
||
105 | * @param string $type |
||
106 | */ |
||
107 | 2 | public function setType($type) |
|
112 | |||
113 | /** |
||
114 | * Filters and validates a value. And return the filtered value. |
||
115 | * It throws an exception if the value is not valid. |
||
116 | * |
||
117 | * @param mixed $value |
||
118 | * @return mixed |
||
119 | * |
||
120 | * @throws \Mcustiel\SimpleRequest\Exception\InvalidValueException |
||
121 | */ |
||
122 | 88 | public function parse($value) |
|
133 | |||
134 | 88 | private function cloneValue($value) |
|
141 | |||
142 | /** |
||
143 | * Checks the value against all validators. |
||
144 | * |
||
145 | * @param mixed $value |
||
146 | * |
||
147 | * @throws \Mcustiel\SimpleRequest\Exception\InvalidValueException |
||
148 | */ |
||
149 | 88 | private function validate($value) |
|
159 | |||
160 | /** |
||
161 | * Run all the filters on the value. |
||
162 | * |
||
163 | * @param mixed $value |
||
164 | * |
||
165 | * @return mixed |
||
166 | */ |
||
167 | 88 | private function runFilters($value) |
|
178 | |||
179 | /** |
||
180 | * Parses the value as it is an instance of the class specified in type property. |
||
181 | * |
||
182 | * @param array|\stdClass $value The value to parse and convert to an object |
||
183 | * |
||
184 | * @throws \Mcustiel\SimpleRequest\Exception\InvalidAnnotationException |
||
185 | * @return object Parsed value as instance of class specified in type property |
||
186 | */ |
||
187 | 2 | private function createInstanceOfTypeFromValue($value) |
|
199 | } |
||
200 |