1 | <?php |
||
28 | class AnnotationService |
||
29 | { |
||
30 | /** @var Application */ |
||
31 | private $app; |
||
32 | |||
33 | /** @var ControllerFinder */ |
||
34 | private $controllerFinder; |
||
35 | |||
36 | /** @var AnnotationReader */ |
||
37 | private $reader; |
||
38 | |||
39 | /** @var AnnotationCache */ |
||
40 | private $cache; |
||
41 | |||
42 | const CONTROLLER_CACHE_INDEX = 'annot.controllerFiles'; |
||
43 | |||
44 | /** |
||
45 | * @param Application $app |
||
46 | * @param ControllerFinder $finder |
||
47 | * @param AnnotationReader $reader |
||
48 | * @param AnnotationCache $cache |
||
49 | */ |
||
50 | public function __construct( |
||
51 | Application $app, |
||
52 | ControllerFinder $finder, |
||
53 | AnnotationReader $reader, |
||
54 | AnnotationCache $cache |
||
55 | ) { |
||
56 | $this->app = $app; |
||
57 | $this->controllerFinder = $finder; |
||
58 | $this->cache = $cache; |
||
59 | $this->reader = $reader; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @throws InvalidArgumentException |
||
64 | */ |
||
65 | public function registerControllers() |
||
66 | { |
||
67 | $controllers = $this->cache->fetch(self::CONTROLLER_CACHE_INDEX, function () { |
||
68 | $controllers = []; |
||
69 | foreach ($this->controllerFinder->getControllerClasses() as $className) { |
||
70 | $controller = $this->getControllerAnnotation($className); |
||
71 | if ($controller instanceof Controller) { |
||
72 | $controllers[$controller->getPrefix()][] = $className; |
||
73 | } |
||
74 | } |
||
75 | return $controllers; |
||
76 | }); |
||
77 | |||
78 | foreach ($controllers as $prefix => $controllerGroup) { |
||
79 | // register the controller only if the prefix matches the request uri |
||
80 | if (strpos($_SERVER['REQUEST_URI'], $this->app['annot.base_uri'].$prefix) === 0) { |
||
81 | foreach ($controllerGroup as $controllerClassName) { |
||
82 | $this->registerController($controllerClassName); |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @param string $controllerClassName |
||
90 | * @return Controller|null |
||
91 | * @throws InvalidArgumentException |
||
92 | */ |
||
93 | private function getControllerAnnotation(string $controllerClassName): ?Controller |
||
99 | |||
100 | /** |
||
101 | * Register the controller using the controller definition parsed from annotation. |
||
102 | * |
||
103 | * @param string $controllerClassName |
||
104 | * @throws InvalidArgumentException |
||
105 | */ |
||
106 | private function registerController(string $controllerClassName) |
||
119 | |||
120 | /** |
||
121 | * @param Controller $controllerAnnotation |
||
122 | */ |
||
123 | private function processClassAnnotation(Controller $controllerAnnotation) |
||
148 | } |
||
149 |
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: