Esempio n. 1
0
 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(')');
 }
Esempio n. 2
0
 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(')');
 }
Esempio n. 3
0
 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('))');
 }
Esempio n. 4
0
 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(')');
 }
Esempio n. 5
0
 /**
  * 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");
 }
Esempio n. 6
0
 /**
  * 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(')');
 }
Esempio n. 7
0
 /**
  * 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);
     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");
 }
Esempio n. 8
0
 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'));
         }
     }
 }
Esempio n. 9
0
 public function compile(IfwPsn_Vendor_Twig_Compiler $compiler)
 {
     $compiler->subcompile($this->getNode('node'));
 }
Esempio n. 10
0
 /**
  * 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 block_%s(\$context, array \$blocks = array())\n", $this->getAttribute('name')), "{\n")->indent();
     $compiler->subcompile($this->getNode('body'))->outdent()->write("}\n\n");
 }
Esempio n. 11
0
 protected function compileMacros(IfwPsn_Vendor_Twig_Compiler $compiler)
 {
     $compiler->subcompile($this->getNode('macros'));
 }