@@ -77,6 +77,12 @@ public function offsetExists($offset)
77
77
// We only check isset on the array, if it is an object we return true as the object could be overloaded
78
78
if (is_array ($ this ->object ))
79
79
{
80
+ if ($ method = $ this ->getPresentMethodForVariable ($ offset ))
81
+ {
82
+ $ result = $ this ->$ method ();
83
+ return isset ($ result );
84
+ }
85
+
80
86
return isset ($ this ->object [$ offset ]);
81
87
}
82
88
@@ -137,8 +143,7 @@ public function offsetUnset($offset)
137
143
*/
138
144
public function __get ($ var )
139
145
{
140
- $ method = 'present ' .str_replace (' ' , '' , ucwords (str_replace (array ('- ' , '_ ' ), ' ' , $ var )));
141
- if (method_exists ($ this , $ method ))
146
+ if ($ method = $ this ->getPresentMethodForVariable ($ var ))
142
147
{
143
148
return $ this ->$ method ();
144
149
}
@@ -173,6 +178,12 @@ public function __call($method, $arguments)
173
178
*/
174
179
public function __isset ($ name )
175
180
{
181
+ if ($ method = $ this ->getPresentMethodForVariable ($ name ))
182
+ {
183
+ $ result = $ this ->$ method ();
184
+ return isset ($ result );
185
+ }
186
+
176
187
if (is_array ($ this ->object ))
177
188
{
178
189
return isset ($ this ->object [$ name ]);
@@ -197,4 +208,21 @@ public function __unset($name)
197
208
unset($ this ->object ->$ name );
198
209
}
199
210
211
+ /**
212
+ * Fetch the 'present' method name for the given variable.
213
+ *
214
+ * @param string $var Variable name
215
+ * @return string|null Present method name, or null if method does not exist
216
+ */
217
+ private function getPresentMethodForVariable ($ var )
218
+ {
219
+ $ method = 'present ' .str_replace (' ' , '' , ucwords (str_replace (array ('- ' , '_ ' ), ' ' , $ var )));
220
+
221
+ if (method_exists ($ this , $ method )) {
222
+ return $ method ;
223
+ } else {
224
+ return null ;
225
+ }
226
+ }
227
+
200
228
}
0 commit comments