| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Go! AOP framework | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @copyright Copyright 2013, Lisachenko Alexander <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * This source file is subject to the license that is bundled | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * with this source code in the file LICENSE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | namespace Go\Aop\Pointcut; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Go\Aop\Pointcut; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Go\Aop\PointFilter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Go\Aop\Support\OrPointFilter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use ReflectionClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use ReflectionMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use ReflectionProperty; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * Logical "OR" pointcut that combines two simple pointcuts | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | class OrPointcut extends AndPointcut | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 27 | 3 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      * "Or" pointcut constructor | 
            
                                                                        
                            
            
                                    
            
            
                | 29 | 3 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 3 |  |     public function __construct(Pointcut $first, Pointcut $second) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 3 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->first  = $first; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 3 |  |         $this->second = $second; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 3 |  |         $this->kind   = $first->getKind() | $second->getKind(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->classFilter = new OrPointFilter($first->getClassFilter(), $second->getClassFilter()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      * Performs matching of point of code | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * @param mixed              $point     Specific part of code, can be any Reflection class | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * @param null|mixed         $context   Related context, can be class or namespace | 
            
                                                                        
                            
            
                                    
            
            
                | 44 | 1 |  |      * @param null|string|object $instance  Invocation instance or string for static calls | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      * @param null|array         $arguments Dynamic arguments for method | 
            
                                                                        
                            
            
                                    
            
            
                | 46 | 1 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 1 |  |     public function matches($point, $context = null, $instance = null, array $arguments = null): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         return $this->matchPart($this->first, $point, $context, $instance, $arguments) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             || $this->matchPart($this->second, $point, $context, $instance, $arguments); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 | 1 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      * @inheritDoc | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     protected function matchPart( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         Pointcut $pointcut, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $point, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $context = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 1 |  |         $instance = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         array $arguments = null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  |     ): bool { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 1 |  |         $pointcutKind = $pointcut->getKind(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         // We need to recheck filter kind one more time, because of OR syntax | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         switch (true) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 1 |  |             case ($point instanceof ReflectionMethod && ($pointcutKind & PointFilter::KIND_METHOD)): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             case ($point instanceof ReflectionProperty && ($pointcutKind & PointFilter::KIND_PROPERTY)): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             case ($point instanceof ReflectionClass && ($pointcutKind & PointFilter::KIND_CLASS)): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 return parent::matchPart($pointcut, $point, $context, $instance, $arguments); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                 return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 75 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |  |