|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of php-simple-request. |
|
4
|
|
|
* |
|
5
|
|
|
* php-simple-request is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
8
|
|
|
* (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* php-simple-request is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU General Public License |
|
16
|
|
|
* along with php-simple-request. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
namespace Mcustiel\SimpleRequest; |
|
19
|
|
|
|
|
20
|
|
|
use Mcustiel\SimpleRequest\Strategies\AnnotationParserFactory; |
|
21
|
|
|
use Mcustiel\SimpleRequest\Strategies\PropertyParserBuilder; |
|
22
|
|
|
use Mcustiel\SimpleRequest\Interfaces\ReflectionService; |
|
23
|
|
|
use Mcustiel\SimpleRequest\Interfaces\AnnotationService; |
|
24
|
|
|
|
|
25
|
|
|
class ParserGenerator |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var \Mcustiel\SimpleRequest\Interfaces\AnnotationService |
|
29
|
|
|
*/ |
|
30
|
|
|
private $annotationReader; |
|
31
|
|
|
/** |
|
32
|
|
|
* @var \Mcustiel\SimpleRequest\Strategies\AnnotationParserFactory |
|
33
|
|
|
*/ |
|
34
|
|
|
private $annotationParserFactory; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var \Mcustiel\SimpleRequest\Interfaces\ReflectionService |
|
38
|
|
|
*/ |
|
39
|
|
|
private $reflectionService; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param \Mcustiel\SimpleRequest\Interfaces\AnnotationService $annotationReader |
|
43
|
|
|
* @param \Mcustiel\SimpleRequest\Strategies\AnnotationParserFactory $annotationParserFactory |
|
44
|
|
|
* @param \Mcustiel\SimpleRequest\Interfaces\ReflectionService $reflectionService |
|
45
|
|
|
*/ |
|
46
|
99 |
|
public function __construct( |
|
47
|
|
|
AnnotationService $annotationReader, |
|
48
|
|
|
AnnotationParserFactory $annotationParserFactory, |
|
49
|
|
|
ReflectionService $reflectionService |
|
50
|
|
|
) { |
|
51
|
99 |
|
$this->annotationReader = $annotationReader; |
|
52
|
99 |
|
$this->annotationParserFactory = $annotationParserFactory; |
|
53
|
99 |
|
$this->reflectionService = $reflectionService; |
|
54
|
99 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Populates the parser object with the properties parser and the class object. |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $className |
|
60
|
|
|
* @param RequestParser $parserObject |
|
61
|
|
|
* @param RequestBuilder $requestBuilder |
|
62
|
|
|
* |
|
63
|
|
|
* @return RequestParser |
|
64
|
|
|
*/ |
|
65
|
95 |
|
public function populateRequestParser( |
|
66
|
|
|
$className, |
|
67
|
|
|
RequestParser $parserObject, |
|
68
|
|
|
RequestBuilder $requestBuilder |
|
69
|
|
|
) { |
|
70
|
95 |
|
$parserObject->setRequestObject(new $className); |
|
71
|
95 |
|
foreach ($this->reflectionService->getClassProperties($className) as $property) { |
|
72
|
95 |
|
$parserObject->addPropertyParser( |
|
73
|
95 |
|
$this->getPropertyParserBuilder($property)->build($requestBuilder) |
|
74
|
95 |
|
); |
|
75
|
95 |
|
} |
|
76
|
95 |
|
return $parserObject; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
95 |
|
private function getPropertyParserBuilder(\ReflectionProperty $property) |
|
80
|
|
|
{ |
|
81
|
95 |
|
$propertyParserBuilder = new PropertyParserBuilder($property->getName()); |
|
82
|
95 |
|
foreach ($this->annotationReader->getAnnotationsFromProperty($property) as $propertyAnnotation) { |
|
83
|
95 |
|
$this->annotationParserFactory |
|
84
|
95 |
|
->getAnnotationParserFor($propertyAnnotation) |
|
|
|
|
|
|
85
|
95 |
|
->execute($propertyAnnotation, $propertyParserBuilder); |
|
|
|
|
|
|
86
|
95 |
|
} |
|
87
|
95 |
|
return $propertyParserBuilder; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: