public function compile(IfwPsn_Vendor_Twig_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('))'); }
/** * Compiles the node to PHP. * * @param IfwPsn_Vendor_Twig_Compiler A IfwPsn_Vendor_Twig_Compiler instance */ public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->addDebugInfo($this)->write('')->subcompile($this->getNode('var'))->raw(' = '); if ($this->getNode('expr') instanceof IfwPsn_Vendor_Twig_Node_Expression_Name && '_self' === $this->getNode('expr')->getAttribute('name')) { $compiler->raw("\$this"); } else { $compiler->raw('$this->env->loadTemplate(')->subcompile($this->getNode('expr'))->raw(")"); } $compiler->raw(";\n"); }
public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { $name = $this->getAttribute('name'); if ($this->getAttribute('is_defined_test')) { if ($this->isSpecial()) { $compiler->repr(true); } else { $compiler->raw('array_key_exists(')->repr($name)->raw(', $context)'); } } elseif ($this->isSpecial()) { $compiler->raw($this->specialVars[$name]); } elseif ($this->getAttribute('always_defined')) { $compiler->raw('$context[')->string($name)->raw(']'); } else { // remove the non-PHP 5.4 version when PHP 5.3 support is dropped // as the non-optimized version is just a workaround for slow ternary operator // when the context has a lot of variables if (version_compare(phpversion(), '5.4.0RC1', '>=')) { // PHP 5.4 ternary operator performance was optimized $compiler->raw('(isset($context[')->string($name)->raw(']) ? $context[')->string($name)->raw('] : '); if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { $compiler->raw('null)'); } else { $compiler->raw('$this->getContext($context, ')->string($name)->raw('))'); } } else { $compiler->raw('$this->getContext($context, ')->string($name); if ($this->getAttribute('ignore_strict_check')) { $compiler->raw(', true'); } $compiler->raw(')'); } } }
/** * Compiles the node to PHP. * * @param IfwPsn_Vendor_Twig_Compiler A IfwPsn_Vendor_Twig_Compiler instance */ public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { if ($this->getAttribute('as_string')) { $compiler->raw('(string) '); } if ($this->getAttribute('output')) { $compiler->addDebugInfo($this)->write("\$this->displayBlock(")->subcompile($this->getNode('name'))->raw(", \$context, \$blocks);\n"); } else { $compiler->raw("\$this->renderBlock(")->subcompile($this->getNode('name'))->raw(", \$context, \$blocks)"); } }
public function compile(IfwPsn_Vendor_Twig_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(')'); }
/** * Compiles the node to PHP. * * @param IfwPsn_Vendor_Twig_Compiler A IfwPsn_Vendor_Twig_Compiler instance */ public function compile(IfwPsn_Vendor_Twig_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(IfwPsn_Vendor_Twig_Compiler $compiler) { if (function_exists('ifwpsn_twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) { $compiler->raw('ifwpsn_twig_template_get_attributes($this, '); } else { $compiler->raw('$this->getAttribute('); } if ($this->getAttribute('ignore_strict_check')) { $this->getNode('node')->setAttribute('ignore_strict_check', true); } $compiler->subcompile($this->getNode('node')); $compiler->raw(', ')->subcompile($this->getNode('attribute')); if (count($this->getNode('arguments')) || IfwPsn_Vendor_Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) { $compiler->raw(', ')->subcompile($this->getNode('arguments')); if (IfwPsn_Vendor_Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) { $compiler->raw(', ')->repr($this->getAttribute('type')); } if ($this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) { $compiler->raw(', ' . ($this->getAttribute('is_defined_test') ? 'true' : 'false')); } if ($this->getAttribute('ignore_strict_check')) { $compiler->raw(', ' . ($this->getAttribute('ignore_strict_check') ? 'true' : 'false')); } } $compiler->raw(')'); }
protected function addTemplateArguments(IfwPsn_Vendor_Twig_Compiler $compiler) { if (false === $this->getAttribute('only')) { if (null === $this->getNode('variables')) { $compiler->raw('$context'); } else { $compiler->raw('array_merge($context, ')->subcompile($this->getNode('variables'))->raw(')'); } } else { if (null === $this->getNode('variables')) { $compiler->raw('array()'); } else { $compiler->subcompile($this->getNode('variables')); } } }
protected function compileDisplayBody(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->subcompile($this->getNode('body')); if (null !== $this->getNode('parent')) { if ($this->getNode('parent') instanceof IfwPsn_Vendor_Twig_Node_Expression_Constant) { $compiler->write("\$this->parent"); } else { $compiler->write("\$this->getParent(\$context)"); } $compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n"); } }
/** * Compiles the node to PHP. * * @param IfwPsn_Vendor_Twig_Compiler A IfwPsn_Vendor_Twig_Compiler instance */ public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->addDebugInfo($this)->write(sprintf("public function get%s(", $this->getAttribute('name'))); $count = count($this->getNode('arguments')); $pos = 0; foreach ($this->getNode('arguments') as $name => $default) { $compiler->raw('$_' . $name . ' = ')->subcompile($default); if (++$pos < $count) { $compiler->raw(', '); } } $compiler->raw(")\n")->write("{\n")->indent(); if (!count($this->getNode('arguments'))) { $compiler->write("\$context = \$this->env->getGlobals();\n\n"); } else { $compiler->write("\$context = \$this->env->mergeGlobals(array(\n")->indent(); foreach ($this->getNode('arguments') as $name => $default) { $compiler->write('')->string($name)->raw(' => $_' . $name)->raw(",\n"); } $compiler->outdent()->write("));\n\n"); } $compiler->write("\$blocks = array();\n\n")->write("ob_start();\n")->write("try {\n")->indent()->subcompile($this->getNode('body'))->outdent()->write("} catch (Exception \$e) {\n")->indent()->write("ob_end_clean();\n\n")->write("throw \$e;\n")->outdent()->write("}\n\n")->write("return ('' === \$tmp = ob_get_clean()) ? '' : new IfwPsn_Vendor_Twig_Markup(\$tmp, \$this->env->getCharset());\n")->outdent()->write("}\n\n"); }
protected function compileArguments(IfwPsn_Vendor_Twig_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->hasAttribute('callable') ? $this->getAttribute('callable') : null; $arguments = $this->getArguments($callable, $this->getNode('arguments')); foreach ($arguments as $node) { if (!$first) { $compiler->raw(', '); } $compiler->subcompile($node); $first = false; } } $compiler->raw(')'); }
/** * Compiles the node to PHP. * * @param IfwPsn_Vendor_Twig_Compiler A IfwPsn_Vendor_Twig_Compiler instance */ public function compile(IfwPsn_Vendor_Twig_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 IfwPsn_Vendor_Twig_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 IfwPsn_Vendor_Twig_Markup(\$tmp, \$this->env->getCharset())"); } else { $compiler->subcompile($this->getNode('values')); } } } $compiler->raw(";\n"); }
/** * Compiles the node to PHP. * * @param IfwPsn_Vendor_Twig_Compiler A IfwPsn_Vendor_Twig_Compiler instance */ public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->raw('$context[')->string($this->getAttribute('name'))->raw(']'); }
public function operator(IfwPsn_Vendor_Twig_Compiler $compiler) { return $compiler->raw('^'); }
/** * Compiles the node to PHP. * * @param IfwPsn_Vendor_Twig_Compiler A IfwPsn_Vendor_Twig_Compiler instance */ public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->raw('(')->subcompile($this->getNode('left'))->raw(' '); $this->operator($compiler); $compiler->raw(' ')->subcompile($this->getNode('right'))->raw(')'); }
public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->raw('(0 == ')->subcompile($this->getNode('node'))->raw(' % ')->subcompile($this->getNode('arguments')->getNode(0))->raw(')'); }
public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->raw('(')->subcompile($this->getNode('node'))->raw(' % 2 == 0')->raw(')'); }
/** * Compiles the node to PHP. * * @param IfwPsn_Vendor_Twig_Compiler A IfwPsn_Vendor_Twig_Compiler instance */ public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name'))); }
public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->raw('((')->subcompile($this->getNode('expr1'))->raw(') ? (')->subcompile($this->getNode('expr2'))->raw(') : (')->subcompile($this->getNode('expr3'))->raw('))'); }
public function operator(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->raw('!'); }
public function compile(IfwPsn_Vendor_Twig_Compiler $compiler) { $compiler->raw('$_')->raw($this->getAttribute('name'))->raw('_'); }