-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProviderAggregate.php
More file actions
84 lines (72 loc) · 2.16 KB
/
ProviderAggregate.php
File metadata and controls
84 lines (72 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*
*
* (c) Yaroslav Honcharuk <yaroslav.xs@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Yarhon\RouteGuardBundle\Security\TestProvider;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerAwareInterface;
use Symfony\Component\Routing\Route;
use Yarhon\RouteGuardBundle\Controller\ControllerMetadata;
use Yarhon\RouteGuardBundle\Security\Test\AbstractTestBagInterface;
use Yarhon\RouteGuardBundle\Security\Test\ProviderAwareInterface;
use Yarhon\RouteGuardBundle\Exception\ExceptionInterface;
/**
* @author Yaroslav Honcharuk <yaroslav.xs@gmail.com>
*/
class ProviderAggregate implements LoggerAwareInterface
{
/**
* @var ProviderInterface[]
*/
private $testProviders;
/**
* @var LoggerInterface;
*/
private $logger;
/**
* @param \Traversable|ProviderInterface[] $testProviders
*/
public function __construct($testProviders = [])
{
$this->testProviders = $testProviders;
}
/**
* {@inheritdoc}
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
foreach ($this->testProviders as $provider) {
if ($provider instanceof LoggerAwareInterface) {
$provider->setLogger($this->logger);
}
}
}
/**
* @param string $routeName
* @param Route $route
* @param ControllerMetadata|null $controllerMetadata
*
* @return AbstractTestBagInterface[]
*
* @throws ExceptionInterface
*/
public function getTests($routeName, Route $route, ControllerMetadata $controllerMetadata = null)
{
$testBags = [];
foreach ($this->testProviders as $provider) {
$testBag = $provider->getTests($routeName, $route, $controllerMetadata);
if (null !== $testBag) {
if ($testBag instanceof ProviderAwareInterface) {
$testBag->setProviderClass(get_class($provider));
}
$testBags[] = $testBag;
}
}
return $testBags;
}
}