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\Security\TestProvider; |
12
|
|
|
|
13
|
|
|
use Psr\Log\LoggerInterface; |
14
|
|
|
use Psr\Log\LoggerAwareInterface; |
15
|
|
|
use Symfony\Component\Routing\Route; |
16
|
|
|
use Yarhon\RouteGuardBundle\Controller\ControllerMetadata; |
17
|
|
|
use Yarhon\RouteGuardBundle\Security\Test\AbstractTestBagInterface; |
18
|
|
|
use Yarhon\RouteGuardBundle\Exception\LogicException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ProviderAggregate implements LoggerAwareInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ProviderInterface[] |
27
|
|
|
*/ |
28
|
|
|
private $testProviders; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var LoggerInterface; |
32
|
|
|
*/ |
33
|
|
|
private $logger; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param \Traversable|ProviderInterface[] $testProviders |
37
|
|
|
*/ |
38
|
21 |
|
public function __construct($testProviders = []) |
39
|
|
|
{ |
40
|
21 |
|
$this->testProviders = $testProviders; |
41
|
21 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
19 |
|
public function setLogger(LoggerInterface $logger) |
47
|
|
|
{ |
48
|
19 |
|
$this->logger = $logger; |
49
|
|
|
|
50
|
19 |
|
foreach ($this->testProviders as $provider) { |
51
|
19 |
|
$provider->setLogger($this->logger); |
52
|
|
|
} |
53
|
19 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $routeName |
57
|
|
|
* @param Route $route |
58
|
|
|
* @param ControllerMetadata|null $controllerMetadata |
59
|
|
|
* |
60
|
|
|
* @return AbstractTestBagInterface[] |
61
|
|
|
* |
62
|
|
|
* @throws LogicException |
63
|
|
|
*/ |
64
|
20 |
|
public function getTests($routeName, Route $route, ControllerMetadata $controllerMetadata = null) |
65
|
|
|
{ |
66
|
20 |
|
if (0 === count($this->testProviders)) { |
67
|
1 |
|
throw new LogicException('Test providers collection is empty.'); |
68
|
|
|
} |
69
|
|
|
|
70
|
19 |
|
$testBags = []; |
71
|
|
|
|
72
|
19 |
|
foreach ($this->testProviders as $provider) { |
73
|
19 |
|
$testBag = $provider->getTests($routeName, $route, $controllerMetadata); |
74
|
|
|
|
75
|
19 |
|
if (null !== $testBag) { |
76
|
19 |
|
$testBag->setProviderClass(get_class($provider)); |
77
|
19 |
|
$testBags[] = $testBag; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
19 |
|
return $testBags; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|