Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ResolveDefinitionTemplatesPass.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 8.61 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Component\DependencyInjection\Compiler;
 013   
 014  use Symfony\Component\DependencyInjection\Definition;
 015  use Symfony\Component\DependencyInjection\DefinitionDecorator;
 016  use Symfony\Component\DependencyInjection\ContainerBuilder;
 017  use Symfony\Component\DependencyInjection\Exception\RuntimeException;
 018   
 019  /**
 020   * This replaces all DefinitionDecorator instances with their equivalent fully
 021   * merged Definition instance.
 022   *
 023   * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 024   * @author Nicolas Grekas <p@tchwork.com>
 025   */
 026  class ResolveDefinitionTemplatesPass implements CompilerPassInterface
 027  {
 028      private $compiler;
 029      private $formatter;
 030      private $currentId;
 031   
 032      /**
 033       * Process the ContainerBuilder to replace DefinitionDecorator instances with their real Definition instances.
 034       *
 035       * @param ContainerBuilder $container
 036       */
 037      public function process(ContainerBuilder $container)
 038      {
 039          $this->compiler = $container->getCompiler();
 040          $this->formatter = $this->compiler->getLoggingFormatter();
 041   
 042          $container->setDefinitions($this->resolveArguments($container, $container->getDefinitions(), true));
 043      }
 044   
 045      /**
 046       * Resolves definition decorator arguments.
 047       *
 048       * @param ContainerBuilder $container The ContainerBuilder
 049       * @param array            $arguments An array of arguments
 050       * @param bool             $isRoot    If we are processing the root definitions or not
 051       *
 052       * @return array
 053       */
 054      private function resolveArguments(ContainerBuilder $container, array $arguments, $isRoot = false)
 055      {
 056          foreach ($arguments as $k => $argument) {
 057              if ($isRoot) {
 058                  // yes, we are specifically fetching the definition from the
 059                  // container to ensure we are not operating on stale data
 060                  $arguments[$k] = $argument = $container->getDefinition($k);
 061                  $this->currentId = $k;
 062              }
 063              if (is_array($argument)) {
 064                  $arguments[$k] = $this->resolveArguments($container, $argument);
 065              } elseif ($argument instanceof Definition) {
 066                  if ($argument instanceof DefinitionDecorator) {
 067                      $arguments[$k] = $argument = $this->resolveDefinition($container, $argument);
 068                      if ($isRoot) {
 069                          $container->setDefinition($k, $argument);
 070                      }
 071                  }
 072                  $argument->setArguments($this->resolveArguments($container, $argument->getArguments()));
 073                  $argument->setMethodCalls($this->resolveArguments($container, $argument->getMethodCalls()));
 074                  $argument->setProperties($this->resolveArguments($container, $argument->getProperties()));
 075   
 076                  $configurator = $this->resolveArguments($container, array($argument->getConfigurator()));
 077                  $argument->setConfigurator($configurator[0]);
 078   
 079                  $factory = $this->resolveArguments($container, array($argument->getFactory()));
 080                  $argument->setFactory($factory[0]);
 081              }
 082          }
 083   
 084          return $arguments;
 085      }
 086   
 087      /**
 088       * Resolves the definition.
 089       *
 090       * @param ContainerBuilder    $container  The ContainerBuilder
 091       * @param DefinitionDecorator $definition
 092       *
 093       * @return Definition
 094       *
 095       * @throws \RuntimeException When the definition is invalid
 096       */
 097      private function resolveDefinition(ContainerBuilder $container, DefinitionDecorator $definition)
 098      {
 099          if (!$container->hasDefinition($parent = $definition->getParent())) {
 100              throw new RuntimeException(sprintf('The parent definition "%s" defined for definition "%s" does not exist.', $parent, $this->currentId));
 101          }
 102   
 103          $parentDef = $container->getDefinition($parent);
 104          if ($parentDef instanceof DefinitionDecorator) {
 105              $id = $this->currentId;
 106              $this->currentId = $parent;
 107              $parentDef = $this->resolveDefinition($container, $parentDef);
 108              $container->setDefinition($parent, $parentDef);
 109              $this->currentId = $id;
 110          }
 111   
 112          $this->compiler->addLogMessage($this->formatter->formatResolveInheritance($this, $this->currentId, $parent));
 113          $def = new Definition();
 114   
 115          // merge in parent definition
 116          // purposely ignored attributes: scope, abstract, tags
 117          $def->setClass($parentDef->getClass());
 118          $def->setArguments($parentDef->getArguments());
 119          $def->setMethodCalls($parentDef->getMethodCalls());
 120          $def->setProperties($parentDef->getProperties());
 121          $def->setAutowiringTypes($parentDef->getAutowiringTypes());
 122          if ($parentDef->getFactoryClass(false)) {
 123              $def->setFactoryClass($parentDef->getFactoryClass(false));
 124          }
 125          if ($parentDef->getFactoryMethod(false)) {
 126              $def->setFactoryMethod($parentDef->getFactoryMethod(false));
 127          }
 128          if ($parentDef->getFactoryService(false)) {
 129              $def->setFactoryService($parentDef->getFactoryService(false));
 130          }
 131          if ($parentDef->isDeprecated()) {
 132              $def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%'));
 133          }
 134          $def->setFactory($parentDef->getFactory());
 135          $def->setConfigurator($parentDef->getConfigurator());
 136          $def->setFile($parentDef->getFile());
 137          $def->setPublic($parentDef->isPublic());
 138          $def->setLazy($parentDef->isLazy());
 139          $def->setAutowired($parentDef->isAutowired());
 140   
 141          // overwrite with values specified in the decorator
 142          $changes = $definition->getChanges();
 143          if (isset($changes['class'])) {
 144              $def->setClass($definition->getClass());
 145          }
 146          if (isset($changes['factory_class'])) {
 147              $def->setFactoryClass($definition->getFactoryClass(false));
 148          }
 149          if (isset($changes['factory_method'])) {
 150              $def->setFactoryMethod($definition->getFactoryMethod(false));
 151          }
 152          if (isset($changes['factory_service'])) {
 153              $def->setFactoryService($definition->getFactoryService(false));
 154          }
 155          if (isset($changes['factory'])) {
 156              $def->setFactory($definition->getFactory());
 157          }
 158          if (isset($changes['configurator'])) {
 159              $def->setConfigurator($definition->getConfigurator());
 160          }
 161          if (isset($changes['file'])) {
 162              $def->setFile($definition->getFile());
 163          }
 164          if (isset($changes['public'])) {
 165              $def->setPublic($definition->isPublic());
 166          }
 167          if (isset($changes['lazy'])) {
 168              $def->setLazy($definition->isLazy());
 169          }
 170          if (isset($changes['deprecated'])) {
 171              $def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%'));
 172          }
 173          if (isset($changes['autowire'])) {
 174              $def->setAutowired($definition->isAutowired());
 175          }
 176          if (isset($changes['decorated_service'])) {
 177              $decoratedService = $definition->getDecoratedService();
 178              if (null === $decoratedService) {
 179                  $def->setDecoratedService($decoratedService);
 180              } else {
 181                  $def->setDecoratedService($decoratedService[0], $decoratedService[1], $decoratedService[2]);
 182              }
 183          }
 184   
 185          // merge arguments
 186          foreach ($definition->getArguments() as $k => $v) {
 187              if (is_numeric($k)) {
 188                  $def->addArgument($v);
 189                  continue;
 190              }
 191   
 192              if (0 !== strpos($k, 'index_')) {
 193                  throw new RuntimeException(sprintf('Invalid argument key "%s" found.', $k));
 194              }
 195   
 196              $index = (int) substr($k, strlen('index_'));
 197              $def->replaceArgument($index, $v);
 198          }
 199   
 200          // merge properties
 201          foreach ($definition->getProperties() as $k => $v) {
 202              $def->setProperty($k, $v);
 203          }
 204   
 205          // append method calls
 206          if (count($calls = $definition->getMethodCalls()) > 0) {
 207              $def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
 208          }
 209   
 210          // merge autowiring types
 211          foreach ($definition->getAutowiringTypes() as $autowiringType) {
 212              $def->addAutowiringType($autowiringType);
 213          }
 214   
 215          // these attributes are always taken from the child
 216          $def->setAbstract($definition->isAbstract());
 217          $def->setScope($definition->getScope(false), false);
 218          $def->setShared($definition->isShared());
 219          $def->setTags($definition->getTags());
 220   
 221          return $def;
 222      }
 223  }
 224