Ejemplo n.º 1
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.º 2
0
 /**
  * Compile
  *
  * @param Apishka_Templater_Compiler $compiler
  */
 public function compile(Apishka_Templater_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $compiler->addDebugInfo($this);
     if ($this->isSpecial()) {
         $compiler->raw($this->specialVars[$name]);
     } elseif ($this->getAttribute('always_defined')) {
         $compiler->raw('$context[')->string($name)->raw(']');
     } else {
         $compiler->raw('(isset($context[')->string($name)->raw(']) ? $context[')->string($name)->raw('] : null)');
     }
 }
Ejemplo n.º 3
0
 /**
  * Compile args
  *
  * @param Apishka_Templater_Compiler     $compiler
  * @param Apishka_Templater_NodeAbstract $args
  */
 protected function compileContext(Apishka_Templater_Compiler $compiler, Apishka_Templater_NodeAbstract $args)
 {
     if (!count($args)) {
         $compiler->raw('$context, ');
         return;
     }
     $compiler->raw('array_replace(')->raw('$context, ')->raw('array(');
     foreach ($args as $name => $arg) {
         $compiler->write('')->string($name)->raw(' => ')->subcompile($arg)->raw(',');
     }
     $compiler->raw(')')->raw('), ');
 }
Ejemplo n.º 4
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.º 5
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.º 6
0
 public function compile(Apishka_Templater_Compiler $compiler)
 {
     if ($this->getAttribute('output')) {
         $compiler->addDebugInfo($this)->write('$this->displayParentBlock(')->string($this->getAttribute('name'))->raw(", \$context, \$blocks);\n");
     } else {
         $compiler->raw('$this->renderParentBlock(')->string($this->getAttribute('name'))->raw(', $context, $blocks)');
     }
 }
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
0
 public function compile(Apishka_Templater_Compiler $compiler)
 {
     $compiler->raw('(null === ')->subcompile($this->getNode('node'))->raw(')');
 }
Ejemplo n.º 11
0
 public function compile(Apishka_Templater_Compiler $compiler)
 {
     $compiler->raw('$_')->raw($this->getAttribute('name'))->raw('_');
 }
Ejemplo n.º 12
0
 /**
  * Compile
  *
  * @param Apishka_Templater_Compiler $compiler
  */
 public function compile(Apishka_Templater_Compiler $compiler)
 {
     $compiler->raw(' ');
     $this->operator($compiler);
     $compiler->subcompile($this->getNode('node'));
 }
Ejemplo n.º 13
0
 protected function compileDisplay(Apishka_Templater_Compiler $compiler)
 {
     $compiler->write("protected function doDisplay(array \$context, array \$blocks = array())\n", "{\n")->indent()->subcompile($this->getNode('display_start'))->subcompile($this->getNode('body'));
     if (null !== ($parent = $this->getNode('parent'))) {
         $compiler->addDebugInfo($parent);
         if ($parent instanceof Apishka_Templater_Node_Expression_Constant) {
             $compiler->write('$this->parent');
         } else {
             $compiler->write('$this->getParent($context)');
         }
         $compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n");
     }
     $compiler->subcompile($this->getNode('display_end'))->outdent()->write("}\n\n");
 }
Ejemplo n.º 14
0
 /**
  * Compile
  *
  * @param Apishka_Templater_Compiler $compiler
  */
 public function compile(Apishka_Templater_Compiler $compiler)
 {
     $compiler->raw('(')->subcompile($this->getNode('left'))->raw(' ');
     $this->operator($compiler);
     $compiler->raw(' ')->subcompile($this->getNode('right'))->raw(')');
 }
Ejemplo n.º 15
0
 /**
  * Operator
  *
  * @param Apishka_Templater_Compiler $compiler
  *
  * @return Apishka_Templater_Compiler
  */
 public function operator(Apishka_Templater_Compiler $compiler)
 {
     return $compiler->raw('!==');
 }
Ejemplo n.º 16
0
 public function compile(Apishka_Templater_Compiler $compiler)
 {
     $compiler->raw('((')->subcompile($this->getNode('expr1'))->raw(') ? (')->subcompile($this->getNode('expr2'))->raw(') : (')->subcompile($this->getNode('expr3'))->raw('))');
 }
Ejemplo n.º 17
0
 public function compile(Apishka_Templater_Compiler $compiler)
 {
     $compiler->raw('(0 == ')->subcompile($this->getNode('node'))->raw(' % ')->subcompile($this->getNode('arguments')->getNode(0))->raw(')');
 }
Ejemplo n.º 18
0
 /**
  * Operator
  *
  * @param Apishka_Templater_Compiler $compiler
  */
 public function operator(Apishka_Templater_Compiler $compiler)
 {
     $compiler->raw('!');
 }
Ejemplo n.º 19
0
 public function compile(Apishka_Templater_Compiler $compiler)
 {
     $compiler->raw('$context[')->string($this->getAttribute('name'))->raw(']');
 }