| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace nstdio\svg\gradient; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Class Direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @package nstdio\svg\gradient | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @author  Edgar Asatryan <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | abstract class Direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     private static $attrs = ['x1', 'y1', 'x2', 'y2']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     private static $radialAttrs = ['fx', 'fy', 'r']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $topLeftBottomRight = [0, 0, 100, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $bottomRightTopLeft = [100, 100, 0, 0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $topBottom = [0, 0, 0, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $bottomTop = [0, 100, 0, 0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $leftRight = [0, 50, 100, 50]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $rightLeft = [100, 50, 0, 50]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $bottomLeftTopRight = [0, 100, 100, 0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $topRightBottomLeft = [100, 0, 0, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $radialTopLeft = [0, 0, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $radialTopRight = [100, 0, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $radialBottomRight = [100, 100, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $radialBottomLeft = [0, 100, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $radialTopCenter = [50, 0, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $radialLeftCenter = [0, 50, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $radialBottomCenter = [50, 100, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     private static /** @noinspection PhpUnusedPrivateFieldInspection */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $radialRightCenter = [100, 50, 100]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 33 |  |     public static function get($staticProp) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 33 |  |         if (isset(self::${$staticProp})) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 33 |  |             $isRadial = strpos($staticProp, 'radial') === 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 33 |  |             return self::buildDirection(self::${$staticProp}, $isRadial); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  |         return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 74 | 33 |  |     private static function buildDirection(array $property, $radial = false) | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 76 | 33 |  |         $direction = []; | 
            
                                                        
            
                                    
            
            
                | 77 | 33 |  |         $attributes = $radial ? self::$radialAttrs : self::$attrs; | 
            
                                                        
            
                                    
            
            
                | 78 | 33 |  |         foreach ($attributes as $key => $attr) { | 
            
                                                        
            
                                    
            
            
                | 79 | 33 |  |             $direction[$attr] = $property[$key] . '%'; | 
            
                                                        
            
                                    
            
            
                | 80 | 33 |  |         } | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 82 | 33 |  |         return $direction; | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 84 |  |  | } |