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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
MagicIsset.php
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 `__isset` method for lazy loading ghost objects
019 *
020 * @author Marco Pivetta <ocramius@gmail.com>
021 * @license MIT
022 */
023 class MagicIsset extends MagicMethodGenerator
024 {
025 /**
026 * @var string
027 */
028 private $callParentTemplate = <<<'PHP'
029 %s
030
031 if (isset(self::$%s[$name])) {
032 return isset($this->$name);
033 }
034
035 if (isset(self::$%s[$name])) {
036 // check protected property access via compatible class
037 $callers = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
038 $caller = isset($callers[1]) ? $callers[1] : [];
039 $object = isset($caller['object']) ? $caller['object'] : '';
040 $expectedType = self::$%s[$name];
041
042 if ($object instanceof $expectedType) {
043 return isset($this->$name);
044 }
045
046 $class = isset($caller['class']) ? $caller['class'] : '';
047
048 if ($class === $expectedType || is_subclass_of($class, $expectedType)) {
049 return isset($this->$name);
050 }
051 } else {
052 // check private property access via same class
053 $callers = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
054 $caller = isset($callers[1]) ? $callers[1] : [];
055 $class = isset($caller['class']) ? $caller['class'] : '';
056
057 static $accessorCache = [];
058
059 if (isset(self::$%s[$name][$class])) {
060 $cacheKey = $class . '#' . $name;
061 $accessor = isset($accessorCache[$cacheKey])
062 ? $accessorCache[$cacheKey]
063 : $accessorCache[$cacheKey] = \Closure::bind(function ($instance) use ($name) {
064 return isset($instance->$name);
065 }, null, $class);
066
067 return $accessor($this);
068 }
069
070 if ('ReflectionProperty' === $class) {
071 $tmpClass = key(self::$%s[$name]);
072 $cacheKey = $tmpClass . '#' . $name;
073 $accessor = isset($accessorCache[$cacheKey])
074 ? $accessorCache[$cacheKey]
075 : $accessorCache[$cacheKey] = \Closure::bind(function ($instance) use ($name) {
076 return isset($instance->$name);
077 }, null, $tmpClass);
078
079 return $accessor($this);
080 }
081 }
082
083 %s
084 PHP;
085
086
087 /**
088 * @param ReflectionClass $originalClass
089 * @param PropertyGenerator $initializerProperty
090 * @param MethodGenerator $callInitializer
091 * @param PublicPropertiesMap $publicProperties
092 * @param ProtectedPropertiesMap $protectedProperties
093 * @param PrivatePropertiesMap $privateProperties
094 *
095 * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
096 * @throws \InvalidArgumentException
097 */
098 public function __construct(
099 ReflectionClass $originalClass,
100 PropertyGenerator $initializerProperty,
101 MethodGenerator $callInitializer,
102 PublicPropertiesMap $publicProperties,
103 ProtectedPropertiesMap $protectedProperties,
104 PrivatePropertiesMap $privateProperties
105 ) {
106 parent::__construct($originalClass, '__isset', [new ParameterGenerator('name')]);
107
108 $override = $originalClass->hasMethod('__isset');
109
110 $parentAccess = 'return parent::__isset($name);';
111
112 if (! $override) {
113 $parentAccess = PublicScopeSimulator::getPublicAccessSimulationCode(
114 PublicScopeSimulator::OPERATION_ISSET,
115 'name'
116 );
117 }
118
119 $this->setBody(sprintf(
120 $this->callParentTemplate,
121 '$this->' . $initializerProperty->getName() . ' && $this->' . $callInitializer->getName()
122 . '(\'__isset\', array(\'name\' => $name));',
123 $publicProperties->getName(),
124 $protectedProperties->getName(),
125 $protectedProperties->getName(),
126 $privateProperties->getName(),
127 $privateProperties->getName(),
128 $parentAccess
129 ));
130 }
131 }
132