| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Go! AOP framework | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @copyright Copyright 2016, Lisachenko Alexander <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * This source file is subject to the license that is bundled | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * with this source code in the file LICENSE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace Go\Proxy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Go\Aop\Framework\ClassFieldAccess; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * Trait that holds all general logic for working with intercepted properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | trait PropertyInterceptionTrait | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * Holds a collection of current values for intercepted properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private $__properties = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function &__get($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         if (\array_key_exists($name, $this->__properties)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             /** @var ClassFieldAccess $fieldAccess */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             $fieldAccess = self::$__joinPoints["prop:$name"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             $fieldAccess->ensureScopeRule(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             $value = &$fieldAccess->__invoke($this, ClassFieldAccess::READ, $this->__properties[$name]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         } elseif (\method_exists(\get_parent_class(), __FUNCTION__)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             $value = parent::__get($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             trigger_error("Trying to access undeclared property {$name}"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             $value = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         return $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function __set($name, $value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         if (\array_key_exists($name, $this->__properties)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             /** @var ClassFieldAccess $fieldAccess */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $fieldAccess = self::$__joinPoints["prop:$name"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             $fieldAccess->ensureScopeRule(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             $this->__properties[$name] = $fieldAccess->__invoke( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 $this, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                 ClassFieldAccess::WRITE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 $this->__properties[$name], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         } elseif (\method_exists(\get_parent_class(), __FUNCTION__)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             parent::__set($name, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             $this->$name = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @inheritDoc | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |     public function __isset($name) | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |         return isset($this->__properties[$name]); | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     public function __unset($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $this->__properties[$name] = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 87 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |  |