| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace W2w\Lib\Apie\Plugins\Core\PropertyInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use ReflectionMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor as SymfonyReflectionExtractor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class ReflectionExtractor extends SymfonyReflectionExtractor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     private $accessFlags; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public function __construct(array $mutatorPrefixes = null, array $accessorPrefixes = null, array $arrayMutatorPrefixes = null, bool $enableConstructorExtraction = true, int $accessFlags = self::ALLOW_PUBLIC) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         $this->accessFlags = $accessFlags; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         parent::__construct($mutatorPrefixes, $accessorPrefixes, $arrayMutatorPrefixes, $enableConstructorExtraction, $accessFlags); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public function isReadable($class, $property, array $context = []): ?bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         if ($this->isAllowedProperty($class, $property)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         list($reflectionMethod) = $this->getAccessorMethod($class, $property); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         return null !== $reflectionMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     public function isWritable($class, $property, array $context = []): ?bool | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         if ($this->isAllowedProperty($class, $property)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |             return true; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         list($reflectionMethod) = $this->getMutatorMethod($class, $property); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         return null !== $reflectionMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     private function isAllowedProperty(string $class, string $property): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $refl = new ReflectionMethod(SymfonyReflectionExtractor::class, 'isAllowedProperty'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $refl->setAccessible(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         return $refl->invoke($this, $class, $property); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     private function getAccessorMethod(string $class, string $property): ?array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $refl = new ReflectionMethod(SymfonyReflectionExtractor::class, 'getAccessorMethod'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $refl->setAccessible(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $result = $refl->invoke($this, $class, $property); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         return $this->filterMethodOnAccessFlag($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     private function getMutatorMethod(string $class, string $property): ?array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $refl = new ReflectionMethod(SymfonyReflectionExtractor::class, 'getMutatorMethod'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $refl->setAccessible(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $result = $refl->invoke($this, $class, $property); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         return $this->filterMethodOnAccessFlag($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     private function filterMethodOnAccessFlag(?array $result): ?array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         if (null === $result) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         /** @var ReflectionMethod $method */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $method = $result[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         if ($this->accessFlags & self::ALLOW_PUBLIC && $method->isPublic()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         if ($this->accessFlags & self::ALLOW_PROTECTED && $method->isProtected()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         if ($this->accessFlags & self::ALLOW_PRIVATE && $method->isPrivate()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 90 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |  |