|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Maba\Bundle\RestBundle\Service\Annotation; |
|
5
|
|
|
|
|
6
|
|
|
use Maba\Bundle\RestBundle\Annotation\RestAnnotationInterface; |
|
7
|
|
|
use Maba\Bundle\RestBundle\Service\RestRequestHelper; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader; |
|
9
|
|
|
use Symfony\Component\Routing\Route; |
|
10
|
|
|
use ReflectionClass; |
|
11
|
|
|
use ReflectionMethod; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @internal |
|
15
|
|
|
*/ |
|
16
|
|
|
class RoutingAnnotationLoader extends AnnotatedRouteControllerLoader |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var RestRequestHelper |
|
20
|
|
|
*/ |
|
21
|
|
|
private $restRequestHelper; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var RestRequestOptionsBuilder |
|
25
|
|
|
*/ |
|
26
|
|
|
private $restRequestOptionsBuilder; |
|
27
|
|
|
|
|
28
|
81 |
|
public function setRequestHelper(RestRequestHelper $restRequestHelper) |
|
29
|
|
|
{ |
|
30
|
81 |
|
$this->restRequestHelper = $restRequestHelper; |
|
31
|
81 |
|
} |
|
32
|
|
|
|
|
33
|
81 |
|
public function setRestRequestOptionsBuilder(RestRequestOptionsBuilder $restRequestOptionsBuilder) |
|
34
|
|
|
{ |
|
35
|
81 |
|
$this->restRequestOptionsBuilder = $restRequestOptionsBuilder; |
|
36
|
81 |
|
} |
|
37
|
|
|
|
|
38
|
81 |
|
protected function configureRoute(Route $route, ReflectionClass $class, ReflectionMethod $method, $routeAnnotation) |
|
39
|
|
|
{ |
|
40
|
81 |
|
parent::configureRoute($route, $class, $method, $routeAnnotation); |
|
41
|
|
|
|
|
42
|
81 |
|
$annotations = []; |
|
43
|
81 |
|
foreach ($this->reader->getClassAnnotations($class) as $annotation) { |
|
44
|
81 |
|
if ($annotation instanceof RestAnnotationInterface) { |
|
45
|
81 |
|
$annotations[] = $annotation; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
81 |
|
foreach ($this->reader->getMethodAnnotations($method) as $annotation) { |
|
50
|
81 |
|
if ($annotation instanceof RestAnnotationInterface) { |
|
51
|
81 |
|
$annotations[] = $annotation; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
81 |
|
if (count($annotations) === 0) { |
|
56
|
|
|
return; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
81 |
|
$this->restRequestHelper->setOptionsForRoute( |
|
60
|
81 |
|
$route, |
|
61
|
81 |
|
$this->restRequestOptionsBuilder->buildOptions($annotations, $method) |
|
62
|
|
|
); |
|
63
|
81 |
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|