|
12 | 12 |
|
13 | 13 | trait MagicMethodsTrait |
14 | 14 | { |
15 | | - public function __call($name, $arguments) |
16 | | - { |
17 | | - $callTypeIndex = 3; |
18 | | - if (substr($name, 0, 2) == "is") { |
19 | | - $callTypeIndex = 2; |
20 | | - } |
21 | | - |
22 | | - $callType = substr($name, 0, $callTypeIndex); |
23 | | - $propertyName = substr($name, $callTypeIndex); |
24 | | - |
25 | | - if (in_array($callType, array('get', 'is')) && count($arguments) == 0) { |
26 | | - return $this->{$callType}($propertyName); |
27 | | - } |
28 | | - |
29 | | - if (in_array($callType, array('add', 'set')) && count($arguments) == 1) { |
30 | | - return $this->{$callType}($propertyName, $arguments[0]); |
31 | | - } |
32 | | - |
33 | | - throw new \Exception("The method you tried to call doesn't exist"); |
34 | | - } |
35 | | - |
36 | 15 | public function __set($name, $value) |
37 | 16 | { |
38 | 17 | if (is_object($value) && !($value instanceof Type) && property_exists($value, "Entry")) { |
@@ -60,75 +39,4 @@ public function methodExists($name) |
60 | 39 | { |
61 | 40 | return method_exists($this, $name); |
62 | 41 | } |
63 | | - |
64 | | - public function get($name) |
65 | | - { |
66 | | - $name = $this->getValidNameInCorrectCase([$name, "get$name"]); |
67 | | - return $this->$name; |
68 | | - } |
69 | | - |
70 | | - public function set($name, $value) |
71 | | - { |
72 | | - $name = $this->getNameInCorrectCase($name); |
73 | | - |
74 | | - $this->$name = $value; |
75 | | - |
76 | | - return $this; |
77 | | - } |
78 | | - |
79 | | - public function add($name, $value) |
80 | | - { |
81 | | - $name = $this->getNameInCorrectCase($name); |
82 | | - |
83 | | - if ($this->$name == null) { |
84 | | - $this->$name = array(); |
85 | | - } |
86 | | - |
87 | | - if (!is_array($this->$name)) { |
88 | | - $this->$name = array($this->$name); |
89 | | - } |
90 | | - |
91 | | - $this->{$name}[] = $value; |
92 | | - |
93 | | - return $this; |
94 | | - } |
95 | | - |
96 | | - public function is($name) |
97 | | - { |
98 | | - $nameWithIs = "Is$name"; |
99 | | - $name = $this->getValidNameInCorrectCase([$nameWithIs, $name]); |
100 | | - |
101 | | - return ((bool) $this->$name); |
102 | | - } |
103 | | - |
104 | | - protected function getValidNameInCorrectCase($names) |
105 | | - { |
106 | | - foreach ($names as $name) { |
107 | | - try { |
108 | | - return $this->getNameInCorrectCase($name); |
109 | | - } catch (\Exception $e) { |
110 | | - //Nothing needed here. If everything errors out, we'll throw a new exception below |
111 | | - } |
112 | | - } |
113 | | - |
114 | | - throw new \Exception('Property ' . $names[0] . ' does not exist'); |
115 | | - } |
116 | | - |
117 | | - /** |
118 | | - * @param $name |
119 | | - * @return string |
120 | | - * @throws \Exception |
121 | | - */ |
122 | | - protected function getNameInCorrectCase($name) |
123 | | - { |
124 | | - if (!$this->exists($name) && $this->exists(lcfirst($name))) { |
125 | | - $name = lcfirst($name); |
126 | | - } |
127 | | - |
128 | | - if (!$this->exists($name)) { |
129 | | - throw new \Exception('Property ' . $name . ' does not exist'); |
130 | | - } |
131 | | - |
132 | | - return $name; |
133 | | - } |
134 | 42 | } |
0 commit comments