2010-12-29 19:12:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-12-29 19:12:24 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-12-29 19:12:24 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-12-29 19:12:24 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
|
|
|
|
2011-12-04 23:51:22 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
|
|
|
|
2010-12-29 19:12:24 +00:00
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Compiler Pass Configuration.
|
2010-12-29 19:12:24 +00:00
|
|
|
*
|
2011-01-09 09:53:46 +00:00
|
|
|
* This class has a default configuration embedded.
|
|
|
|
*
|
2010-12-29 19:12:24 +00:00
|
|
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
|
|
*/
|
|
|
|
class PassConfig
|
|
|
|
{
|
2011-01-09 09:53:46 +00:00
|
|
|
const TYPE_AFTER_REMOVING = 'afterRemoving';
|
|
|
|
const TYPE_BEFORE_OPTIMIZATION = 'beforeOptimization';
|
|
|
|
const TYPE_BEFORE_REMOVING = 'beforeRemoving';
|
2010-12-29 19:12:24 +00:00
|
|
|
const TYPE_OPTIMIZE = 'optimization';
|
|
|
|
const TYPE_REMOVE = 'removing';
|
|
|
|
|
2011-03-11 13:50:46 +00:00
|
|
|
private $mergePass;
|
2013-11-10 17:06:47 +00:00
|
|
|
private $afterRemovingPasses = array();
|
|
|
|
private $beforeOptimizationPasses = array();
|
|
|
|
private $beforeRemovingPasses = array();
|
2011-03-11 13:50:46 +00:00
|
|
|
private $optimizationPasses;
|
|
|
|
private $removingPasses;
|
2010-12-29 19:12:24 +00:00
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->mergePass = new MergeExtensionConfigurationPass();
|
|
|
|
|
2017-01-08 17:25:40 +00:00
|
|
|
$this->beforeOptimizationPasses = array(
|
|
|
|
100 => array(
|
2017-07-12 11:01:37 +01:00
|
|
|
new ResolveClassPass(),
|
2017-04-07 17:38:55 +01:00
|
|
|
new ResolveInstanceofConditionalsPass(),
|
2016-10-22 17:25:15 +01:00
|
|
|
new RegisterEnvVarProcessorsPass(),
|
2017-01-08 17:25:40 +00:00
|
|
|
),
|
2017-09-19 11:45:06 +01:00
|
|
|
-1000 => array(new ExtensionCompilerPass()),
|
2017-01-08 17:25:40 +00:00
|
|
|
);
|
|
|
|
|
2016-03-05 12:39:12 +00:00
|
|
|
$this->optimizationPasses = array(array(
|
2018-03-03 10:07:55 +00:00
|
|
|
new ValidateEnvPlaceholdersPass(),
|
2017-09-07 09:34:20 +01:00
|
|
|
new ResolveChildDefinitionsPass(),
|
2017-03-16 14:19:51 +00:00
|
|
|
new ServiceLocatorTagPass(),
|
2018-12-12 13:43:43 +00:00
|
|
|
new RegisterServiceSubscribersPass(),
|
2013-09-12 11:15:48 +01:00
|
|
|
new DecoratorServicePass(),
|
2017-06-12 12:31:43 +01:00
|
|
|
new ResolveParameterPlaceHoldersPass(false),
|
2016-12-15 18:13:39 +00:00
|
|
|
new ResolveFactoryClassPass(),
|
2011-01-24 18:44:27 +00:00
|
|
|
new CheckDefinitionValidityPass(),
|
2017-01-23 22:09:54 +00:00
|
|
|
new ResolveNamedArgumentsPass(),
|
2017-09-23 23:04:06 +01:00
|
|
|
new AutowireRequiredMethodsPass(),
|
2017-03-27 19:16:27 +01:00
|
|
|
new ResolveBindingsPass(),
|
2017-09-22 18:54:05 +01:00
|
|
|
new AutowirePass(false),
|
2017-03-28 11:05:21 +01:00
|
|
|
new ResolveTaggedIteratorArgumentPass(),
|
2017-04-17 18:50:34 +01:00
|
|
|
new ResolveServiceSubscribersPass(),
|
2011-01-05 11:13:27 +00:00
|
|
|
new ResolveReferencesToAliasesPass(),
|
|
|
|
new ResolveInvalidReferencesPass(),
|
2011-01-17 22:28:59 +00:00
|
|
|
new AnalyzeServiceReferencesPass(true),
|
|
|
|
new CheckCircularReferencesPass(),
|
2011-01-26 23:14:31 +00:00
|
|
|
new CheckReferenceValidityPass(),
|
2017-09-22 18:54:05 +01:00
|
|
|
new CheckArgumentsValidityPass(false),
|
2016-03-05 12:39:12 +00:00
|
|
|
));
|
2010-12-29 19:12:24 +00:00
|
|
|
|
2017-10-06 18:34:39 +01:00
|
|
|
$this->beforeRemovingPasses = array(
|
|
|
|
-100 => array(
|
|
|
|
new ResolvePrivatesPass(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2016-03-05 12:39:12 +00:00
|
|
|
$this->removingPasses = array(array(
|
2011-01-07 14:44:29 +00:00
|
|
|
new RemovePrivateAliasesPass(),
|
|
|
|
new ReplaceAliasByActualDefinitionPass(),
|
2016-04-05 14:46:37 +01:00
|
|
|
new RemoveAbstractDefinitionsPass(),
|
2018-06-01 17:19:33 +01:00
|
|
|
new RemoveUnusedDefinitionsPass(),
|
|
|
|
new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()),
|
2018-07-04 14:24:49 +01:00
|
|
|
new AnalyzeServiceReferencesPass(),
|
2017-09-22 18:54:05 +01:00
|
|
|
new DefinitionErrorExceptionPass(),
|
2011-04-14 23:11:50 +01:00
|
|
|
new CheckExceptionOnInvalidReferenceBehaviorPass(),
|
2017-11-08 09:48:34 +00:00
|
|
|
new ResolveHotPathPass(),
|
2016-03-05 12:39:12 +00:00
|
|
|
));
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Returns all passes in order to be processed.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @return CompilerPassInterface[]
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2010-12-29 19:12:24 +00:00
|
|
|
public function getPasses()
|
|
|
|
{
|
|
|
|
return array_merge(
|
|
|
|
array($this->mergePass),
|
2016-03-05 12:39:12 +00:00
|
|
|
$this->getBeforeOptimizationPasses(),
|
|
|
|
$this->getOptimizationPasses(),
|
|
|
|
$this->getBeforeRemovingPasses(),
|
|
|
|
$this->getRemovingPasses(),
|
|
|
|
$this->getAfterRemovingPasses()
|
2010-12-29 19:12:24 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Adds a pass.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @param CompilerPassInterface $pass A Compiler pass
|
|
|
|
* @param string $type The pass type
|
|
|
|
* @param int $priority Used to sort the passes
|
2011-12-13 07:50:54 +00:00
|
|
|
*
|
2011-12-04 23:51:22 +00:00
|
|
|
* @throws InvalidArgumentException when a pass type doesn't exist
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2017-06-20 19:51:06 +01:00
|
|
|
public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
|
2010-12-29 19:12:24 +00:00
|
|
|
{
|
|
|
|
$property = $type.'Passes';
|
|
|
|
if (!isset($this->$property)) {
|
2011-12-04 23:51:22 +00:00
|
|
|
throw new InvalidArgumentException(sprintf('Invalid type "%s".', $type));
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 12:39:12 +00:00
|
|
|
$passes = &$this->$property;
|
|
|
|
|
|
|
|
if (!isset($passes[$priority])) {
|
|
|
|
$passes[$priority] = array();
|
|
|
|
}
|
|
|
|
$passes[$priority][] = $pass;
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Gets all passes for the AfterRemoving pass.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @return CompilerPassInterface[]
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2011-01-26 23:14:31 +00:00
|
|
|
public function getAfterRemovingPasses()
|
|
|
|
{
|
2016-03-05 12:39:12 +00:00
|
|
|
return $this->sortPasses($this->afterRemovingPasses);
|
2011-01-26 23:14:31 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Gets all passes for the BeforeOptimization pass.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @return CompilerPassInterface[]
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2011-01-09 09:53:46 +00:00
|
|
|
public function getBeforeOptimizationPasses()
|
|
|
|
{
|
2016-03-05 12:39:12 +00:00
|
|
|
return $this->sortPasses($this->beforeOptimizationPasses);
|
2011-01-09 09:53:46 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Gets all passes for the BeforeRemoving pass.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @return CompilerPassInterface[]
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2011-01-09 09:53:46 +00:00
|
|
|
public function getBeforeRemovingPasses()
|
|
|
|
{
|
2016-03-05 12:39:12 +00:00
|
|
|
return $this->sortPasses($this->beforeRemovingPasses);
|
2011-01-09 09:53:46 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Gets all passes for the Optimization pass.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @return CompilerPassInterface[]
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2010-12-29 19:12:24 +00:00
|
|
|
public function getOptimizationPasses()
|
|
|
|
{
|
2016-03-05 12:39:12 +00:00
|
|
|
return $this->sortPasses($this->optimizationPasses);
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Gets all passes for the Removing pass.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @return CompilerPassInterface[]
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2010-12-29 19:12:24 +00:00
|
|
|
public function getRemovingPasses()
|
|
|
|
{
|
2016-03-05 12:39:12 +00:00
|
|
|
return $this->sortPasses($this->removingPasses);
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
2016-07-12 08:46:53 +01:00
|
|
|
* Gets the Merge pass.
|
2011-02-13 18:06:41 +00:00
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @return CompilerPassInterface
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2010-12-29 19:12:24 +00:00
|
|
|
public function getMergePass()
|
|
|
|
{
|
|
|
|
return $this->mergePass;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setMergePass(CompilerPassInterface $pass)
|
|
|
|
{
|
|
|
|
$this->mergePass = $pass;
|
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Sets the AfterRemoving passes.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @param CompilerPassInterface[] $passes
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2011-01-26 23:14:31 +00:00
|
|
|
public function setAfterRemovingPasses(array $passes)
|
|
|
|
{
|
2016-03-05 12:39:12 +00:00
|
|
|
$this->afterRemovingPasses = array($passes);
|
2011-01-26 23:14:31 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Sets the BeforeOptimization passes.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @param CompilerPassInterface[] $passes
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2011-01-09 09:53:46 +00:00
|
|
|
public function setBeforeOptimizationPasses(array $passes)
|
|
|
|
{
|
2016-03-05 12:39:12 +00:00
|
|
|
$this->beforeOptimizationPasses = array($passes);
|
2011-01-09 09:53:46 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Sets the BeforeRemoving passes.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @param CompilerPassInterface[] $passes
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2011-01-09 09:53:46 +00:00
|
|
|
public function setBeforeRemovingPasses(array $passes)
|
|
|
|
{
|
2016-03-05 12:39:12 +00:00
|
|
|
$this->beforeRemovingPasses = array($passes);
|
2011-01-09 09:53:46 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Sets the Optimization passes.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @param CompilerPassInterface[] $passes
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2010-12-29 19:12:24 +00:00
|
|
|
public function setOptimizationPasses(array $passes)
|
|
|
|
{
|
2016-03-05 12:39:12 +00:00
|
|
|
$this->optimizationPasses = array($passes);
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 18:06:41 +00:00
|
|
|
/**
|
|
|
|
* Sets the Removing passes.
|
|
|
|
*
|
2016-03-05 12:39:12 +00:00
|
|
|
* @param CompilerPassInterface[] $passes
|
2011-02-13 18:06:41 +00:00
|
|
|
*/
|
2010-12-29 19:12:24 +00:00
|
|
|
public function setRemovingPasses(array $passes)
|
|
|
|
{
|
2016-03-05 12:39:12 +00:00
|
|
|
$this->removingPasses = array($passes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort passes by priority.
|
|
|
|
*
|
2016-06-29 06:43:32 +01:00
|
|
|
* @param array $passes CompilerPassInterface instances with their priority as key
|
2016-03-05 12:39:12 +00:00
|
|
|
*
|
|
|
|
* @return CompilerPassInterface[]
|
|
|
|
*/
|
|
|
|
private function sortPasses(array $passes)
|
|
|
|
{
|
2018-05-02 11:14:26 +01:00
|
|
|
if (0 === \count($passes)) {
|
2016-03-05 12:39:12 +00:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
krsort($passes);
|
|
|
|
|
|
|
|
// Flatten the array
|
2018-05-02 11:14:26 +01:00
|
|
|
return array_merge(...$passes);
|
2010-12-29 19:12:24 +00:00
|
|
|
}
|
2011-04-23 10:42:31 +01:00
|
|
|
}
|