Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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:58 - Dateigröße: 5.42 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   */
 025  class ResolveDefinitionTemplatesPass implements CompilerPassInterface
 026  {
 027      private $container;
 028      private $compiler;
 029      private $formatter;
 030   
 031      /**
 032       * Process the ContainerBuilder to replace DefinitionDecorator instances with their real Definition instances.
 033       *
 034       * @param ContainerBuilder $container
 035       */
 036      public function process(ContainerBuilder $container)
 037      {
 038          $this->container = $container;
 039          $this->compiler = $container->getCompiler();
 040          $this->formatter = $this->compiler->getLoggingFormatter();
 041   
 042          foreach (array_keys($container->getDefinitions()) as $id) {
 043              // yes, we are specifically fetching the definition from the
 044              // container to ensure we are not operating on stale data
 045              $definition = $container->getDefinition($id);
 046              if (!$definition instanceof DefinitionDecorator || $definition->isAbstract()) {
 047                  continue;
 048              }
 049   
 050              $this->resolveDefinition($id, $definition);
 051          }
 052      }
 053   
 054      /**
 055       * Resolves the definition
 056       *
 057       * @param string              $id         The definition identifier
 058       * @param DefinitionDecorator $definition
 059       *
 060       * @return Definition
 061       *
 062       * @throws \RuntimeException When the definition is invalid
 063       */
 064      private function resolveDefinition($id, DefinitionDecorator $definition)
 065      {
 066          if (!$this->container->hasDefinition($parent = $definition->getParent())) {
 067              throw new RuntimeException(sprintf('The parent definition "%s" defined for definition "%s" does not exist.', $parent, $id));
 068          }
 069   
 070          $parentDef = $this->container->getDefinition($parent);
 071          if ($parentDef instanceof DefinitionDecorator) {
 072              $parentDef = $this->resolveDefinition($parent, $parentDef);
 073          }
 074   
 075          $this->compiler->addLogMessage($this->formatter->formatResolveInheritance($this, $id, $parent));
 076          $def = new Definition();
 077   
 078          // merge in parent definition
 079          // purposely ignored attributes: scope, abstract, tags
 080          $def->setClass($parentDef->getClass());
 081          $def->setArguments($parentDef->getArguments());
 082          $def->setMethodCalls($parentDef->getMethodCalls());
 083          $def->setProperties($parentDef->getProperties());
 084          $def->setFactoryClass($parentDef->getFactoryClass());
 085          $def->setFactoryMethod($parentDef->getFactoryMethod());
 086          $def->setFactoryService($parentDef->getFactoryService());
 087          $def->setConfigurator($parentDef->getConfigurator());
 088          $def->setFile($parentDef->getFile());
 089          $def->setPublic($parentDef->isPublic());
 090          $def->setLazy($parentDef->isLazy());
 091   
 092          // overwrite with values specified in the decorator
 093          $changes = $definition->getChanges();
 094          if (isset($changes['class'])) {
 095              $def->setClass($definition->getClass());
 096          }
 097          if (isset($changes['factory_class'])) {
 098              $def->setFactoryClass($definition->getFactoryClass());
 099          }
 100          if (isset($changes['factory_method'])) {
 101              $def->setFactoryMethod($definition->getFactoryMethod());
 102          }
 103          if (isset($changes['factory_service'])) {
 104              $def->setFactoryService($definition->getFactoryService());
 105          }
 106          if (isset($changes['configurator'])) {
 107              $def->setConfigurator($definition->getConfigurator());
 108          }
 109          if (isset($changes['file'])) {
 110              $def->setFile($definition->getFile());
 111          }
 112          if (isset($changes['public'])) {
 113              $def->setPublic($definition->isPublic());
 114          }
 115          if (isset($changes['lazy'])) {
 116              $def->setLazy($definition->isLazy());
 117          }
 118   
 119          // merge arguments
 120          foreach ($definition->getArguments() as $k => $v) {
 121              if (is_numeric($k)) {
 122                  $def->addArgument($v);
 123                  continue;
 124              }
 125   
 126              if (0 !== strpos($k, 'index_')) {
 127                  throw new RuntimeException(sprintf('Invalid argument key "%s" found.', $k));
 128              }
 129   
 130              $index = (int) substr($k, strlen('index_'));
 131              $def->replaceArgument($index, $v);
 132          }
 133   
 134          // merge properties
 135          foreach ($definition->getProperties() as $k => $v) {
 136              $def->setProperty($k, $v);
 137          }
 138   
 139          // append method calls
 140          if (count($calls = $definition->getMethodCalls()) > 0) {
 141              $def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
 142          }
 143   
 144          // these attributes are always taken from the child
 145          $def->setAbstract($definition->isAbstract());
 146          $def->setScope($definition->getScope());
 147          $def->setTags($definition->getTags());
 148   
 149          // set new definition on container
 150          $this->container->setDefinition($id, $def);
 151   
 152          return $def;
 153      }
 154  }
 155