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

ResolveReferencesToAliasesPass.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 3.93 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\Alias;
 015  use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
 016  use Symfony\Component\DependencyInjection\Reference;
 017  use Symfony\Component\DependencyInjection\ContainerBuilder;
 018   
 019  /**
 020   * Replaces all references to aliases with references to the actual service.
 021   *
 022   * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 023   */
 024  class ResolveReferencesToAliasesPass implements CompilerPassInterface
 025  {
 026      private $container;
 027   
 028      /**
 029       * Processes the ContainerBuilder to replace references to aliases with actual service references.
 030       *
 031       * @param ContainerBuilder $container
 032       */
 033      public function process(ContainerBuilder $container)
 034      {
 035          $this->container = $container;
 036   
 037          foreach ($container->getDefinitions() as $definition) {
 038              if ($definition->isSynthetic() || $definition->isAbstract()) {
 039                  continue;
 040              }
 041   
 042              $definition->setArguments($this->processArguments($definition->getArguments()));
 043              $definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
 044              $definition->setProperties($this->processArguments($definition->getProperties()));
 045              $definition->setFactory($this->processFactory($definition->getFactory()));
 046              $definition->setFactoryService($this->processFactoryService($definition->getFactoryService(false)), false);
 047          }
 048   
 049          foreach ($container->getAliases() as $id => $alias) {
 050              $aliasId = (string) $alias;
 051              if ($aliasId !== $defId = $this->getDefinitionId($aliasId)) {
 052                  $container->setAlias($id, new Alias($defId, $alias->isPublic()));
 053              }
 054          }
 055      }
 056   
 057      /**
 058       * Processes the arguments to replace aliases.
 059       *
 060       * @param array $arguments An array of References
 061       *
 062       * @return array An array of References
 063       */
 064      private function processArguments(array $arguments)
 065      {
 066          foreach ($arguments as $k => $argument) {
 067              if (is_array($argument)) {
 068                  $arguments[$k] = $this->processArguments($argument);
 069              } elseif ($argument instanceof Reference) {
 070                  $defId = $this->getDefinitionId($id = (string) $argument);
 071   
 072                  if ($defId !== $id) {
 073                      $arguments[$k] = new Reference($defId, $argument->getInvalidBehavior(), $argument->isStrict(false));
 074                  }
 075              }
 076          }
 077   
 078          return $arguments;
 079      }
 080   
 081      private function processFactoryService($factoryService)
 082      {
 083          if (null === $factoryService) {
 084              return;
 085          }
 086   
 087          return $this->getDefinitionId($factoryService);
 088      }
 089   
 090      private function processFactory($factory)
 091      {
 092          if (null === $factory || !is_array($factory) || !$factory[0] instanceof Reference) {
 093              return $factory;
 094          }
 095   
 096          $defId = $this->getDefinitionId($id = (string) $factory[0]);
 097   
 098          if ($defId !== $id) {
 099              $factory[0] = new Reference($defId, $factory[0]->getInvalidBehavior(), $factory[0]->isStrict(false));
 100          }
 101   
 102          return $factory;
 103      }
 104   
 105      /**
 106       * Resolves an alias into a definition id.
 107       *
 108       * @param string $id The definition or alias id to resolve
 109       *
 110       * @return string The definition id with aliases resolved
 111       */
 112      private function getDefinitionId($id)
 113      {
 114          $seen = array();
 115          while ($this->container->hasAlias($id)) {
 116              if (isset($seen[$id])) {
 117                  throw new ServiceCircularReferenceException($id, array_keys($seen));
 118              }
 119              $seen[$id] = true;
 120              $id = (string) $this->container->getAlias($id);
 121          }
 122   
 123          return $id;
 124      }
 125  }
 126