Beispiel #1
0
 public static function reset()
 {
     static::$compile = array();
     static::$parse = array();
 }
Beispiel #2
0
 public static function run()
 {
     $compiler = new static();
     $compiler->compile();
 }
Beispiel #3
0
 /**
  * @param array $node
  * @return string
  * @throws Exception
  */
 protected function generatePartial(array $node) : string
 {
     $argumentList = $this->parseArguments($node['value']);
     $args = $argumentList->getArguments();
     $partialNameArg = array_shift($args);
     $partial = $this->runtime->getPartial($partialNameArg->getRawValue());
     if (is_null($partial) === true) {
         if ($partialNameArg instanceof StringArgument) {
             $partial = $partialNameArg->getRawValue();
         } else {
             // TODO: Add message
             throw new Exception();
         }
     }
     $compiler = new static($this->runtime, $this->tokenizerFactory, $this->argumentParserFactory);
     $code = $compiler->compile($partial, $this->offset + 3);
     // If there is at least one other argument, use it
     // as the scope for the partial.
     if (count($args)) {
         $scope = '\\r\\t\\1' . $args[0]->getValue() . ', ';
     } else {
         $scope = '';
     }
     $hash = array();
     foreach ($argumentList->getNamedArguments() as $key => $value) {
         $hash[$key] = sprintf('\'%s\' => %s', $key, $value->getValue());
     }
     if (empty($hash)) {
         $hash = '';
     } else {
         $hash = '\\r\\t\\1\\1\\1' . implode(', \\r\\t\\1\\1\\1', $hash) . '\\r\\t\\1\\1';
     }
     $layout = str_replace(array('\\r', '\\t', '\\1'), array("\n", str_repeat('    ', $this->offset), str_repeat('    ', 1)), '\\r\\t$buffer .= $this->runtime->getHelper(\'noop\')(' . $scope . '\\r\\t\\1array(' . '\\r\\t\\1\\1\'name\' => \'noop\',' . '\\r\\t\\1\\1\'hash\' => array(' . $hash . '),' . '\\r\\t\\1\\1\'fn\' => function($context = null) use ($data) {' . '\\r\\t\\1\\1\\1if (is_array($context)) {' . '\\r\\t\\1\\1\\1\\1$data->push($context);' . '\\r\\t\\1\\1\\1}' . '\\r\\r\\t\\1\\1\\1$buffer = \'\';' . '%s' . '\\r\\t\\1\\1\\1if (is_array($context)) {' . '\\r\\t\\1\\1\\1\\1$data->pop();' . '\\r\\t\\1\\1\\1}' . '\\r\\r\\t\\1\\1\\1return $buffer;' . '\\r\\t\\1\\1},' . '\\r\\t\\1\\1\'inverse\' => function() {},' . '\\r\\t\\1)' . '\\r\\t);\\r');
     return sprintf($layout, $code);
 }