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

AnalyzeServiceReferencesPass.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.56 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\Reference;
 016  use Symfony\Component\DependencyInjection\ContainerBuilder;
 017   
 018  /**
 019   * Run this pass before passes that need to know more about the relation of
 020   * your services.
 021   *
 022   * This class will populate the ServiceReferenceGraph with information. You can
 023   * retrieve the graph in other passes from the compiler.
 024   *
 025   * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 026   */
 027  class AnalyzeServiceReferencesPass implements RepeatablePassInterface
 028  {
 029      private $graph;
 030      private $container;
 031      private $currentId;
 032      private $currentDefinition;
 033      private $repeatedPass;
 034      private $onlyConstructorArguments;
 035   
 036      /**
 037       * Constructor.
 038       *
 039       * @param bool    $onlyConstructorArguments Sets this Service Reference pass to ignore method calls
 040       */
 041      public function __construct($onlyConstructorArguments = false)
 042      {
 043          $this->onlyConstructorArguments = (bool) $onlyConstructorArguments;
 044      }
 045   
 046      /**
 047       * {@inheritdoc}
 048       */
 049      public function setRepeatedPass(RepeatedPass $repeatedPass)
 050      {
 051          $this->repeatedPass = $repeatedPass;
 052      }
 053   
 054      /**
 055       * Processes a ContainerBuilder object to populate the service reference graph.
 056       *
 057       * @param ContainerBuilder $container
 058       */
 059      public function process(ContainerBuilder $container)
 060      {
 061          $this->container = $container;
 062          $this->graph     = $container->getCompiler()->getServiceReferenceGraph();
 063          $this->graph->clear();
 064   
 065          foreach ($container->getDefinitions() as $id => $definition) {
 066              if ($definition->isSynthetic() || $definition->isAbstract()) {
 067                  continue;
 068              }
 069   
 070              $this->currentId = $id;
 071              $this->currentDefinition = $definition;
 072   
 073              $this->processArguments($definition->getArguments());
 074              if ($definition->getFactoryService()) {
 075                  $this->processArguments(array(new Reference($definition->getFactoryService())));
 076              }
 077   
 078              if (!$this->onlyConstructorArguments) {
 079                  $this->processArguments($definition->getMethodCalls());
 080                  $this->processArguments($definition->getProperties());
 081                  if ($definition->getConfigurator()) {
 082                      $this->processArguments(array($definition->getConfigurator()));
 083                  }
 084              }
 085          }
 086   
 087          foreach ($container->getAliases() as $id => $alias) {
 088              $this->graph->connect($id, $alias, (string) $alias, $this->getDefinition((string) $alias), null);
 089          }
 090      }
 091   
 092      /**
 093       * Processes service definitions for arguments to find relationships for the service graph.
 094       *
 095       * @param array $arguments An array of Reference or Definition objects relating to service definitions
 096       */
 097      private function processArguments(array $arguments)
 098      {
 099          foreach ($arguments as $argument) {
 100              if (is_array($argument)) {
 101                  $this->processArguments($argument);
 102              } elseif ($argument instanceof Reference) {
 103                  $this->graph->connect(
 104                      $this->currentId,
 105                      $this->currentDefinition,
 106                      $this->getDefinitionId((string) $argument),
 107                      $this->getDefinition((string) $argument),
 108                      $argument
 109                  );
 110              } elseif ($argument instanceof Definition) {
 111                  $this->processArguments($argument->getArguments());
 112                  $this->processArguments($argument->getMethodCalls());
 113                  $this->processArguments($argument->getProperties());
 114              }
 115          }
 116      }
 117   
 118      /**
 119       * Returns a service definition given the full name or an alias.
 120       *
 121       * @param string $id A full id or alias for a service definition.
 122       *
 123       * @return Definition|null The definition related to the supplied id
 124       */
 125      private function getDefinition($id)
 126      {
 127          $id = $this->getDefinitionId($id);
 128   
 129          return null === $id ? null : $this->container->getDefinition($id);
 130      }
 131   
 132      private function getDefinitionId($id)
 133      {
 134          while ($this->container->hasAlias($id)) {
 135              $id = (string) $this->container->getAlias($id);
 136          }
 137   
 138          if (!$this->container->hasDefinition($id)) {
 139              return;
 140          }
 141   
 142          return $id;
 143      }
 144  }
 145