This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/Compiler/RepeatedPass.php

60 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* A pass that might be run repeatedly.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
2011-01-17 22:28:59 +00:00
class RepeatedPass implements CompilerPassInterface
{
protected $repeat;
protected $passes;
public function __construct(array $passes)
{
foreach ($passes as $pass) {
if (!$pass instanceof RepeatablePassInterface) {
throw new \InvalidArgumentException('$passes must be an array of RepeatablePassInterface.');
}
$pass->setRepeatedPass($this);
}
$this->passes = $passes;
}
public function process(ContainerBuilder $container)
{
2011-01-17 22:28:59 +00:00
$compiler = $container->getCompiler();
$this->repeat = false;
foreach ($this->passes as $pass) {
$time = microtime(true);
$pass->process($container);
2011-01-17 22:28:59 +00:00
$compiler->addLogMessage(sprintf(
'%s finished in %.3fs', get_class($pass), microtime(true) - $time
));
}
if ($this->repeat) {
$this->process($container);
}
}
public function setRepeat()
{
$this->repeat = true;
}
}