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