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

InlineServiceDefinitionsPass.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.48 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\ContainerInterface;
 015  use Symfony\Component\DependencyInjection\Definition;
 016  use Symfony\Component\DependencyInjection\Reference;
 017  use Symfony\Component\DependencyInjection\ContainerBuilder;
 018   
 019  /**
 020   * Inline service definitions where this is possible.
 021   *
 022   * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 023   */
 024  class InlineServiceDefinitionsPass implements RepeatablePassInterface
 025  {
 026      private $repeatedPass;
 027      private $graph;
 028      private $compiler;
 029      private $formatter;
 030      private $currentId;
 031   
 032      /**
 033       * {@inheritdoc}
 034       */
 035      public function setRepeatedPass(RepeatedPass $repeatedPass)
 036      {
 037          $this->repeatedPass = $repeatedPass;
 038      }
 039   
 040      /**
 041       * Processes the ContainerBuilder for inline service definitions.
 042       *
 043       * @param ContainerBuilder $container
 044       */
 045      public function process(ContainerBuilder $container)
 046      {
 047          $this->compiler = $container->getCompiler();
 048          $this->formatter = $this->compiler->getLoggingFormatter();
 049          $this->graph = $this->compiler->getServiceReferenceGraph();
 050   
 051          foreach ($container->getDefinitions() as $id => $definition) {
 052              $this->currentId = $id;
 053   
 054              $definition->setArguments(
 055                  $this->inlineArguments($container, $definition->getArguments())
 056              );
 057   
 058              $definition->setMethodCalls(
 059                  $this->inlineArguments($container, $definition->getMethodCalls())
 060              );
 061   
 062              $definition->setProperties(
 063                  $this->inlineArguments($container, $definition->getProperties())
 064              );
 065          }
 066      }
 067   
 068      /**
 069       * Processes inline arguments.
 070       *
 071       * @param ContainerBuilder $container The ContainerBuilder
 072       * @param array            $arguments An array of arguments
 073       *
 074       * @return array
 075       */
 076      private function inlineArguments(ContainerBuilder $container, array $arguments)
 077      {
 078          foreach ($arguments as $k => $argument) {
 079              if (is_array($argument)) {
 080                  $arguments[$k] = $this->inlineArguments($container, $argument);
 081              } elseif ($argument instanceof Reference) {
 082                  if (!$container->hasDefinition($id = (string) $argument)) {
 083                      continue;
 084                  }
 085   
 086                  if ($this->isInlineableDefinition($container, $id, $definition = $container->getDefinition($id))) {
 087                      $this->compiler->addLogMessage($this->formatter->formatInlineService($this, $id, $this->currentId));
 088   
 089                      if (ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope()) {
 090                          $arguments[$k] = $definition;
 091                      } else {
 092                          $arguments[$k] = clone $definition;
 093                      }
 094                  }
 095              } elseif ($argument instanceof Definition) {
 096                  $argument->setArguments($this->inlineArguments($container, $argument->getArguments()));
 097                  $argument->setMethodCalls($this->inlineArguments($container, $argument->getMethodCalls()));
 098                  $argument->setProperties($this->inlineArguments($container, $argument->getProperties()));
 099              }
 100          }
 101   
 102          return $arguments;
 103      }
 104   
 105      /**
 106       * Checks if the definition is inlineable.
 107       *
 108       * @param ContainerBuilder $container
 109       * @param string           $id
 110       * @param Definition       $definition
 111       *
 112       * @return bool    If the definition is inlineable
 113       */
 114      private function isInlineableDefinition(ContainerBuilder $container, $id, Definition $definition)
 115      {
 116          if (ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope()) {
 117              return true;
 118          }
 119   
 120          if ($definition->isPublic() || $definition->isLazy()) {
 121              return false;
 122          }
 123   
 124          if (!$this->graph->hasNode($id)) {
 125              return true;
 126          }
 127   
 128          if ($this->currentId == $id) {
 129              return false;
 130          }
 131   
 132          $ids = array();
 133          foreach ($this->graph->getNode($id)->getInEdges() as $edge) {
 134              $ids[] = $edge->getSourceNode()->getId();
 135          }
 136   
 137          if (count(array_unique($ids)) > 1) {
 138              return false;
 139          }
 140   
 141          return $container->getDefinition(reset($ids))->getScope() === $definition->getScope();
 142      }
 143  }
 144