|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\DependencyInjection\Compiler; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* A pass that might be run repeatedly. |
|
|
18 |
* |
|
|
19 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
20 |
*/ |
|
|
21 |
class RepeatedPass implements CompilerPassInterface |
|
|
22 |
{ |
|
|
23 |
private $repeat; |
|
|
24 |
private $passes; |
|
|
25 |
|
|
|
26 |
/** |
|
|
27 |
* Constructor. |
|
|
28 |
* |
|
|
29 |
* @param array $passes An array of RepeatablePassInterface objects |
|
|
30 |
*/ |
|
|
31 |
public function __construct(array $passes) |
|
|
32 |
{ |
|
|
33 |
foreach ($passes as $pass) { |
|
|
34 |
if (!$pass instanceof RepeatablePassInterface) { |
|
|
35 |
throw new \InvalidArgumentException('$passes must be an array of RepeatablePassInterface.'); |
|
|
36 |
} |
|
|
37 |
|
|
|
38 |
$pass->setRepeatedPass($this); |
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
$this->passes = $passes; |
|
|
42 |
} |
|
|
43 |
|
|
|
44 |
/** |
|
|
45 |
* Process the repeatable passes that run more than once. |
|
|
46 |
* |
|
|
47 |
* @param ContainerBuilder $container |
|
|
48 |
*/ |
|
|
49 |
public function process(ContainerBuilder $container) |
|
|
50 |
{ |
|
|
51 |
$compiler = $container->getCompiler(); |
|
|
52 |
$this->repeat = false; |
|
|
53 |
foreach ($this->passes as $pass) { |
|
|
54 |
$pass->process($container); |
|
|
55 |
} |
|
|
56 |
|
|
|
57 |
if ($this->repeat) { |
|
|
58 |
$this->process($container); |
|
|
59 |
} |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
/** |
|
|
63 |
* Sets if the pass should repeat |
|
|
64 |
*/ |
|
|
65 |
public function setRepeat() |
|
|
66 |
{ |
|
|
67 |
$this->repeat = true; |
|
|
68 |
} |
|
|
69 |
|
|
|
70 |
/** |
|
|
71 |
* Returns the passes |
|
|
72 |
* |
|
|
73 |
* @return array An array of RepeatablePassInterface objects |
|
|
74 |
*/ |
|
|
75 |
public function getPasses() |
|
|
76 |
{ |
|
|
77 |
return $this->passes; |
|
|
78 |
} |
|
|
79 |
} |