inroutephp /
inroute
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types = 1); |
||
| 4 | |||
| 5 | namespace inroutephp\inroute\Compiler\Dsl; |
||
| 6 | |||
| 7 | use inroutephp\inroute\Annotations\Route; |
||
| 8 | use inroutephp\inroute\Compiler\CompilerPassInterface; |
||
| 9 | use inroutephp\inroute\Runtime\RouteInterface; |
||
| 10 | |||
| 11 | final class RouteCompilerPass implements CompilerPassInterface |
||
| 12 | { |
||
| 13 | public function processRoute(RouteInterface $route): RouteInterface |
||
| 14 | { |
||
| 15 | /** @var Route $annotation */ |
||
| 16 | foreach ($route->getAnnotations(Route::CLASS) as $annotation) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 17 | $route = $route |
||
| 18 | ->withRoutable(true) |
||
| 19 | ->withHttpMethod($annotation->method); |
||
| 20 | |||
| 21 | if ($annotation->path) { |
||
| 22 | $route = $route->withPath($annotation->path); |
||
| 23 | } |
||
| 24 | |||
| 25 | if ($annotation->name) { |
||
| 26 | $route = $route->withName($annotation->name); |
||
| 27 | } |
||
| 28 | |||
| 29 | foreach ((array)$annotation->attributes as $key => $value) { |
||
| 30 | $route = $route->withAttribute($key, $value); |
||
| 31 | } |
||
| 32 | } |
||
| 33 | |||
| 34 | return $route; |
||
| 35 | } |
||
| 36 | } |
||
| 37 |