[ 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\Factory; 6 7 use Closure; 8 use ProxyManager\Proxy\GhostObjectInterface; 9 use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator; 10 use ProxyManager\ProxyGenerator\ProxyGeneratorInterface; 11 use ProxyManager\Signature\Exception\InvalidSignatureException; 12 use ProxyManager\Signature\Exception\MissingSignatureException; 13 14 /** 15 * Factory responsible of producing ghost instances 16 * 17 * @author Marco Pivetta <ocramius@gmail.com> 18 * @license MIT 19 */ 20 class LazyLoadingGhostFactory extends AbstractBaseFactory 21 { 22 /** 23 * @var \ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator|null 24 */ 25 private $generator; 26 27 /** 28 * {@inheritDoc} 29 */ 30 protected function getGenerator() : ProxyGeneratorInterface 31 { 32 return $this->generator ?: $this->generator = new LazyLoadingGhostGenerator(); 33 } 34 35 /** 36 * Creates a new lazy proxy instance of the given class with 37 * the given initializer 38 * 39 * Please refer to the following documentation when using this method: 40 * 41 * @link https://github.com/Ocramius/ProxyManager/blob/master/docs/lazy-loading-ghost-object.md 42 * 43 * @param string $className name of the class to be proxied 44 * @param Closure $initializer initializer to be passed to the proxy. The initializer closure should have following 45 * signature: 46 * 47 * <code> 48 * $initializer = function ( 49 * GhostObjectInterface $proxy, 50 * string $method, 51 * array $parameters, 52 * & $initializer, 53 * array $properties 54 * ) {}; 55 * </code> 56 * 57 * Where: 58 * - $proxy is the proxy instance on which the initializer is acting 59 * - $method is the name of the method that triggered the lazy initialization 60 * - $parameters are the parameters that were passed to $method 61 * - $initializer by-ref initializer - should be assigned null in the initializer body 62 * - $properties a by-ref map of the properties of the object, indexed by PHP 63 * internal property name. Assign values to it to initialize the 64 * object state 65 * 66 * @param mixed[] $proxyOptions a set of options to be used when generating the proxy. Currently supports only 67 * key "skippedProperties", which allows to skip lazy-loading of some properties. 68 * "skippedProperties" is a string[], containing a list of properties referenced 69 * via PHP's internal property name (i.e. "\0ClassName\0propertyName") 70 * 71 * @throws MissingSignatureException 72 * @throws InvalidSignatureException 73 * @throws \OutOfBoundsException 74 */ 75 public function createProxy( 76 string $className, 77 Closure $initializer, 78 array $proxyOptions = [] 79 ) : GhostObjectInterface { 80 $proxyClassName = $this->generateProxy($className, $proxyOptions); 81 82 return $proxyClassName::staticProxyConstructor($initializer); 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 |