[ 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\LazyLoadingValueHolder\MethodGenerator; 6 7 use ProxyManager\Generator\MagicMethodGenerator; 8 use Zend\Code\Generator\ParameterGenerator; 9 use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap; 10 use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator; 11 use ReflectionClass; 12 use Zend\Code\Generator\PropertyGenerator; 13 14 /** 15 * Magic `__get` for lazy loading value holder objects 16 * 17 * @author Marco Pivetta <ocramius@gmail.com> 18 * @license MIT 19 */ 20 class MagicGet extends MagicMethodGenerator 21 { 22 /** 23 * Constructor 24 * 25 * @param ReflectionClass $originalClass 26 * @param PropertyGenerator $initializerProperty 27 * @param PropertyGenerator $valueHolderProperty 28 * @param PublicPropertiesMap $publicProperties 29 * 30 * @throws \Zend\Code\Generator\Exception\InvalidArgumentException 31 * @throws \InvalidArgumentException 32 */ 33 public function __construct( 34 ReflectionClass $originalClass, 35 PropertyGenerator $initializerProperty, 36 PropertyGenerator $valueHolderProperty, 37 PublicPropertiesMap $publicProperties 38 ) { 39 parent::__construct($originalClass, '__get', [new ParameterGenerator('name')]); 40 41 $hasParent = $originalClass->hasMethod('__get'); 42 43 $initializer = $initializerProperty->getName(); 44 $valueHolder = $valueHolderProperty->getName(); 45 $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" 46 . ' return $this->' . $valueHolder . '->$name;' 47 . "\n}\n\n"; 48 49 if ($hasParent) { 50 $this->setInitializerBody( 51 $initializer, 52 $valueHolder, 53 $callParent . 'return $this->' . $valueHolder . '->__get($name);' 54 ); 55 56 return; 57 } 58 59 $this->setInitializerBody( 60 $initializer, 61 $valueHolder, 62 $callParent . PublicScopeSimulator::getPublicAccessSimulationCode( 63 PublicScopeSimulator::OPERATION_GET, 64 'name', 65 null, 66 $valueHolderProperty 67 ) 68 ); 69 } 70 71 private function setInitializerBody(string $initializer, string $valueHolder, string $callParent) : void 72 { 73 $this->setBody( 74 '$this->' . $initializer . ' && $this->' . $initializer 75 . '->__invoke($this->' . $valueHolder . ', $this, \'__get\', [\'name\' => $name], $this->' 76 . $initializer . ');' 77 . "\n\n" . $callParent 78 ); 79 } 80 }
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 |