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

ProxyDumper.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 3.79 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\Bridge\ProxyManager\LazyProxy\PhpDumper;
013   
014  use ProxyManager\Generator\ClassGenerator;
015  use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
016  use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
017  use Symfony\Component\DependencyInjection\Container;
018  use Symfony\Component\DependencyInjection\ContainerInterface;
019  use Symfony\Component\DependencyInjection\Definition;
020  use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
021   
022  /**
023   * Generates dumped PHP code of proxies via reflection.
024   *
025   * @author Marco Pivetta <ocramius@gmail.com>
026   */
027  class ProxyDumper implements DumperInterface
028  {
029      /**
030       * @var string
031       */
032      private $salt;
033   
034      /**
035       * @var LazyLoadingValueHolderGenerator
036       */
037      private $proxyGenerator;
038   
039      /**
040       * @var BaseGeneratorStrategy
041       */
042      private $classGenerator;
043   
044      /**
045       * Constructor.
046       *
047       * @param string $salt
048       */
049      public function __construct($salt = '')
050      {
051          $this->salt = $salt;
052          $this->proxyGenerator = new LazyLoadingValueHolderGenerator();
053          $this->classGenerator = new BaseGeneratorStrategy();
054      }
055   
056      /**
057       * {@inheritdoc}
058       */
059      public function isProxyCandidate(Definition $definition)
060      {
061          return $definition->isLazy() && ($class = $definition->getClass()) && class_exists($class);
062      }
063   
064      /**
065       * {@inheritdoc}
066       */
067      public function getProxyFactoryCode(Definition $definition, $id)
068      {
069          $instantiation = 'return';
070   
071          if ($definition->isShared()) {
072              $instantiation .= " \$this->services['$id'] =";
073   
074              if (defined('Symfony\Component\DependencyInjection\ContainerInterface::SCOPE_CONTAINER') && ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope(false)) {
075                  $instantiation .= " \$this->scopedServices['$scope']['$id'] =";
076              }
077          }
078   
079          $methodName = 'get'.Container::camelize($id).'Service';
080          $proxyClass = $this->getProxyClassName($definition);
081   
082          $generatedClass = $this->generateProxyClass($definition);
083   
084          $constructorCall = $generatedClass->hasMethod('staticProxyConstructor')
085              ? $proxyClass.'::staticProxyConstructor'
086              : 'new '.$proxyClass;
087   
088          return <<<EOF
089          if (\$lazyLoad) {
090              \$container = \$this;
091   
092              $instantiation $constructorCall(
093                  function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) use (\$container) {
094                      \$wrappedInstance = \$container->$methodName(false);
095   
096                      \$proxy->setProxyInitializer(null);
097   
098                      return true;
099                  }
100              );
101          }
102   
103   
104  EOF;
105   
106      }
107   
108      /**
109       * {@inheritdoc}
110       */
111      public function getProxyCode(Definition $definition)
112      {
113          return $this->classGenerator->generate($this->generateProxyClass($definition));
114      }
115   
116      /**
117       * Produces the proxy class name for the given definition.
118       *
119       * @param Definition $definition
120       *
121       * @return string
122       */
123      private function getProxyClassName(Definition $definition)
124      {
125          return str_replace('\\', '', $definition->getClass()).'_'.spl_object_hash($definition).$this->salt;
126      }
127   
128      /**
129       * @param Definition $definition
130       *
131       * @return ClassGenerator
132       */
133      private function generateProxyClass(Definition $definition)
134      {
135          $generatedClass = new ClassGenerator($this->getProxyClassName($definition));
136   
137          $this->proxyGenerator->generate(new \ReflectionClass($definition->getClass()), $generatedClass);
138   
139          return $generatedClass;
140      }
141  }
142