Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| RouteAnnotation | |
0.00% |
0 / 8 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| types | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| name | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| regex | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| process | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Dynart\Micro\Annotation; |
| 4 | |
| 5 | use Dynart\Micro\Annotation; |
| 6 | use Dynart\Micro\Router; |
| 7 | use Dynart\Micro\MicroException; |
| 8 | |
| 9 | /** |
| 10 | * The @route annotation |
| 11 | * |
| 12 | * @see Annotation |
| 13 | * @package Dynart\Micro |
| 14 | */ |
| 15 | class RouteAnnotation implements Annotation { |
| 16 | |
| 17 | /** @var Router */ |
| 18 | private $router; |
| 19 | |
| 20 | public function __construct(Router $router) { |
| 21 | $this->router = $router; |
| 22 | } |
| 23 | |
| 24 | public function types(): array { |
| 25 | return [Annotation::TYPE_METHOD]; |
| 26 | } |
| 27 | |
| 28 | public function name(): string { |
| 29 | return 'route'; |
| 30 | } |
| 31 | |
| 32 | public function regex(): string { |
| 33 | return '(GET|POST|OPTIONS|PUT|DELETE|PATCH|BOTH)\s(.*)'; |
| 34 | } |
| 35 | |
| 36 | public function process(string $type, string $className, $subject, string $comment, array $matches): void { |
| 37 | if ($matches) { |
| 38 | $route = str_replace(' ', '', $matches[2]); // remove spaces |
| 39 | $this->router->add($route, [$className, $subject->getName()], $matches[1]); |
| 40 | } else { |
| 41 | throw new MicroException("Can't find valid route in: $comment\nA valid route example: @route GET /api/something"); |
| 42 | } |
| 43 | } |
| 44 | } |