| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is a part of "Axessors" library. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @license GPL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace NoOne4rever\Axessors; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Class RunningSuit. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * Stores running configuration. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @package NoOne4rever\Axessors | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | abstract class RunningSuit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public const INPUT_MODE = 4; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public const OUTPUT_MODE = 8; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** @var object|null object */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     protected $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** @var PropertyData property data */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     protected $propertyData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** @var string class */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     protected $class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** @var int running mode */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     protected $mode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * RunningSuit constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param int $mode running mode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @param PropertyData $data property data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @param string $class class name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @param object|null $object object with called method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 92 |  |     public function __construct(int $mode, PropertyData $data, string $class, $object = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 92 |  |         $this->mode = $mode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 92 |  |         $this->propertyData = $data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 92 |  |         $this->class = $class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 92 |  |         $this->object = $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 92 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * Runs *injected* callback or condition. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @param string $expr *injected* string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @param mixed $var variable to process  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @param bool $mode mode of execution | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @return mixed the result of *injected* string execution | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 9 |  |     protected function executeInjectedString(string $expr, $var, bool $mode) | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 | 9 |  |         $handler = str_replace('\\`', '`', substr($expr, 1, strlen($expr) - 2)); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 | 9 |  |         if (is_null($this->object)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |             return call_user_func("{$this->class}::__axessorsExecuteStatic", $handler, $var, $mode); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 62 | 9 |  |             return $this->object->__axessorsExecute($handler, $var, $mode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } |