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

MagicUnset.php

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