Example #1
0
 public function fetch($name, $evalDirectly = false, $default = '__raise')
 {
     /* new syntax for iteration */
     if ($name === ".") {
         return $this->stack[0];
     }
     /* explode the dot notation */
     $list = explode(".", $name);
     $res = null;
     $found = false;
     if (isset($this->memoizer[$name])) {
         $res = $this->memoizer[$name];
         $found = true;
     } else {
         foreach ($this->stack as $a) {
             $res = null;
             $found = false;
             foreach ($list as $part) {
                 if ($part === "") {
                     /* XXX syntax error */
                     return null;
                 }
                 $res = $this->__fetch($a, $part, $found);
                 if (!$found) {
                     continue 2;
                 }
                 $a = $res;
             }
             if ($found) {
                 $this->memoizer[$name] = $res;
                 break;
             }
         }
     }
     if ($found) {
         /* evaluate the lambda directly if it is a tag. */
         if (is_callable($res) && $evalDirectly) {
             // temporarily reset to default delimiters for immediate lambda return
             $ctag = $this->ctag;
             $otag = $this->otag;
             $this->ctag = $this->otag = null;
             Context::PushContext($this);
             $str = $this->render($res());
             Context::PopContext();
             $this->ctag = $ctag;
             $this->otag = $otag;
             return $str;
         } else {
             return $res;
         }
     }
     /* raise an exception only if requested. */
     if ($default == '__raise' || $this->proust && $this->proust->raiseOnContextMiss) {
         throw new ContextMissException("Can't find {$name}");
     } else {
         return $default;
     }
 }