2011-01-09 09:53:46 +00:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-01-09 09:53:46 +00:00
|
|
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
2011-01-16 07:53:28 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
2011-01-09 09:53:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is used to remove circular dependencies between individual passes.
|
|
|
|
*
|
|
|
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
|
|
*/
|
|
|
|
class Compiler
|
|
|
|
{
|
|
|
|
protected $passConfig;
|
|
|
|
protected $currentPass;
|
|
|
|
protected $currentStartTime;
|
|
|
|
protected $log;
|
|
|
|
protected $serviceReferenceGraph;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->passConfig = new PassConfig();
|
|
|
|
$this->serviceReferenceGraph = new ServiceReferenceGraph();
|
|
|
|
$this->log = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPassConfig()
|
|
|
|
{
|
|
|
|
return $this->passConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getServiceReferenceGraph()
|
|
|
|
{
|
|
|
|
return $this->serviceReferenceGraph;
|
|
|
|
}
|
|
|
|
|
2011-01-16 07:53:28 +00:00
|
|
|
public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
|
2011-01-09 09:53:46 +00:00
|
|
|
{
|
2011-01-16 07:53:28 +00:00
|
|
|
$this->passConfig->addPass($pass, $type);
|
2011-01-09 09:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function addLogMessage($string)
|
|
|
|
{
|
|
|
|
$this->log[] = $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLog()
|
|
|
|
{
|
|
|
|
return $this->log;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function compile(ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
foreach ($this->passConfig->getPasses() as $pass) {
|
|
|
|
$this->startPass($pass);
|
|
|
|
$pass->process($container);
|
|
|
|
$this->endPass($pass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function startPass(CompilerPassInterface $pass)
|
|
|
|
{
|
|
|
|
$this->currentPass = $pass;
|
|
|
|
$this->currentStartTime = microtime(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function endPass(CompilerPassInterface $pass)
|
|
|
|
{
|
|
|
|
$this->currentPass = null;
|
|
|
|
$this->addLogMessage(sprintf('%s finished in %.3fs', get_class($pass), microtime(true) - $this->currentStartTime));
|
|
|
|
}
|
|
|
|
}
|