| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Neta\Shopware\SDK\Entity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Support\Arr; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Support\Str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Class Base. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @author    Alexander Mahrt <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @copyright 2016 LeadCommerce <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class Base | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * @var int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     protected $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     protected $attributesRaw = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 11 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 11 |  |      * Sets the attributes of this entity. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 11 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 11 |  |      * @param array $attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 11 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public function setEntityAttributes(array $attributes) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 11 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->attributesRaw = $attributes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         foreach ($attributes as $attribute => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             $setter = 'set' . ucfirst($attribute); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             if (method_exists($this, $setter)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                 $this->$setter($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 4 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 4 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 4 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 4 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  |      * Gets the attributes of this entity. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 4 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 4 |  |     public function getArrayCopy() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $array = get_object_vars($this); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         unset($array['attributesRaw']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         foreach ($array as $key => &$value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 4 |  |             if ($value instanceof Base) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 4 |  |                 $array[$key] = $value->getArrayCopy(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             } elseif (is_array($value)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 4 |  |                 foreach ($value as $k => $v) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                     if ($v instanceof Base) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                         $value[$k] = $v->getArrayCopy(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $array = array_filter($array, function ($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             return $value !== null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         return $array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 9 |  |      * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 9 |  |     public function getId() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 9 |  |         return $this->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @param int $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @return Base | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     public function setId($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $this->id = $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @return mixed | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 101 |  |  |     public function get(string $key) | 
            
                                                        
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 103 |  |  |         $method = 'get' . Str::camel(ucfirst($key)); | 
            
                                                        
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 105 |  |  |         if (method_exists($this, $method)) { | 
            
                                                        
            
                                    
            
            
                | 106 |  |  |             return $this->$method(); | 
            
                                                        
            
                                    
            
            
                | 107 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |         return Arr::get($this->attributesRaw, $key, null); | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 111 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |  |