Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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: 02.04.2025, 15:03 - Dateigröße: 5.46 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\Version;
017  use Symfony\Component\DependencyInjection\Container;
018  use Symfony\Component\DependencyInjection\ContainerBuilder;
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   * @final since version 3.3
028   */
029  class ProxyDumper implements DumperInterface
030  {
031      private $salt;
032      private $proxyGenerator;
033      private $classGenerator;
034   
035      /**
036       * @param string $salt
037       */
038      public function __construct($salt = '')
039      {
040          $this->salt = $salt;
041          $this->proxyGenerator = new LazyLoadingValueHolderGenerator();
042          $this->classGenerator = new BaseGeneratorStrategy();
043      }
044   
045      /**
046       * {@inheritdoc}
047       */
048      public function isProxyCandidate(Definition $definition)
049      {
050          return $definition->isLazy() && ($class = $definition->getClass()) && (class_exists($class) || interface_exists($class));
051      }
052   
053      /**
054       * {@inheritdoc}
055       */
056      public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null)
057      {
058          $instantiation = 'return';
059   
060          if ($definition->isShared()) {
061              $instantiation .= sprintf(' $this->%s[%s] =', method_exists(ContainerBuilder::class, 'addClassResource') || ($definition->isPublic() && !$definition->isPrivate()) ? 'services' : 'privates', var_export($id, true));
062          }
063   
064          if (null === $factoryCode) {
065              @trigger_error(sprintf('The "%s()" method expects a third argument defining the code to execute to construct your service since Symfony 3.4, providing it will be required in 4.0.', __METHOD__), \E_USER_DEPRECATED);
066              $factoryCode = '$this->get'.Container::camelize($id).'Service(false)';
067          } elseif (false === strpos($factoryCode, '(')) {
068              @trigger_error(sprintf('The "%s()" method expects its third argument to define the code to execute to construct your service since Symfony 3.4, providing it will be required in 4.0.', __METHOD__), \E_USER_DEPRECATED);
069              $factoryCode = "\$this->$factoryCode(false)";
070          }
071          $proxyClass = $this->getProxyClassName($definition);
072   
073          $hasStaticConstructor = $this->generateProxyClass($definition)->hasMethod('staticProxyConstructor');
074   
075          $constructorCall = sprintf($hasStaticConstructor ? '%s::staticProxyConstructor' : 'new %s', '\\'.$proxyClass);
076   
077          return <<<EOF
078          if (\$lazyLoad) {
079              $instantiation \$this->createProxy('$proxyClass', function () {
080                  return $constructorCall(function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) {
081                      \$wrappedInstance = $factoryCode;
082   
083                      \$proxy->setProxyInitializer(null);
084   
085                      return true;
086                  });
087              });
088          }
089   
090   
091  EOF;
092   
093      }
094   
095      /**
096       * {@inheritdoc}
097       */
098      public function getProxyCode(Definition $definition)
099      {
100          $code = $this->classGenerator->generate($this->generateProxyClass($definition));
101          $code = preg_replace('/^(class [^ ]++ extends )([^\\\\])/', '$1\\\\$2', $code);
102   
103          $code = preg_replace(
104              '/(\$this->initializer[0-9a-f]++) && \1->__invoke\(\$this->(valueHolder[0-9a-f]++), (.*?), \1\);/',
105              '$1 && ($1->__invoke(\$$2, $3, $1) || 1) && $this->$2 = \$$2;',
106              $code
107          );
108   
109          if (version_compare(self::getProxyManagerVersion(), '2.2', '<')) {
110              $code = preg_replace(
111                  '/((?:\$(?:this|initializer|instance)->)?(?:publicProperties|initializer|valueHolder))[0-9a-f]++/',
112                  '${1}'.$this->getIdentifierSuffix($definition),
113                  $code
114              );
115          }
116   
117          if (version_compare(self::getProxyManagerVersion(), '2.5', '<')) {
118              $code = preg_replace('/ \\\\Closure::bind\(function ((?:& )?\(\$instance(?:, \$value)?\))/', ' \Closure::bind(static function \1', $code);
119          }
120   
121          return $code;
122      }
123   
124      /**
125       * @return string
126       */
127      private static function getProxyManagerVersion()
128      {
129          if (!class_exists(Version::class)) {
130              return '0.0.1';
131          }
132   
133          return \defined(Version::class.'::VERSION') ? Version::VERSION : Version::getVersion();
134      }
135   
136      /**
137       * Produces the proxy class name for the given definition.
138       *
139       * @return string
140       */
141      private function getProxyClassName(Definition $definition)
142      {
143          return preg_replace('/^.*\\\\/', '', $definition->getClass()).'_'.$this->getIdentifierSuffix($definition);
144      }
145   
146      /**
147       * @return ClassGenerator
148       */
149      private function generateProxyClass(Definition $definition)
150      {
151          $generatedClass = new ClassGenerator($this->getProxyClassName($definition));
152   
153          $this->proxyGenerator->generate(new \ReflectionClass($definition->getClass()), $generatedClass);
154   
155          return $generatedClass;
156      }
157   
158      /**
159       * @return string
160       */
161      private function getIdentifierSuffix(Definition $definition)
162      {
163          return substr(hash('sha256', $definition->getClass().$this->salt), -7);
164      }
165  }
166