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 |
LazyLoadingGhostGenerator.php
001 <?php
002
003 declare(strict_types=1);
004
005 namespace ProxyManager\ProxyGenerator;
006
007 use ProxyManager\Exception\InvalidProxiedClassException;
008 use ProxyManager\Generator\MethodGenerator as ProxyManagerMethodGenerator;
009 use ProxyManager\Generator\Util\ClassGeneratorUtils;
010 use ProxyManager\Proxy\GhostObjectInterface;
011 use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
012 use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\StaticProxyConstructor;
013 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\CallInitializer;
014 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\GetProxyInitializer;
015 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\InitializeProxy;
016 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\IsProxyInitialized;
017 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicClone;
018 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet;
019 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset;
020 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSet;
021 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicSleep;
022 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset;
023 use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\SetProxyInitializer;
024 use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializationTracker;
025 use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\InitializerProperty;
026 use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\PrivatePropertiesMap;
027 use ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator\ProtectedPropertiesMap;
028 use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
029 use ProxyManager\ProxyGenerator\Util\Properties;
030 use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter;
031 use ReflectionClass;
032 use ReflectionMethod;
033 use Zend\Code\Generator\ClassGenerator;
034 use Zend\Code\Generator\MethodGenerator;
035 use Zend\Code\Reflection\MethodReflection;
036
037 /**
038 * Generator for proxies implementing {@see \ProxyManager\Proxy\GhostObjectInterface}
039 *
040 * {@inheritDoc}
041 *
042 * @author Marco Pivetta <ocramius@gmail.com>
043 * @license MIT
044 */
045 class LazyLoadingGhostGenerator implements ProxyGeneratorInterface
046 {
047 /**
048 * {@inheritDoc}
049 *
050 * @throws InvalidProxiedClassException
051 * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
052 * @throws \InvalidArgumentException
053 */
054 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator, array $proxyOptions = [])
055 {
056 CanProxyAssertion::assertClassCanBeProxied($originalClass, false);
057
058 $filteredProperties = Properties::fromReflectionClass($originalClass)
059 ->filter($proxyOptions['skippedProperties'] ?? []);
060
061 $publicProperties = new PublicPropertiesMap($filteredProperties);
062 $privateProperties = new PrivatePropertiesMap($filteredProperties);
063 $protectedProperties = new ProtectedPropertiesMap($filteredProperties);
064
065 $classGenerator->setExtendedClass($originalClass->getName());
066 $classGenerator->setImplementedInterfaces([GhostObjectInterface::class]);
067 $classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty());
068 $classGenerator->addPropertyFromGenerator($initializationTracker = new InitializationTracker());
069 $classGenerator->addPropertyFromGenerator($publicProperties);
070 $classGenerator->addPropertyFromGenerator($privateProperties);
071 $classGenerator->addPropertyFromGenerator($protectedProperties);
072
073 $init = new CallInitializer($initializer, $initializationTracker, $filteredProperties);
074
075 array_map(
076 function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) {
077 ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod);
078 },
079 array_merge(
080 $this->getAbstractProxiedMethods($originalClass),
081 [
082 $init,
083 new StaticProxyConstructor($initializer, $filteredProperties),
084 new MagicGet(
085 $originalClass,
086 $initializer,
087 $init,
088 $publicProperties,
089 $protectedProperties,
090 $privateProperties,
091 $initializationTracker
092 ),
093 new MagicSet(
094 $originalClass,
095 $initializer,
096 $init,
097 $publicProperties,
098 $protectedProperties,
099 $privateProperties
100 ),
101 new MagicIsset(
102 $originalClass,
103 $initializer,
104 $init,
105 $publicProperties,
106 $protectedProperties,
107 $privateProperties
108 ),
109 new MagicUnset(
110 $originalClass,
111 $initializer,
112 $init,
113 $publicProperties,
114 $protectedProperties,
115 $privateProperties
116 ),
117 new MagicClone($originalClass, $initializer, $init),
118 new MagicSleep($originalClass, $initializer, $init),
119 new SetProxyInitializer($initializer),
120 new GetProxyInitializer($initializer),
121 new InitializeProxy($initializer, $init),
122 new IsProxyInitialized($initializer),
123 ]
124 )
125 );
126 }
127
128 /**
129 * Retrieves all abstract methods to be proxied
130 *
131 * @param ReflectionClass $originalClass
132 *
133 * @return MethodGenerator[]
134 */
135 private function getAbstractProxiedMethods(ReflectionClass $originalClass) : array
136 {
137 return array_map(
138 function (ReflectionMethod $method) : ProxyManagerMethodGenerator {
139 $generated = ProxyManagerMethodGenerator::fromReflectionWithoutBodyAndDocBlock(
140 new MethodReflection($method->getDeclaringClass()->getName(), $method->getName())
141 );
142
143 $generated->setAbstract(false);
144
145 return $generated;
146 },
147 ProxiedMethodsFilter::getAbstractProxiedMethods($originalClass)
148 );
149 }
150 }
151