1 | <?php |
||
15 | class AttributeProcessor extends AbstractProcessor |
||
16 | { |
||
17 | /** |
||
18 | * Pattern of "type" parameter of attribute annotation |
||
19 | */ |
||
20 | const DATATYPE_PATTERN = '~^(?<type>[a-z_][a-z0-9_]*)\s*(?:\((?<params>[^\)]*)\))?$~i'; |
||
21 | |||
22 | /** |
||
23 | * Process annotations |
||
24 | * |
||
25 | * @param \ReflectionClass $reflection |
||
26 | * @param Definition $definition |
||
27 | */ |
||
28 | 4 | public function process(\ReflectionClass $reflection, Definition $definition) |
|
40 | |||
41 | /** |
||
42 | * Process property of class |
||
43 | * |
||
44 | * @param \ReflectionProperty $property |
||
45 | * @param Definition $definition |
||
46 | */ |
||
47 | 2 | protected function processProperty(\ReflectionProperty $property, Definition $definition) |
|
61 | |||
62 | /** |
||
63 | * Process method of class |
||
64 | * |
||
65 | * @param \ReflectionMethod $method |
||
66 | * @param Definition $definition |
||
67 | */ |
||
68 | 4 | protected function processMethod(\ReflectionMethod $method, Definition $definition) |
|
82 | |||
83 | /** |
||
84 | * Validate method with attribute definition |
||
85 | * |
||
86 | * @param AttributeAnnotation $annotation |
||
87 | * @param \ReflectionMethod $method |
||
88 | * @throws \LogicException |
||
89 | */ |
||
90 | 2 | protected function validateMethodAttribute(AttributeAnnotation $annotation, \ReflectionMethod $method) |
|
106 | |||
107 | /** |
||
108 | * Create attribute by annotation of property |
||
109 | * |
||
110 | * @param AttributeAnnotation $annotation |
||
111 | * @param \ReflectionProperty $property |
||
112 | * @return Attribute |
||
113 | */ |
||
114 | 2 | protected function createAttributeByProperty(AttributeAnnotation $annotation, \ReflectionProperty $property): Attribute |
|
139 | |||
140 | /** |
||
141 | * Process optional properties of attribute |
||
142 | * |
||
143 | * @param AttributeAnnotation $annotation |
||
144 | * @param Attribute $attribute |
||
145 | */ |
||
146 | 2 | protected function processAttributeOptions(AttributeAnnotation $annotation, Attribute $attribute) |
|
160 | |||
161 | /** |
||
162 | * Create attribute by annotation of method |
||
163 | * |
||
164 | * @param AttributeAnnotation $annotation |
||
165 | * @param \ReflectionMethod $method |
||
166 | * @return Attribute |
||
167 | */ |
||
168 | 2 | protected function createAttributeByMethod(AttributeAnnotation $annotation, \ReflectionMethod $method): Attribute |
|
182 | |||
183 | /** |
||
184 | * Resolve name of attribute by method |
||
185 | * |
||
186 | * @param \ReflectionMethod $method |
||
187 | * @return string |
||
188 | */ |
||
189 | 2 | protected function resolveNameByMethod(\ReflectionMethod $method): string |
|
199 | |||
200 | /** |
||
201 | * Process data-type |
||
202 | * |
||
203 | * @param string $definition |
||
204 | * @param Attribute $attribute |
||
205 | */ |
||
206 | 4 | protected function processDataType(string $definition, Attribute $attribute) |
|
223 | } |