Beispiel #1
0
 public function execute(Runtime $vm)
 {
     foreach (array('source', 'key', 'value', 'body') as $var) {
         ${$var} = $this->{$var};
     }
     if ($source instanceof Variable) {
         /* it's a json definition */
         $val = $vm->get($source);
         if (is_null($val)) {
             throw new \RuntimeException("Cannot find variable " . $source);
         }
         $source = $vm->getValue($val);
     } else {
         $source = $vm->getValue($source);
     }
     foreach ($source as $zkey => $zvalue) {
         if ($key) {
             $vm->define($key, new Term($zkey));
         }
         $vm->define($value, $zvalue);
         foreach ($body as $stmt) {
             $vm->execute($stmt);
             if ($vm->isSuspended()) {
                 $vm->isSuspended(false);
                 break;
             }
             if ($vm->isStopped()) {
                 break 2;
             }
         }
     }
 }
Beispiel #2
0
 public function execute(Runtime $vm)
 {
     $text = preg_replace_callback("/__(@?[a-z][a-z0-9_]*?)__/i", function ($var) use($vm) {
         if ($var[1][0] == '@') {
             $var[1] = substr($var[1], 1);
             $varValue = true;
         }
         $value = $vm->get($var[1]);
         if (is_null($value)) {
             /* variable is not found, we ignore it */
             return $var[0];
         }
         $result = $vm->getValue($value);
         if (!empty($varValue)) {
             $result = var_export($result, true);
         }
         if (is_object($result) && is_callable(array($result, '__toString'))) {
             $result = (string) $result;
         }
         if (!is_scalar($result)) {
             throw new \RuntimeException("Only scalar values may be replaced. Use @ to get the string representation.");
         }
         return $result;
     }, $this->args);
     if ($this->isString()) {
         return $vm->printIndented($text, $this);
     }
     return $vm->doPrint($text);
 }
Beispiel #3
0
 public function getValue(Runtime $vm)
 {
     return $vm->get($this);
 }