/** * The functions that fixes and returns a value. * * Be warned: this function may return a lazy value. * * @param \MUtil_Lazy_StackInterface $stack A \MUtil_Lazy_StackInterface object providing variable data * @return mixed */ public function __toValue(\MUtil_Lazy_StackInterface $stack) { $params = $this->_params; if (is_array($this->_callable)) { list($object, $method) = $this->_callable; while ($object instanceof \MUtil_Lazy_LazyInterface) { $object = $object->__toValue($stack); } $callable = array($object, $method); if (!(is_object($object) && (method_exists($object, $method) || method_exists($object, '__call')))) { if (function_exists($method)) { // Add the object as the first parameter array_unshift($params, $object); $callable = $method; } elseif ('if' === strtolower($method)) { if ($object) { return isset($params[0]) ? $params[0] : null; } else { return isset($params[1]) ? $params[1] : null; } } } } else { $method = $this->_callable; // For error message $callable = $this->_callable; } if (is_callable($callable)) { $params = \MUtil_Lazy::riseRa($params, $stack); /* if ('_' == $method) { \MUtil_Echo::r($params); } */ return call_user_func_array($callable, $params); } throw new \MUtil_Lazy_LazyException('Lazy execution exception! "' . $method . '" is not a valid callable.'); }
/** * The functions that fixes and returns a value. * * Be warned: this function may return a lazy value. * * @param \MUtil_Lazy_StackInterface $stack A \MUtil_Lazy_StackInterface object providing variable data * @return mixed */ public function __toValue(\MUtil_Lazy_StackInterface $stack) { $array = $this->_array; $offset = $this->_offset; while ($offset instanceof \MUtil_Lazy_LazyInterface) { $offset = $offset->__toValue($stack); } while ($array instanceof \MUtil_Lazy_LazyInterface) { $array = $array->__toValue($stack); } if (\MUtil_Lazy::$verbose) { \MUtil_Echo::header('Lazy offset get for offset: <em>' . $offset . '</em>'); \MUtil_Echo::classToName($array); } if (null === $offset) { if (isset($array[''])) { $value = $array['']; } else { $value = null; } } elseif (is_array($offset)) { // When the offset is itself an array, return an // array of values applied to this offset. $value = array(); foreach (\MUtil_Lazy::riseRa($offset, $stack) as $key => $val) { if (isset($array[$val])) { $value[$key] = $val; } } } elseif (isset($array[$offset])) { $value = $array[$offset]; } else { $value = null; } while ($value instanceof \MUtil_Lazy_LazyInterface) { $value = $value->__toValue($stack); } if (is_array($value)) { $value = \MUtil_Lazy::riseRa($value, $stack); } return $value; }