1 | <?php |
||
19 | class ValidateInterceptor implements MethodInterceptor |
||
20 | { |
||
21 | /** |
||
22 | * @var Reader |
||
23 | */ |
||
24 | private $reader; |
||
25 | |||
26 | public function __construct(Reader $reader) |
||
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | * |
||
34 | * @throws InvalidArgumentException |
||
35 | */ |
||
36 | public function invoke(MethodInvocation $invocation) |
||
48 | |||
49 | /** |
||
50 | * Return Validate and OnFailure method |
||
51 | * |
||
52 | * @param \ReflectionMethod $method |
||
53 | * |
||
54 | * @return \ReflectionMethod[] [$onValidateMethod, $onFailureMethod] |
||
55 | */ |
||
56 | private function getOnValidate(\ReflectionMethod $method) |
||
67 | |||
68 | /** |
||
69 | * Validate with Validate method |
||
70 | * |
||
71 | * @param MethodInvocation $invocation |
||
72 | * @param \ReflectionMethod $onValidate |
||
73 | * @param \ReflectionMethod $onFailure |
||
74 | * |
||
75 | * @return bool|mixed|InvalidArgumentException |
||
76 | * |
||
77 | * @throws \Exception |
||
78 | */ |
||
79 | private function validate(MethodInvocation $invocation, \ReflectionMethod $onValidate, \ReflectionMethod $onFailure = null) |
||
95 | |||
96 | /** |
||
97 | * Return result OnFailure |
||
98 | * |
||
99 | * @param MethodInvocation $invocation |
||
100 | * @param FailureInterface $failure |
||
101 | * @param \ReflectionMethod $onFailure |
||
102 | * |
||
103 | * @return mixed|InvalidArgumentException |
||
104 | */ |
||
105 | private function getFailure(MethodInvocation $invocation, FailureInterface $failure, \ReflectionMethod $onFailure = null) |
||
113 | |||
114 | /** |
||
115 | * Return InvalidArgumentException exception |
||
116 | * |
||
117 | * @param MethodInvocation $invocation |
||
118 | * @param FailureInterface $failure |
||
119 | * |
||
120 | * @return InvalidArgumentException |
||
121 | */ |
||
122 | private function failureException(MethodInvocation $invocation, FailureInterface $failure) |
||
131 | |||
132 | /** |
||
133 | * @param \ReflectionClass $class |
||
134 | * @param Valid $valid |
||
135 | * |
||
136 | * @return \ReflectionMethod[] |
||
137 | */ |
||
138 | private function findOnMethods(\ReflectionClass $class, Valid $valid) |
||
154 | |||
155 | /** |
||
156 | * @param Valid $valid |
||
157 | * @param array $annotations |
||
158 | * @param \ReflectionMethod $method |
||
159 | * @param \ReflectionMethod $onValidateMethod |
||
160 | * @param \ReflectionMethod $onFailureMethod |
||
161 | * |
||
162 | * @return array |
||
163 | */ |
||
164 | private function scanAnnotation( |
||
182 | |||
183 | /** |
||
184 | * @param object $annotation |
||
185 | * @param Valid $valid |
||
186 | * @param \ReflectionMethod $onValidateMethod |
||
187 | * |
||
188 | * @return bool |
||
189 | */ |
||
190 | private function isOnValidateFound($annotation, Valid $valid, \ReflectionMethod $onValidateMethod = null) |
||
194 | |||
195 | /** |
||
196 | * @param object $annotation |
||
197 | * @param Valid $valid |
||
198 | * @param \ReflectionMethod $onFailureMethod |
||
199 | * |
||
200 | * @return bool |
||
201 | */ |
||
202 | private function isOnFailureFound($annotation, Valid $valid, \ReflectionMethod $onFailureMethod = null) |
||
206 | } |
||
207 |