[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare(strict_types=1); 4 5 namespace ProxyManager\ProxyGenerator; 6 7 use ProxyManager\Exception\InvalidProxiedClassException; 8 use ProxyManager\Generator\Util\ClassGeneratorUtils; 9 use ProxyManager\Proxy\RemoteObjectInterface; 10 use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; 11 use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicGet; 12 use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicIsset; 13 use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicSet; 14 use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\MagicUnset; 15 use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod; 16 use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\StaticProxyConstructor; 17 use ProxyManager\ProxyGenerator\RemoteObject\PropertyGenerator\AdapterProperty; 18 use ProxyManager\ProxyGenerator\Util\ProxiedMethodsFilter; 19 use ReflectionClass; 20 use ReflectionMethod; 21 use Zend\Code\Generator\ClassGenerator; 22 use Zend\Code\Generator\MethodGenerator; 23 use Zend\Code\Reflection\MethodReflection; 24 25 /** 26 * Generator for proxies implementing {@see \ProxyManager\Proxy\RemoteObjectInterface} 27 * 28 * {@inheritDoc} 29 * 30 * @author Vincent Blanchon <blanchon.vincent@gmail.com> 31 * @license MIT 32 */ 33 class RemoteObjectGenerator implements ProxyGeneratorInterface 34 { 35 /** 36 * {@inheritDoc} 37 * 38 * @throws InvalidProxiedClassException 39 * @throws \Zend\Code\Generator\Exception\InvalidArgumentException 40 */ 41 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator) 42 { 43 CanProxyAssertion::assertClassCanBeProxied($originalClass); 44 45 $interfaces = [RemoteObjectInterface::class]; 46 47 if ($originalClass->isInterface()) { 48 $interfaces[] = $originalClass->getName(); 49 } else { 50 $classGenerator->setExtendedClass($originalClass->getName()); 51 } 52 53 $classGenerator->setImplementedInterfaces($interfaces); 54 $classGenerator->addPropertyFromGenerator($adapter = new AdapterProperty()); 55 56 array_map( 57 function (MethodGenerator $generatedMethod) use ($originalClass, $classGenerator) { 58 ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, $generatedMethod); 59 }, 60 array_merge( 61 array_map( 62 function (ReflectionMethod $method) use ($adapter, $originalClass) : RemoteObjectMethod { 63 return RemoteObjectMethod::generateMethod( 64 new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()), 65 $adapter, 66 $originalClass 67 ); 68 }, 69 ProxiedMethodsFilter::getProxiedMethods( 70 $originalClass, 71 ['__get', '__set', '__isset', '__unset'] 72 ) 73 ), 74 [ 75 new StaticProxyConstructor($originalClass, $adapter), 76 new MagicGet($originalClass, $adapter), 77 new MagicSet($originalClass, $adapter), 78 new MagicIsset($originalClass, $adapter), 79 new MagicUnset($originalClass, $adapter), 80 ] 81 ) 82 ); 83 } 84 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |