1 | <?php |
||||||
2 | |||||||
3 | declare(strict_types=1); |
||||||
4 | |||||||
5 | namespace Yiistack\Routing; |
||||||
6 | |||||||
7 | use Doctrine\Common\Annotations\AnnotationRegistry; |
||||||
8 | use Yiisoft\Router\Group; |
||||||
9 | use Yiisoft\Router\Route; |
||||||
10 | use Yiistack\Annotated\AnnotationLoader; |
||||||
11 | use Yiistack\Routing\Annotation\Controller; |
||||||
12 | use Yiistack\Routing\Annotation\RouteAnnotationInterface; |
||||||
13 | |||||||
14 | class RouteCompiler |
||||||
15 | { |
||||||
16 | private AnnotationLoader $loader; |
||||||
17 | |||||||
18 | 1 | public function __construct(AnnotationLoader $loader) |
|||||
19 | { |
||||||
20 | 1 | $this->loader = $loader; |
|||||
21 | 1 | } |
|||||
22 | |||||||
23 | /** |
||||||
24 | * @psalm-suppress DeprecatedMethod |
||||||
25 | * |
||||||
26 | * @return array |
||||||
27 | */ |
||||||
28 | 1 | public function compile(): array |
|||||
29 | { |
||||||
30 | // autoload |
||||||
31 | 1 | AnnotationRegistry::registerUniqueLoader('class_exists'); |
|||||
0 ignored issues
–
show
|
|||||||
32 | |||||||
33 | 1 | $compiledRoutes = []; |
|||||
34 | 1 | $controllers = $this->loader->findClasses(Controller::class); |
|||||
35 | 1 | foreach ($controllers as $annotatedClass) { |
|||||
36 | 1 | $controllerClass = $annotatedClass->getClass(); |
|||||
37 | 1 | $controller = $annotatedClass->getAnnotation(); |
|||||
38 | 1 | $controllerRoutes = $this->loader->findMethods(RouteAnnotationInterface::class, $controllerClass); |
|||||
39 | 1 | $compiledRoutes[] = Group::create( |
|||||
40 | 1 | $controller->getRoute(), |
|||||
41 | 1 | static function (Group $group) use ($controllerRoutes) { |
|||||
0 ignored issues
–
show
function(...) { /* ... */ } of type callable is incompatible with the type Yiisoft\Middleware\Dispa...ddlewareDispatcher|null expected by parameter $dispatcher of Yiisoft\Router\Group::create() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
42 | 1 | foreach ($controllerRoutes as $controllerAction) { |
|||||
43 | 1 | $group->addRoute( |
|||||
0 ignored issues
–
show
The method
addRoute() does not exist on Yiisoft\Router\Group .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
44 | 1 | Route::methods( |
|||||
45 | 1 | $controllerAction->getAnnotation()->getMethods(), |
|||||
46 | 1 | $controllerAction->getAnnotation()->getRoute(), |
|||||
47 | [ |
||||||
0 ignored issues
–
show
array($controllerAction-...thod()->getShortName()) of type array<integer,string> is incompatible with the type Yiisoft\Middleware\Dispa...ddlewareDispatcher|null expected by parameter $dispatcher of Yiisoft\Router\Route::methods() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
48 | 1 | $controllerAction->getClass()->getName(), |
|||||
49 | 1 | $controllerAction->getMethod()->getShortName(), |
|||||
50 | ] |
||||||
51 | ) |
||||||
52 | ); |
||||||
53 | } |
||||||
54 | 1 | } |
|||||
55 | ); |
||||||
56 | } |
||||||
57 | |||||||
58 | 1 | return $compiledRoutes; |
|||||
59 | } |
||||||
60 | } |
||||||
61 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.