annotate vendor/symfony/dependency-injection/Compiler/RepeatedPass.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
rev   line source
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 /**
Chris@0 30 * @var RepeatablePassInterface[]
Chris@0 31 */
Chris@0 32 private $passes;
Chris@0 33
Chris@0 34 /**
Chris@0 35 * @param RepeatablePassInterface[] $passes An array of RepeatablePassInterface objects
Chris@0 36 *
Chris@0 37 * @throws InvalidArgumentException when the passes don't implement RepeatablePassInterface
Chris@0 38 */
Chris@0 39 public function __construct(array $passes)
Chris@0 40 {
Chris@0 41 foreach ($passes as $pass) {
Chris@0 42 if (!$pass instanceof RepeatablePassInterface) {
Chris@0 43 throw new InvalidArgumentException('$passes must be an array of RepeatablePassInterface.');
Chris@0 44 }
Chris@0 45
Chris@0 46 $pass->setRepeatedPass($this);
Chris@0 47 }
Chris@0 48
Chris@0 49 $this->passes = $passes;
Chris@0 50 }
Chris@0 51
Chris@0 52 /**
Chris@0 53 * Process the repeatable passes that run more than once.
Chris@0 54 *
Chris@0 55 * @param ContainerBuilder $container
Chris@0 56 */
Chris@0 57 public function process(ContainerBuilder $container)
Chris@0 58 {
Chris@0 59 do {
Chris@0 60 $this->repeat = false;
Chris@0 61 foreach ($this->passes as $pass) {
Chris@0 62 $pass->process($container);
Chris@0 63 }
Chris@0 64 } while ($this->repeat);
Chris@0 65 }
Chris@0 66
Chris@0 67 /**
Chris@0 68 * Sets if the pass should repeat.
Chris@0 69 */
Chris@0 70 public function setRepeat()
Chris@0 71 {
Chris@0 72 $this->repeat = true;
Chris@0 73 }
Chris@0 74
Chris@0 75 /**
Chris@0 76 * Returns the passes.
Chris@0 77 *
Chris@0 78 * @return RepeatablePassInterface[] An array of RepeatablePassInterface objects
Chris@0 79 */
Chris@0 80 public function getPasses()
Chris@0 81 {
Chris@0 82 return $this->passes;
Chris@0 83 }
Chris@0 84 }