| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Doctrine\Common\Reflection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Doctrine\Common\Proxy\Proxy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use ReflectionProperty; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * PHP Runtime Reflection Public Property - special overrides for public properties. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class RuntimePublicReflectionProperty extends ReflectionProperty | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * Checks is the value actually exist before fetching it. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * This is to avoid calling `__get` on the provided $object if it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * is a {@see \Doctrine\Common\Proxy\Proxy}. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     public function getValue($object = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         $name = $this->getName(); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         if ($object instanceof Proxy && ! $object->__isInitialized()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |             $originalInitializer = $object->__getInitializer(); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             $object->__setInitializer(null); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |             $val = $object->$name ?? null; | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |             $object->__setInitializer($originalInitializer); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |             return $val; | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         return isset($object->$name) ? parent::getValue($object) : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * Avoids triggering lazy loading via `__set` if the provided object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * is a {@see \Doctrine\Common\Proxy\Proxy}. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @link https://bugs.php.net/bug.php?id=63463 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function setValue($object, $value = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         if (! ($object instanceof Proxy && ! $object->__isInitialized())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             parent::setValue($object, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $originalInitializer = $object->__getInitializer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $object->__setInitializer(null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         parent::setValue($object, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $object->__setInitializer($originalInitializer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  |