Exemple #1
0
 /**
  * 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;
 }