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

ResolveReferencesToAliasesPass.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 2.83 KiB


 01  <?php
 02   
 03  /*
 04   * This file is part of the Symfony package.
 05   *
 06   * (c) Fabien Potencier <fabien@symfony.com>
 07   *
 08   * For the full copyright and license information, please view the LICENSE
 09   * file that was distributed with this source code.
 10   */
 11   
 12  namespace Symfony\Component\DependencyInjection\Compiler;
 13   
 14  use Symfony\Component\DependencyInjection\Alias;
 15  use Symfony\Component\DependencyInjection\Reference;
 16  use Symfony\Component\DependencyInjection\ContainerBuilder;
 17   
 18  /**
 19   * Replaces all references to aliases with references to the actual service.
 20   *
 21   * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 22   */
 23  class ResolveReferencesToAliasesPass implements CompilerPassInterface
 24  {
 25      private $container;
 26   
 27      /**
 28       * Processes the ContainerBuilder to replace references to aliases with actual service references.
 29       *
 30       * @param ContainerBuilder $container
 31       */
 32      public function process(ContainerBuilder $container)
 33      {
 34          $this->container = $container;
 35   
 36          foreach ($container->getDefinitions() as $definition) {
 37              if ($definition->isSynthetic() || $definition->isAbstract()) {
 38                  continue;
 39              }
 40   
 41              $definition->setArguments($this->processArguments($definition->getArguments()));
 42              $definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
 43              $definition->setProperties($this->processArguments($definition->getProperties()));
 44          }
 45   
 46          foreach ($container->getAliases() as $id => $alias) {
 47              $aliasId = (string) $alias;
 48              if ($aliasId !== $defId = $this->getDefinitionId($aliasId)) {
 49                  $container->setAlias($id, new Alias($defId, $alias->isPublic()));
 50              }
 51          }
 52      }
 53   
 54      /**
 55       * Processes the arguments to replace aliases.
 56       *
 57       * @param array $arguments An array of References
 58       *
 59       * @return array An array of References
 60       */
 61      private function processArguments(array $arguments)
 62      {
 63          foreach ($arguments as $k => $argument) {
 64              if (is_array($argument)) {
 65                  $arguments[$k] = $this->processArguments($argument);
 66              } elseif ($argument instanceof Reference) {
 67                  $defId = $this->getDefinitionId($id = (string) $argument);
 68   
 69                  if ($defId !== $id) {
 70                      $arguments[$k] = new Reference($defId, $argument->getInvalidBehavior(), $argument->isStrict());
 71                  }
 72              }
 73          }
 74   
 75          return $arguments;
 76      }
 77   
 78      /**
 79       * Resolves an alias into a definition id.
 80       *
 81       * @param string $id The definition or alias id to resolve
 82       *
 83       * @return string The definition id with aliases resolved
 84       */
 85      private function getDefinitionId($id)
 86      {
 87          while ($this->container->hasAlias($id)) {
 88              $id = (string) $this->container->getAlias($id);
 89          }
 90   
 91          return $id;
 92      }
 93  }
 94