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/Compiler.php

116 lines
2.7 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.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;
/**
* This class is used to remove circular dependencies between individual passes.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class Compiler
{
private $passConfig;
private $log = array();
2011-04-12 23:51:22 +01:00
private $loggingFormatter;
private $serviceReferenceGraph;
public function __construct()
{
$this->passConfig = new PassConfig();
$this->serviceReferenceGraph = new ServiceReferenceGraph();
2011-04-12 23:51:22 +01:00
$this->loggingFormatter = new LoggingFormatter();
}
2011-02-13 18:06:41 +00:00
/**
* Returns the PassConfig.
*
* @return PassConfig The PassConfig instance
*/
public function getPassConfig()
{
return $this->passConfig;
}
2011-02-13 18:06:41 +00:00
/**
* Returns the ServiceReferenceGraph.
*
* @return ServiceReferenceGraph The ServiceReferenceGraph instance
*/
public function getServiceReferenceGraph()
{
return $this->serviceReferenceGraph;
}
2011-04-12 23:51:22 +01:00
/**
* Returns the logging formatter which can be used by compilation passes.
*
* @return LoggingFormatter
*/
public function getLoggingFormatter()
{
return $this->loggingFormatter;
}
2011-02-13 18:06:41 +00:00
/**
* Adds a pass to the PassConfig.
*
* @param CompilerPassInterface $pass A compiler pass
* @param string $type The type of the pass
* @param int $priority Used to sort the passes
2011-02-13 18:06:41 +00:00
*/
public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/**, $priority = 0*/)
{
// For BC
if (func_num_args() >= 3) {
$priority = func_get_arg(2);
} else {
$priority = 0;
}
$this->passConfig->addPass($pass, $type, $priority);
}
2011-02-13 18:06:41 +00:00
/**
* Adds a log message.
*
2011-04-12 23:51:22 +01:00
* @param string $string The log message
2011-02-13 18:06:41 +00:00
*/
public function addLogMessage($string)
{
$this->log[] = $string;
}
2011-02-13 18:06:41 +00:00
/**
* Returns the log.
*
* @return array Log array
*/
public function getLog()
{
return $this->log;
}
2011-02-13 18:06:41 +00:00
/**
* Run the Compiler and process all Passes.
*
2011-04-12 23:51:22 +01:00
* @param ContainerBuilder $container
2011-02-13 18:06:41 +00:00
*/
public function compile(ContainerBuilder $container)
{
foreach ($this->passConfig->getPasses() as $pass) {
$pass->process($container);
}
}
2011-06-08 11:16:48 +01:00
}