commit c1324d93b003aa5e5ad96cff3ac16aebba1225a6
parent d95206a6ee66de78f3db256005d1a90e067ab452
Author: finwo <finwo@pm.me>
Date: Thu, 12 May 2016 13:49:48 +0200
Bugfix
Diffstat:
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/PropertyAccessor.php b/src/PropertyAccessor.php
@@ -21,12 +21,22 @@ class PropertyAccessor
* @return array|mixed|null
* @throws \Exception
*/
- public function getSafe(&$subject, $path = '', $pathSplit = '|', $default = null, $options = array())
+ public function getSafe(&$subject, $path = '', $pathSplit = '|', &$default = null, $options = array())
{
+ // Fetch
$result = $this->get($subject, $path, $pathSplit);
- if ( !in_array($result, $options) || is_null($result) ) {
+
+ // Filter down to options
+ if (!is_null($options) && count($options) && !in_array($result, $options)) {
$result = &$default;
}
+
+ // Make sure there is a value
+ if (is_null($result)) {
+ $result = &$default;
+ }
+
+ // And return offcourse
return $result;
}