Ejemplo n.º 1
0
 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(')');
 }
Ejemplo n.º 2
0
 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('))');
 }
Ejemplo n.º 3
0
 /**
  * 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(')');
 }
Ejemplo n.º 4
0
 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");
 }
Ejemplo n.º 5
0
 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(')');
 }
Ejemplo n.º 6
0
 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");
 }
Ejemplo n.º 7
0
 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(')');
 }
Ejemplo n.º 8
0
 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");
 }
Ejemplo n.º 9
0
 protected function compileMacros(Apishka_Templater_Compiler $compiler)
 {
     $compiler->subcompile($this->getNode('macros'));
 }
Ejemplo n.º 10
0
 public function compile(Apishka_Templater_Compiler $compiler)
 {
     $compiler->subcompile($this->getNode('body'));
 }