[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 * 15 * This software consists of voluntary contributions made by many individuals 16 * and is licensed under the MIT license. 17 */ 18 19 namespace ProxyManager\ProxyGenerator; 20 21 use ProxyManager\Generator\Util\ClassGeneratorUtils; 22 use ProxyManager\ProxyGenerator\AccessInterceptor\MethodGenerator\MagicWakeup; 23 use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; 24 use ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\Constructor; 25 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\GetProxyInitializer; 26 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\InitializeProxy; 27 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\IsProxyInitialized; 28 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\LazyLoadingMethodInterceptor; 29 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicClone; 30 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicGet; 31 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicIsset; 32 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSet; 33 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicSleep; 34 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\MagicUnset; 35 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator\SetProxyInitializer; 36 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\InitializerProperty; 37 use ProxyManager\ProxyGenerator\LazyLoadingValueHolder\PropertyGenerator\ValueHolderProperty; 38 use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap; 39 use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; 40 use ProxyManager\ProxyGenerator\ValueHolder\MethodGenerator\GetWrappedValueHolderValue; 41 use ReflectionClass; 42 use ReflectionMethod; 43 use Zend\Code\Generator\ClassGenerator; 44 use Zend\Code\Generator\MethodGenerator; 45 use Zend\Code\Reflection\MethodReflection; 46 47 /** 48 * Generator for proxies implementing {@see \ProxyManager\Proxy\VirtualProxyInterface} 49 * 50 * {@inheritDoc} 51 * 52 * @author Marco Pivetta <ocramius@gmail.com> 53 * @license MIT 54 */ 55 class LazyLoadingValueHolderGenerator implements ProxyGeneratorInterface 56 { 57 /** 58 * {@inheritDoc} 59 */ 60 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) 61 { 62 CanProxyAssertion::assertClassCanBeProxied($originalClass); 63 64 $interfaces = array('ProxyManager\\Proxy\\VirtualProxyInterface'); 65 $publicProperties = new PublicPropertiesMap($originalClass); 66 67 if ($originalClass->isInterface()) { 68 $interfaces[] = $originalClass->getName(); 69 } else { 70 $classGenerator->setExtendedClass($originalClass->getName()); 71 } 72 73 $classGenerator->setImplementedInterfaces($interfaces); 74 $classGenerator->addPropertyFromGenerator($valueHolder = new ValueHolderProperty()); 75 $classGenerator->addPropertyFromGenerator($initializer = new InitializerProperty()); 76 $classGenerator->addPropertyFromGenerator($publicProperties); 77 78 array_map( 79 function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) { 80 ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod); 81 }, 82 array_merge( 83 array_map( 84 function (ReflectionMethod $method) use ($initializer, $valueHolder) { 85 return LazyLoadingMethodInterceptor::generateMethod( 86 new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), 87 $initializer, 88 $valueHolder 89 ); 90 }, 91 ProxiedMethodsFilter::getProxiedMethods($originalClass) 92 ), 93 array( 94 new Constructor($originalClass, $initializer), 95 new MagicGet($originalClass, $initializer, $valueHolder, $publicProperties), 96 new MagicSet($originalClass, $initializer, $valueHolder, $publicProperties), 97 new MagicIsset($originalClass, $initializer, $valueHolder, $publicProperties), 98 new MagicUnset($originalClass, $initializer, $valueHolder, $publicProperties), 99 new MagicClone($originalClass, $initializer, $valueHolder), 100 new MagicSleep($originalClass, $initializer, $valueHolder), 101 new MagicWakeup($originalClass), 102 new SetProxyInitializer($initializer), 103 new GetProxyInitializer($initializer), 104 new InitializeProxy($initializer, $valueHolder), 105 new IsProxyInitialized($valueHolder), 106 new GetWrappedValueHolderValue($valueHolder), 107 ) 108 ) 109 ); 110 } 111 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |