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

MagicGet.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 4.72 KiB


001  <?php
002   
003  declare(strict_types=1);
004   
005  namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
006   
007  use ProxyManager\Generator\MagicMethodGenerator;
008  use Zend\Code\Generator\ParameterGenerator;
009  use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializationTracker;
010  use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\PrivatePropertiesMap;
011  use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\ProtectedPropertiesMap;
012  use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
013  use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
014  use ReflectionClass;
015  use Zend\Code\Generator\MethodGenerator;
016  use Zend\Code\Generator\PropertyGenerator;
017   
018  /**
019   * Magic `__get` for lazy loading ghost objects
020   *
021   * @author Marco Pivetta <ocramius@gmail.com>
022   * @license MIT
023   */
024  class MagicGet extends MagicMethodGenerator
025  {
026      /**
027       * @var string
028       */
029      private $callParentTemplate =  <<<'PHP'
030  $this->%s && ! $this->%s && $this->%s('__get', array('name' => $name));
031   
032  if (isset(self::$%s[$name])) {
033      return $this->$name;
034  }
035   
036  if (isset(self::$%s[$name])) {
037      if ($this->%s) {
038          return $this->$name;
039      }
040   
041      // check protected property access via compatible class
042      $callers      = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
043      $caller       = isset($callers[1]) ? $callers[1] : [];
044      $object       = isset($caller['object']) ? $caller['object'] : '';
045      $expectedType = self::$%s[$name];
046   
047      if ($object instanceof $expectedType) {
048          return $this->$name;
049      }
050   
051      $class = isset($caller['class']) ? $caller['class'] : '';
052   
053      if ($class === $expectedType || is_subclass_of($class, $expectedType) || $class === 'ReflectionProperty') {
054          return $this->$name;
055      }
056  } elseif (isset(self::$%s[$name])) {
057      // check private property access via same class
058      $callers = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
059      $caller  = isset($callers[1]) ? $callers[1] : [];
060      $class   = isset($caller['class']) ? $caller['class'] : '';
061   
062      static $accessorCache = [];
063   
064      if (isset(self::$%s[$name][$class])) {
065          $cacheKey = $class . '#' . $name;
066          $accessor = isset($accessorCache[$cacheKey])
067              ? $accessorCache[$cacheKey]
068              : $accessorCache[$cacheKey] = \Closure::bind(function & ($instance) use ($name) {
069                  return $instance->$name;
070              }, null, $class);
071   
072          return $accessor($this);
073      }
074   
075      if ($this->%s || 'ReflectionProperty' === $class) {
076          $tmpClass = key(self::$%s[$name]);
077          $cacheKey = $tmpClass . '#' . $name;
078          $accessor = isset($accessorCache[$cacheKey])
079              ? $accessorCache[$cacheKey]
080              : $accessorCache[$cacheKey] = \Closure::bind(function & ($instance) use ($name) {
081                  return $instance->$name;
082              }, null, $tmpClass);
083   
084          return $accessor($this);
085      }
086  }
087   
088  %s
089  PHP;
090   
091   
092      /**
093       * @param ReflectionClass        $originalClass
094       * @param PropertyGenerator      $initializerProperty
095       * @param MethodGenerator        $callInitializer
096       * @param PublicPropertiesMap    $publicProperties
097       * @param ProtectedPropertiesMap $protectedProperties
098       * @param PrivatePropertiesMap   $privateProperties
099       * @param InitializationTracker  $initializationTracker
100       *
101       * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
102       * @throws \InvalidArgumentException
103       */
104      public function __construct(
105          ReflectionClass $originalClass,
106          PropertyGenerator $initializerProperty,
107          MethodGenerator $callInitializer,
108          PublicPropertiesMap $publicProperties,
109          ProtectedPropertiesMap $protectedProperties,
110          PrivatePropertiesMap $privateProperties,
111          InitializationTracker $initializationTracker
112      ) {
113          parent::__construct($originalClass, '__get', [new ParameterGenerator('name')]);
114   
115          $override = $originalClass->hasMethod('__get');
116   
117          $parentAccess = 'return parent::__get($name);';
118   
119          if (! $override) {
120              $parentAccess = PublicScopeSimulator::getPublicAccessSimulationCode(
121                  PublicScopeSimulator::OPERATION_GET,
122                  'name'
123              );
124          }
125   
126          $this->setBody(sprintf(
127              $this->callParentTemplate,
128              $initializerProperty->getName(),
129              $initializationTracker->getName(),
130              $callInitializer->getName(),
131              $publicProperties->getName(),
132              $protectedProperties->getName(),
133              $initializationTracker->getName(),
134              $protectedProperties->getName(),
135              $privateProperties->getName(),
136              $privateProperties->getName(),
137              $initializationTracker->getName(),
138              $privateProperties->getName(),
139              $parentAccess
140          ));
141      }
142  }
143