public function compile(Apishka_Templater_Compiler $compiler) { $compiler->subcompile($this->getNode('node'))->raw('->')->raw($this->getAttribute('method'))->raw('('); $first = true; foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) { if (!$first) { $compiler->raw(', '); } $first = false; $compiler->subcompile($pair['value']); } $compiler->raw(')'); }
public function compile(Apishka_Templater_Compiler $compiler) { $compiler->raw('(')->subcompile($this->getNode('node'))->raw(' === constant('); if ($this->getNode('arguments')->hasNode(1)) { $compiler->raw('get_class(')->subcompile($this->getNode('arguments')->getNode(1))->raw(')."::".'); } $compiler->subcompile($this->getNode('arguments')->getNode(0))->raw('))'); }
/** * Compile arguments * * @param Apishka_Templater_Compiler $compiler */ protected function compileArguments(Apishka_Templater_Compiler $compiler) { $compiler->raw('('); $first = true; if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { $compiler->raw('$this->env'); $first = false; } if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { if (!$first) { $compiler->raw(', '); } $compiler->raw('$context'); $first = false; } if ($this->hasAttribute('arguments')) { foreach ($this->getAttribute('arguments') as $argument) { if (!$first) { $compiler->raw(', '); } $compiler->string($argument); $first = false; } } if ($this->hasNode('node')) { if (!$first) { $compiler->raw(', '); } $compiler->subcompile($this->getNode('node')); $first = false; } if ($this->hasNode('arguments') && null !== $this->getNode('arguments')) { $callable = $this->getAttribute('callable'); $arguments = $this->getArguments($callable, $this->getNode('arguments')); foreach ($arguments as $node) { if (!$first) { $compiler->raw(', '); } $compiler->subcompile($node); $first = false; } } $compiler->raw(')'); }
public function compile(Apishka_Templater_Compiler $compiler) { $compiler->addDebugInfo($this); if (count($this->getNode('names')) > 1) { $compiler->write('list('); foreach ($this->getNode('names') as $idx => $node) { if ($idx) { $compiler->raw(', '); } $compiler->subcompile($node); } $compiler->raw(')'); } else { if ($this->getAttribute('capture')) { $compiler->write("ob_start();\n")->subcompile($this->getNode('values')); } $compiler->subcompile($this->getNode('names'), false); if ($this->getAttribute('capture')) { $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Apishka_Templater_Markup(\$tmp, \$this->env->getCharset())"); } } if (!$this->getAttribute('capture')) { $compiler->raw(' = '); if (count($this->getNode('names')) > 1) { $compiler->write('array('); foreach ($this->getNode('values') as $idx => $value) { if ($idx) { $compiler->raw(', '); } $compiler->subcompile($value); } $compiler->raw(')'); } else { if ($this->getAttribute('safe')) { $compiler->raw("('' === \$tmp = ")->subcompile($this->getNode('values'))->raw(") ? '' : new Apishka_Templater_Markup(\$tmp, \$this->env->getCharset())"); } else { $compiler->subcompile($this->getNode('values')); } } } $compiler->raw(";\n"); }
public function compile(Apishka_Templater_Compiler $compiler) { $compiler->raw('array('); $first = true; foreach ($this->getKeyValuePairs() as $pair) { if (!$first) { $compiler->raw(', '); } $first = false; $compiler->subcompile($pair['key'])->raw(' => ')->subcompile($pair['value']); } $compiler->raw(')'); }
public function compile(Apishka_Templater_Compiler $compiler) { $compiler->addDebugInfo($this); for ($i = 0, $count = count($this->getNode('tests')); $i < $count; $i += 2) { if ($i > 0) { $compiler->outdent()->write('} elseif ('); } else { $compiler->write('if ('); } $compiler->subcompile($this->getNode('tests')->getNode($i))->raw(") {\n")->indent()->subcompile($this->getNode('tests')->getNode($i + 1)); } if ($this->hasNode('else') && null !== $this->getNode('else')) { $compiler->outdent()->write("} else {\n")->indent()->subcompile($this->getNode('else')); } $compiler->outdent()->write("}\n"); }
public function compile(Apishka_Templater_Compiler $compiler) { if (function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) { $compiler->raw('twig_template_get_attributes($this, '); } else { $compiler->raw('$this->getAttribute('); } $compiler->subcompile($this->getNode('node')); $compiler->raw(', ')->subcompile($this->getNode('attribute')); // only generate optional arguments when needed (to make generated code more readable) $needSecond = Apishka_Templater_TemplateAbstract::ANY_CALL !== $this->getAttribute('type'); $needFirst = $needSecond || null !== $this->getNode('arguments'); if ($needFirst) { if (null !== $this->getNode('arguments')) { $compiler->raw(', ')->subcompile($this->getNode('arguments')); } else { $compiler->raw(', array()'); } } if ($needSecond) { $compiler->raw(', ')->repr($this->getAttribute('type')); } $compiler->raw(')'); }
public function compile(Apishka_Templater_Compiler $compiler) { $compiler->addDebugInfo($this)->write(sprintf("public function block_%s(\$context, array \$blocks = array())\n", $this->getAttribute('name')), "{\n")->indent(); $compiler->subcompile($this->getNode('body'))->outdent()->write("}\n\n"); }
protected function compileMacros(Apishka_Templater_Compiler $compiler) { $compiler->subcompile($this->getNode('macros')); }
public function compile(Apishka_Templater_Compiler $compiler) { $compiler->subcompile($this->getNode('body')); }