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

ReplaceAliasByActualDefinitionPass.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.07 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\ContainerBuilder;
015  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
016  use Symfony\Component\DependencyInjection\Reference;
017   
018  /**
019   * Replaces aliases with actual service definitions, effectively removing these
020   * aliases.
021   *
022   * @author Johannes M. Schmitt <schmittjoh@gmail.com>
023   */
024  class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
025  {
026      private $compiler;
027      private $formatter;
028      private $sourceId;
029   
030      /**
031       * Process the Container to replace aliases with service definitions.
032       *
033       * @param ContainerBuilder $container
034       *
035       * @throws InvalidArgumentException if the service definition does not exist
036       */
037      public function process(ContainerBuilder $container)
038      {
039          $this->compiler = $container->getCompiler();
040          $this->formatter = $this->compiler->getLoggingFormatter();
041   
042          foreach ($container->getAliases() as $id => $alias) {
043              $aliasId = (string) $alias;
044   
045              try {
046                  $definition = $container->getDefinition($aliasId);
047              } catch (InvalidArgumentException $e) {
048                  throw new InvalidArgumentException(sprintf('Unable to replace alias "%s" with "%s".', $alias, $id), null, $e);
049              }
050   
051              if ($definition->isPublic()) {
052                  continue;
053              }
054   
055              $definition->setPublic(true);
056              $container->setDefinition($id, $definition);
057              $container->removeDefinition($aliasId);
058   
059              $this->updateReferences($container, $aliasId, $id);
060   
061              // we have to restart the process due to concurrent modification of
062              // the container
063              $this->process($container);
064   
065              break;
066          }
067      }
068   
069      /**
070       * Updates references to remove aliases.
071       *
072       * @param ContainerBuilder $container The container
073       * @param string           $currentId The alias identifier being replaced
074       * @param string           $newId     The id of the service the alias points to
075       */
076      private function updateReferences($container, $currentId, $newId)
077      {
078          foreach ($container->getAliases() as $id => $alias) {
079              if ($currentId === (string) $alias) {
080                  $container->setAlias($id, $newId);
081              }
082          }
083   
084          foreach ($container->getDefinitions() as $id => $definition) {
085              $this->sourceId = $id;
086   
087              $definition->setArguments(
088                  $this->updateArgumentReferences($definition->getArguments(), $currentId, $newId)
089              );
090   
091              $definition->setMethodCalls(
092                  $this->updateArgumentReferences($definition->getMethodCalls(), $currentId, $newId)
093              );
094   
095              $definition->setProperties(
096                  $this->updateArgumentReferences($definition->getProperties(), $currentId, $newId)
097              );
098          }
099      }
100   
101      /**
102       * Updates argument references.
103       *
104       * @param array  $arguments An array of Arguments
105       * @param string $currentId The alias identifier
106       * @param string $newId     The identifier the alias points to
107       *
108       * @return array
109       */
110      private function updateArgumentReferences(array $arguments, $currentId, $newId)
111      {
112          foreach ($arguments as $k => $argument) {
113              if (is_array($argument)) {
114                  $arguments[$k] = $this->updateArgumentReferences($argument, $currentId, $newId);
115              } elseif ($argument instanceof Reference) {
116                  if ($currentId === (string) $argument) {
117                      $arguments[$k] = new Reference($newId, $argument->getInvalidBehavior());
118                      $this->compiler->addLogMessage($this->formatter->formatUpdateReference($this, $this->sourceId, $currentId, $newId));
119                  }
120              }
121          }
122   
123          return $arguments;
124      }
125  }
126