public function compile(Compiler $compiler) { $args = $this->getNode(self::NODE_ARGS)->getNodes(); $macroName = $this->getAttribute(self::ATTR_NAME); $compiler->writeln('// Line ' . $this->getLineNo())->write('public function macro_' . $macroName)->scopeIn(Compiler::SCOPE_MACRO, $macroName)->raw('( $context = [] , $arguments = [] ) {')->line()->indent()->writeln('$args = [')->indent(); foreach ($args as $name => $value) { $compiler->write('')->string($name)->raw(' => '); if ($value) { $compiler->subcompile($value); } else { $compiler->raw('null'); } $compiler->raw(',')->line(); } $compiler->outdent()->writeln('];')->writeln('$context = array_merge( $context , $this->prepareArgs( $args , $arguments ) );')->subcompile($this->getNode(self::NODE_BODY))->scopeOut()->outdent()->writeln('}'); }
private function compileArguments(Compiler $compiler) { $compiler->raw('['); $first = true; foreach ($this->nodes as $name => $node) { if (!$first) { $compiler->raw(','); } if (is_string($name)) { $compiler->string($name)->raw(' => '); } $node->compile($compiler); $first = false; } $compiler->raw(']'); }
public function compile(Compiler $compiler) { $compiler->raw('$this->filter(')->string($this->getAttribute(self::ATTR_NAME))->raw(', '); $this->getArguments()->compile($compiler); $compiler->raw(', function() use ( $context ){ return '); $this->getNode(self::NODE_CONTENT)->compile($compiler); $compiler->raw(' ;}'); $compiler->raw(')'); }
public function compile(Compiler $compiler) { /** @var Node[] $tests */ $tests = $this->getNode(self::NODE_TESTS); for ($i = 0; $i < count($tests); $i += 2) { $test = $tests[$i]; $true = $tests[$i + 1]; if ($i == 0) { $compiler->write('if ( '); } else { $compiler->raw(' elseif ( '); } $compiler->subcompile($test)->raw(' ) { ' . "\n")->indent()->subcompile($true)->outdent()->write('}'); } if ($this->hasNode(self::NODE_ELSE)) { $compiler->raw(' else { ' . "\n")->indent()->subcompile($this->getNode(self::NODE_ELSE))->outdent()->write('}'); } $compiler->line(); }
public function compile(Compiler $compiler) { $compiler->raw('array('); $elements = $this->getNode(self::NODE_ELEMENTS); $first = true; foreach ($elements as $element) { if (!$first) { $compiler->raw(','); } list($key, $value) = $element; if ($key) { if ($key instanceof Constant) { $compiler->subcompile($key); } elseif ($key instanceof Name) { $compiler->string($key->getName()); } $compiler->raw(' => '); } $compiler->subcompile($value); $first = false; } $compiler->raw(')'); }
public function compile(Compiler $compiler) { $compiler->raw('range(')->subcompile($this->getNode(self::NODE_1))->raw(', ')->subcompile($this->getNode(self::NODE_2))->raw(')'); }
public function compile(Compiler $compiler) { $name = $this->getAttribute(self::ATTR_NAME); $route = $this->convertToRoute($name); $compiler->raw('$this->getValue( $context , ["' . implode('","', $route) . '"] )'); }
public function compile(Compiler $compiler) { $compiler->raw($this->getAttribute('constant')); }
public function compile(Compiler $compiler) { $compiler->raw(sprintf('$this->renderBlock("%s", ', $this->getAttribute(self::ATTR_NAME)))->raw('array_merge( $context , ')->subcompile($this->getNode(self::NODE_CONTEXT))->raw('))'); }