[ 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 `__set` for lazy loading value holder objects 16 * 17 * @author Marco Pivetta <ocramius@gmail.com> 18 * @license MIT 19 */ 20 class MagicSet 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( 40 $originalClass, 41 '__set', 42 [new ParameterGenerator('name'), new ParameterGenerator('value')] 43 ); 44 45 $hasParent = $originalClass->hasMethod('__set'); 46 $initializer = $initializerProperty->getName(); 47 $valueHolder = $valueHolderProperty->getName(); 48 $callParent = ''; 49 50 if (! $publicProperties->isEmpty()) { 51 $callParent = 'if (isset(self::$' . $publicProperties->getName() . "[\$name])) {\n" 52 . ' return ($this->' . $valueHolder . '->$name = $value);' 53 . "\n}\n\n"; 54 } 55 56 $callParent .= $hasParent 57 ? 'return $this->' . $valueHolder . '->__set($name, $value);' 58 : PublicScopeSimulator::getPublicAccessSimulationCode( 59 PublicScopeSimulator::OPERATION_SET, 60 'name', 61 'value', 62 $valueHolderProperty 63 ); 64 65 $this->setBody( 66 '$this->' . $initializer . ' && $this->' . $initializer 67 . '->__invoke($this->' . $valueHolder . ', $this, ' 68 . '\'__set\', array(\'name\' => $name, \'value\' => $value), $this->' . $initializer . ');' 69 . "\n\n" . $callParent 70 ); 71 } 72 }
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 |