1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* |
5
|
|
|
* (c) Yaroslav Honcharuk <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Yarhon\RouteGuardBundle\Cache\DataCollector; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Routing\Route; |
14
|
|
|
use Yarhon\RouteGuardBundle\Controller\ControllerMetadataFactory; |
15
|
|
|
use Yarhon\RouteGuardBundle\Routing\RouteMetadataFactory; |
16
|
|
|
use Yarhon\RouteGuardBundle\Security\TestProvider\ProviderAggregate; |
17
|
|
|
use Yarhon\RouteGuardBundle\Exception\ExceptionInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class RouteDataCollector |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ProviderAggregate |
26
|
|
|
*/ |
27
|
|
|
private $testProvider; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ControllerMetadataFactory |
31
|
|
|
*/ |
32
|
|
|
private $controllerMetadataFactory; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var RouteMetadataFactory |
36
|
|
|
*/ |
37
|
|
|
private $routeMetadataFactory; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param ProviderAggregate $testProvider |
41
|
|
|
* @param ControllerMetadataFactory $controllerMetadataFactory |
42
|
|
|
* @param RouteMetadataFactory $routeMetadataFactory |
43
|
|
|
*/ |
44
|
20 |
|
public function __construct(ProviderAggregate $testProvider, ControllerMetadataFactory $controllerMetadataFactory, RouteMetadataFactory $routeMetadataFactory) |
45
|
|
|
{ |
46
|
20 |
|
$this->testProvider = $testProvider; |
47
|
20 |
|
$this->controllerMetadataFactory = $controllerMetadataFactory; |
48
|
20 |
|
$this->routeMetadataFactory = $routeMetadataFactory; |
49
|
20 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $routeName |
53
|
|
|
* @param Route $route |
54
|
|
|
* @param string|null $controllerName |
55
|
|
|
* |
56
|
|
|
* @return array |
57
|
|
|
* |
58
|
|
|
* @throws ExceptionInterface |
59
|
|
|
*/ |
60
|
20 |
|
public function collect($routeName, Route $route, $controllerName = null) |
61
|
|
|
{ |
62
|
20 |
|
$controllerMetadata = $controllerName ? $this->controllerMetadataFactory->createMetadata($controllerName) : null; |
63
|
20 |
|
$routeMetadata = $this->routeMetadataFactory->createMetadata($route); |
64
|
|
|
|
65
|
20 |
|
$tests = $this->testProvider->getTests($routeName, $route, $controllerMetadata); |
66
|
|
|
|
67
|
20 |
|
return [$tests, $controllerMetadata, $routeMetadata]; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|