Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\DependencyInjection\Compiler; Chris@0: Chris@0: use Symfony\Component\DependencyInjection\ContainerBuilder; Chris@0: use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; Chris@0: Chris@0: /** Chris@0: * A pass that might be run repeatedly. Chris@0: * Chris@0: * @author Johannes M. Schmitt Chris@0: */ Chris@0: class RepeatedPass implements CompilerPassInterface Chris@0: { Chris@0: /** Chris@0: * @var bool Chris@0: */ Chris@0: private $repeat = false; Chris@0: Chris@0: private $passes; Chris@0: Chris@0: /** Chris@0: * @param RepeatablePassInterface[] $passes An array of RepeatablePassInterface objects Chris@0: * Chris@0: * @throws InvalidArgumentException when the passes don't implement RepeatablePassInterface Chris@0: */ Chris@0: public function __construct(array $passes) Chris@0: { Chris@0: foreach ($passes as $pass) { Chris@0: if (!$pass instanceof RepeatablePassInterface) { Chris@0: throw new InvalidArgumentException('$passes must be an array of RepeatablePassInterface.'); Chris@0: } Chris@0: Chris@0: $pass->setRepeatedPass($this); Chris@0: } Chris@0: Chris@0: $this->passes = $passes; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Process the repeatable passes that run more than once. Chris@0: */ Chris@0: public function process(ContainerBuilder $container) Chris@0: { Chris@0: do { Chris@0: $this->repeat = false; Chris@0: foreach ($this->passes as $pass) { Chris@0: $pass->process($container); Chris@0: } Chris@0: } while ($this->repeat); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets if the pass should repeat. Chris@0: */ Chris@0: public function setRepeat() Chris@0: { Chris@0: $this->repeat = true; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the passes. Chris@0: * Chris@0: * @return RepeatablePassInterface[] An array of RepeatablePassInterface objects Chris@0: */ Chris@0: public function getPasses() Chris@0: { Chris@0: return $this->passes; Chris@0: } Chris@0: }