[ Index ]

PHP Cross Reference of phpBB-3.3.7-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Compiler/ -> PassConfig.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\DependencyInjection\Compiler;
  13  
  14  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  15  
  16  /**
  17   * Compiler Pass Configuration.
  18   *
  19   * This class has a default configuration embedded.
  20   *
  21   * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  22   */
  23  class PassConfig
  24  {
  25      const TYPE_AFTER_REMOVING = 'afterRemoving';
  26      const TYPE_BEFORE_OPTIMIZATION = 'beforeOptimization';
  27      const TYPE_BEFORE_REMOVING = 'beforeRemoving';
  28      const TYPE_OPTIMIZE = 'optimization';
  29      const TYPE_REMOVE = 'removing';
  30  
  31      private $mergePass;
  32      private $afterRemovingPasses = [];
  33      private $beforeOptimizationPasses = [];
  34      private $beforeRemovingPasses = [];
  35      private $optimizationPasses;
  36      private $removingPasses;
  37  
  38      public function __construct()
  39      {
  40          $this->mergePass = new MergeExtensionConfigurationPass();
  41  
  42          $this->beforeOptimizationPasses = [
  43              100 => [
  44                  $resolveClassPass = new ResolveClassPass(),
  45                  new ResolveInstanceofConditionalsPass(),
  46                  new RegisterEnvVarProcessorsPass(),
  47              ],
  48              -1000 => [new ExtensionCompilerPass()],
  49          ];
  50  
  51          $this->optimizationPasses = [[
  52              new ResolveChildDefinitionsPass(),
  53              new ServiceLocatorTagPass(),
  54              new RegisterServiceSubscribersPass(),
  55              new DecoratorServicePass(),
  56              new ResolveParameterPlaceHoldersPass(false, false),
  57              new ResolveFactoryClassPass(),
  58              new FactoryReturnTypePass($resolveClassPass),
  59              new CheckDefinitionValidityPass(),
  60              new ResolveNamedArgumentsPass(),
  61              new AutowireRequiredMethodsPass(),
  62              new ResolveBindingsPass(),
  63              new AutowirePass(false),
  64              new ResolveTaggedIteratorArgumentPass(),
  65              new ResolveServiceSubscribersPass(),
  66              new ResolveReferencesToAliasesPass(),
  67              new ResolveInvalidReferencesPass(),
  68              new AnalyzeServiceReferencesPass(true),
  69              new CheckCircularReferencesPass(),
  70              new CheckReferenceValidityPass(),
  71              new CheckArgumentsValidityPass(false),
  72          ]];
  73  
  74          $this->beforeRemovingPasses = [
  75              -100 => [
  76                  new ResolvePrivatesPass(),
  77              ],
  78          ];
  79  
  80          $this->removingPasses = [[
  81              new RemovePrivateAliasesPass(),
  82              new ReplaceAliasByActualDefinitionPass(),
  83              new RemoveAbstractDefinitionsPass(),
  84              new RepeatedPass([
  85                  new AnalyzeServiceReferencesPass(),
  86                  new InlineServiceDefinitionsPass(),
  87                  new AnalyzeServiceReferencesPass(),
  88                  new RemoveUnusedDefinitionsPass(),
  89              ]),
  90              new DefinitionErrorExceptionPass(),
  91              new CheckExceptionOnInvalidReferenceBehaviorPass(),
  92              new ResolveHotPathPass(),
  93          ]];
  94      }
  95  
  96      /**
  97       * Returns all passes in order to be processed.
  98       *
  99       * @return CompilerPassInterface[]
 100       */
 101      public function getPasses()
 102      {
 103          return array_merge(
 104              [$this->mergePass],
 105              $this->getBeforeOptimizationPasses(),
 106              $this->getOptimizationPasses(),
 107              $this->getBeforeRemovingPasses(),
 108              $this->getRemovingPasses(),
 109              $this->getAfterRemovingPasses()
 110          );
 111      }
 112  
 113      /**
 114       * Adds a pass.
 115       *
 116       * @param CompilerPassInterface $pass A Compiler pass
 117       * @param string                $type The pass type
 118       *
 119       * @throws InvalidArgumentException when a pass type doesn't exist
 120       */
 121      public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_OPTIMIZATION/*, int $priority = 0*/)
 122      {
 123          if (\func_num_args() >= 3) {
 124              $priority = func_get_arg(2);
 125          } else {
 126              if (__CLASS__ !== static::class) {
 127                  $r = new \ReflectionMethod($this, __FUNCTION__);
 128                  if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
 129                      @trigger_error(sprintf('Method %s() will have a third `int $priority = 0` argument in version 4.0. Not defining it is deprecated since Symfony 3.2.', __METHOD__), \E_USER_DEPRECATED);
 130                  }
 131              }
 132  
 133              $priority = 0;
 134          }
 135  
 136          $property = $type.'Passes';
 137          if (!isset($this->$property)) {
 138              throw new InvalidArgumentException(sprintf('Invalid type "%s".', $type));
 139          }
 140  
 141          $passes = &$this->$property;
 142  
 143          if (!isset($passes[$priority])) {
 144              $passes[$priority] = [];
 145          }
 146          $passes[$priority][] = $pass;
 147      }
 148  
 149      /**
 150       * Gets all passes for the AfterRemoving pass.
 151       *
 152       * @return CompilerPassInterface[]
 153       */
 154      public function getAfterRemovingPasses()
 155      {
 156          return $this->sortPasses($this->afterRemovingPasses);
 157      }
 158  
 159      /**
 160       * Gets all passes for the BeforeOptimization pass.
 161       *
 162       * @return CompilerPassInterface[]
 163       */
 164      public function getBeforeOptimizationPasses()
 165      {
 166          return $this->sortPasses($this->beforeOptimizationPasses);
 167      }
 168  
 169      /**
 170       * Gets all passes for the BeforeRemoving pass.
 171       *
 172       * @return CompilerPassInterface[]
 173       */
 174      public function getBeforeRemovingPasses()
 175      {
 176          return $this->sortPasses($this->beforeRemovingPasses);
 177      }
 178  
 179      /**
 180       * Gets all passes for the Optimization pass.
 181       *
 182       * @return CompilerPassInterface[]
 183       */
 184      public function getOptimizationPasses()
 185      {
 186          return $this->sortPasses($this->optimizationPasses);
 187      }
 188  
 189      /**
 190       * Gets all passes for the Removing pass.
 191       *
 192       * @return CompilerPassInterface[]
 193       */
 194      public function getRemovingPasses()
 195      {
 196          return $this->sortPasses($this->removingPasses);
 197      }
 198  
 199      /**
 200       * Gets the Merge pass.
 201       *
 202       * @return CompilerPassInterface
 203       */
 204      public function getMergePass()
 205      {
 206          return $this->mergePass;
 207      }
 208  
 209      public function setMergePass(CompilerPassInterface $pass)
 210      {
 211          $this->mergePass = $pass;
 212      }
 213  
 214      /**
 215       * Sets the AfterRemoving passes.
 216       *
 217       * @param CompilerPassInterface[] $passes
 218       */
 219      public function setAfterRemovingPasses(array $passes)
 220      {
 221          $this->afterRemovingPasses = [$passes];
 222      }
 223  
 224      /**
 225       * Sets the BeforeOptimization passes.
 226       *
 227       * @param CompilerPassInterface[] $passes
 228       */
 229      public function setBeforeOptimizationPasses(array $passes)
 230      {
 231          $this->beforeOptimizationPasses = [$passes];
 232      }
 233  
 234      /**
 235       * Sets the BeforeRemoving passes.
 236       *
 237       * @param CompilerPassInterface[] $passes
 238       */
 239      public function setBeforeRemovingPasses(array $passes)
 240      {
 241          $this->beforeRemovingPasses = [$passes];
 242      }
 243  
 244      /**
 245       * Sets the Optimization passes.
 246       *
 247       * @param CompilerPassInterface[] $passes
 248       */
 249      public function setOptimizationPasses(array $passes)
 250      {
 251          $this->optimizationPasses = [$passes];
 252      }
 253  
 254      /**
 255       * Sets the Removing passes.
 256       *
 257       * @param CompilerPassInterface[] $passes
 258       */
 259      public function setRemovingPasses(array $passes)
 260      {
 261          $this->removingPasses = [$passes];
 262      }
 263  
 264      /**
 265       * Sort passes by priority.
 266       *
 267       * @param array $passes CompilerPassInterface instances with their priority as key
 268       *
 269       * @return CompilerPassInterface[]
 270       */
 271      private function sortPasses(array $passes)
 272      {
 273          if (0 === \count($passes)) {
 274              return [];
 275          }
 276  
 277          krsort($passes);
 278  
 279          // Flatten the array
 280          return \call_user_func_array('array_merge', $passes);
 281      }
 282  }


Generated: Thu Mar 24 21:31:15 2022 Cross-referenced by PHPXref 0.7.1