当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Compiler类代码示例

本文整理汇总了PHP中Twig_Compiler的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Compiler类的具体用法?PHP Twig_Compiler怎么用?PHP Twig_Compiler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Twig_Compiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: compile

 /**
  * Compiles the node to PHP.
  *
  * @param Twig_Compiler A Twig_Compiler instance
  */
 public function compile(Twig_Compiler $compiler)
 {
     $compiler
         ->addDebugInfo($this)
         ->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name')))
     ;
 }
开发者ID:nizsheanez,项目名称:PolymorphCMS,代码行数:12,代码来源:BlockReference.php

示例2: compile

    /**
     * Compiles the node to PHP.
     *
     * @param Twig_Compiler A Twig_Compiler instance
     */
    public function compile(Twig_Compiler $compiler)
    {
        $arguments = array();
        foreach ($this->getNode('arguments') as $argument) {
            $arguments[] = '$'.$argument->getAttribute('name').' = null';
        }

        $compiler
            ->addDebugInfo($this)
            ->write(sprintf("public function get%s(%s)\n", $this->getAttribute('name'), implode(', ', $arguments)), "{\n")
            ->indent()
            ->write("\$context = array_merge(\$this->env->getGlobals(), array(\n")
            ->indent()
        ;

        foreach ($this->getNode('arguments') as $argument) {
            $compiler
                ->write('')
                ->string($argument->getAttribute('name'))
                ->raw(' => $'.$argument->getAttribute('name'))
                ->raw(",\n")
            ;
        }

        $compiler
            ->outdent()
            ->write("));\n\n")
            ->write("ob_start();\n")
            ->subcompile($this->getNode('body'))
            ->raw("\n")
            ->write("return ob_get_clean();\n")
            ->outdent()
            ->write("}\n\n")
        ;
    }
开发者ID:nizsheanez,项目名称:PolymorphCMS,代码行数:40,代码来源:Macro.php

示例3: compile

 /**
  * Compiles the node to PHP.
  *
  * @param Twig_Compiler A Twig_Compiler instance
  */
 public function compile(Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $template = $this->getNode('expr')->getAttribute('value');
     $value = 'Elements' . DS . $template . '.tpl';
     $this->getNode('expr')->setAttribute('value', $value);
     if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) {
         $compiler->write("\$this->env->loadTemplate(")->subcompile($this->getNode('expr'))->raw(")->display(");
     } else {
         $compiler->write("\$template = ")->subcompile($this->getNode('expr'))->raw(";\n")->write("if (!\$template")->raw(" instanceof Twig_Template) {\n")->indent()->write("\$template = \$this->env->loadTemplate(\$template);\n")->outdent()->write("}\n")->write('$template->display(');
     }
     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'));
         }
     }
     $compiler->raw(");\n");
 }
开发者ID:visonforcoding,项目名称:TwigView,代码行数:31,代码来源:Twig_Node_Element.php

示例4: compile

 /**
  * compile
  *
  * @param \Twig_Compiler $compiler
  *
  * @return  void
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $data = $this->getNode('value')->getAttribute('data');
     $markdown = new MarkdownExtra();
     $data = $markdown->defaultTransform($data);
     $compiler->write('echo ')->string($data)->raw(';');
 }
开发者ID:bgao-ca,项目名称:vaseman,代码行数:14,代码来源:MarkdownNode.php

示例5: compile

 /**
  * Compiles the node to PHP.
  *
  * @param \Twig_Compiler $compiler A Twig_Compiler instance
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $vars = $this->getNode('vars');
     $defaults = new \Twig_Node_Expression_Array(array(), -1);
     if ($vars instanceof \Twig_Node_Expression_Array) {
         $defaults = $this->getNode('vars');
         $vars = null;
     }
     list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults);
     $method = null === $this->getNode('count') ? 'trans' : 'transChoice';
     $compiler->write('echo $this->env->getExtension(\'translation\')->getTranslator()->' . $method . '(')->subcompile($msg);
     $compiler->raw(', ');
     if (null !== $this->getNode('count')) {
         $compiler->subcompile($this->getNode('count'))->raw(', ');
     }
     if (null !== $vars) {
         $compiler->raw('array_merge(')->subcompile($defaults)->raw(', ')->subcompile($this->getNode('vars'))->raw(')');
     } else {
         $compiler->subcompile($defaults);
     }
     $compiler->raw(', ')->subcompile($this->getNode('domain'));
     if (null !== $this->getNode('locale')) {
         $compiler->raw(', ')->subcompile($this->getNode('locale'));
     }
     $compiler->raw(");\n");
 }
开发者ID:miguelibero,项目名称:meinhof,代码行数:32,代码来源:TransNode.php

示例6: compile

 public function compile(\Twig_Compiler $compiler)
 {
     $varsToUnset = array();
     // Rights verification
     $compiler->write('$allowed = true; ' . "\n");
     foreach ($this->getAttribute('paths') as $path) {
         $compiler->write('$allowed = $context[\'dcylabs_twig_serviceProvider\']->get(\'path_roles\')->checkPath( ' . "\n")->subcompile($path)->write(') ? $allowed : false ;' . "\n");
     }
     $compiler->write('if($allowed){ ' . "\n");
     // Variable generation
     if (count($this->getAttribute('paths')) > 1) {
         foreach ($this->getAttribute('paths') as $path) {
             $this->setVar($compiler, '$context[\'check_urls\'][]', $path);
         }
         array_push($varsToUnset, 'check_urls');
     }
     $this->setVar($compiler, '$context[\'check_url\']', $this->getAttribute('paths')[0]);
     array_push($varsToUnset, 'check_url');
     $compiler->subcompile($this->getAttribute('body'));
     if (!is_null($this->getAttribute('alternativeBody'))) {
         $compiler->write('} else { ' . "\n");
         $compiler->subcompile($this->getAttribute('alternativeBody'));
     }
     $compiler->write('} ' . "\n");
     foreach ($varsToUnset as $var) {
         $this->unsetVar($compiler, '$context[\'' . $var . '\']');
     }
 }
开发者ID:dcylabs,项目名称:symfony-twig-helper,代码行数:28,代码来源:CheckRolesNode.php

示例7: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $testMap = $compiler->getEnvironment()->getTests();
     if (!isset($testMap[$name])) {
         $message = sprintf('The test "%s" does not exist', $name);
         if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getTests()))) {
             $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
         }
         throw new Twig_Error_Syntax($message, $this->getLine(), $compiler->getFilename());
     }
     $name = $this->getAttribute('name');
     $node = $this->getNode('node');
     $compiler->raw($testMap[$name]->compile() . '(')->subcompile($node);
     if (null !== $this->getNode('arguments')) {
         $compiler->raw(', ');
         $max = count($this->getNode('arguments')) - 1;
         foreach ($this->getNode('arguments') as $i => $arg) {
             $compiler->subcompile($arg);
             if ($i != $max) {
                 $compiler->raw(', ');
             }
         }
     }
     $compiler->raw(')');
 }
开发者ID:nsiskov,项目名称:tools.siskov,代码行数:26,代码来源:Test.php

示例8: compile

 /**
  * {@inheritdoc}
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->write('echo($this->env->getExtension(\'list_script_extension\')->get(
             \'' . $this->getAttribute('namespace') . '\',
             \'' . $this->getAttribute('bundle') . '\',
             \'' . $this->getAttribute('controller') . '\'));');
 }
开发者ID:hexmedia,项目名称:administrator-bundle,代码行数:10,代码来源:ListScriptNode.php

示例9: compileTemplateCall

 private function compileTemplateCall(Twig_Compiler $compiler)
 {
     if (!$this->hasNode('template')) {
         return $compiler->write('$this');
     }
     return $compiler->write('$this->loadTemplate(')->subcompile($this->getNode('template'))->raw(', ')->repr($this->getTemplateName())->raw(', ')->repr($this->getTemplateLine())->raw(')');
 }
开发者ID:richlove1,项目名称:avc-october,代码行数:7,代码来源:BlockReference.php

示例10: compile

 public function compile(\Twig_Compiler $compiler)
 {
     if (!$this->getNode('right') instanceof \Twig_Node_Expression_Name) {
         throw new \Exception("Right side of const operator must be identifier.");
     }
     $compiler->raw('(constant(get_class(')->subcompile($this->getNode('left'))->raw(') . (')->string("::" . $this->getNode('right')->getAttribute('name'))->raw(')))');
 }
开发者ID:dpolac,项目名称:twig-const,代码行数:7,代码来源:ConstOperator.php

示例11: compile

 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $type = $this->getAttribute('type');
     $template = $type == \Wave\View\Tag\Register::TYPE_JS ? self::FORMAT_JS : self::FORMAT_CSS;
     $compiler->write('foreach($this->env->_wave_register["' . $type . '"] as $priority => $files):')->raw("\n\t")->write('foreach($files as $file => $extra):')->raw("\n\t")->write('$code = sprintf("' . $template . '", $file, $extra);')->raw("\n\t")->write('echo $code . "<!-- $priority -->\\n";')->raw("\n\t")->write('endforeach;')->raw("\n")->write('endforeach;')->raw("\n");
 }
开发者ID:wave-framework,项目名称:wave,代码行数:7,代码来源:Output.php

示例12: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     if (false === ($function = $compiler->getEnvironment()->getFunction($name))) {
         $message = sprintf('The function "%s" does not exist', $name);
         if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getFunctions()))) {
             $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
         }
         throw new Twig_Error_Syntax($message, $this->getLine());
     }
     $compiler->raw($function->compile() . '(')->raw($function->needsEnvironment() ? '$this->env' : '');
     if ($function->needsContext()) {
         $compiler->raw($function->needsEnvironment() ? ', $context' : '$context');
     }
     $first = true;
     foreach ($this->getNode('arguments') as $node) {
         if (!$first) {
             $compiler->raw(', ');
         } else {
             if ($function->needsEnvironment() || $function->needsContext()) {
                 $compiler->raw(', ');
             }
             $first = false;
         }
         $compiler->subcompile($node);
     }
     $compiler->raw(')');
 }
开发者ID:fdelgados,项目名称:building-testable-applications,代码行数:28,代码来源:Function.php

示例13: compile

 /**
  * Compiles the node to PHP.
  *
  * @param \Twig_Compiler $compiler A Twig_Compiler instance
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $attrib = $this->getAttribute('name');
     //        if ($attrib == 'ajax') {
     $compiler->write('echo "<script type=\\"text/template\\" id=\\"ebussola-statefull-message-template\\">";')->write('$context["type"] = \'{{ type }}\';')->write('$context["message"] = \'{{ message }}\';')->subcompile($this->getNode('body'))->write('echo "</script>";');
     //        }
 }
开发者ID:ebussola,项目名称:OC-Statefull-Website,代码行数:12,代码来源:TwigFlashNode.php

示例14: compile

 public function compile(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', '>=') && ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables())) {
             // PHP 5.4 ternary operator performance was optimized
             $compiler->raw('(isset($context[')->string($name)->raw(']) ? $context[')->string($name)->raw('] : null)');
         } else {
             $compiler->raw('$this->getContext($context, ')->string($name);
             if ($this->getAttribute('ignore_strict_check')) {
                 $compiler->raw(', true');
             }
             $compiler->raw(')');
         }
     }
 }
开发者ID:2eye-studios,项目名称:development,代码行数:29,代码来源:Name.php

示例15: compile

 /**
  * Compiles the node to PHP.
  *
  * @param Twig_Compiler A Twig_Compiler instance
  */
 public function compile(Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this)->write("\$context['_parent'] = (array) \$context;\n")->write("\$context['_seq'] = twig_ensure_traversable(")->subcompile($this->getNode('seq'))->raw(");\n");
     if (null !== $this->getNode('else')) {
         $compiler->write("\$context['_iterated'] = false;\n");
     }
     if ($this->getAttribute('with_loop')) {
         $compiler->write("\$context['loop'] = array(\n")->write("  'parent' => \$context['_parent'],\n")->write("  'index0' => 0,\n")->write("  'index'  => 1,\n")->write("  'first'  => true,\n")->write(");\n");
         if (!$this->getAttribute('ifexpr')) {
             $compiler->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) {\n")->indent()->write("\$length = count(\$context['_seq']);\n")->write("\$context['loop']['revindex0'] = \$length - 1;\n")->write("\$context['loop']['revindex'] = \$length;\n")->write("\$context['loop']['length'] = \$length;\n")->write("\$context['loop']['last'] = 1 === \$length;\n")->outdent()->write("}\n");
         }
     }
     $this->loop->setAttribute('else', null !== $this->getNode('else'));
     $this->loop->setAttribute('with_loop', $this->getAttribute('with_loop'));
     $this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr'));
     $compiler->write("foreach (\$context['_seq'] as ")->subcompile($this->getNode('key_target'))->raw(" => ")->subcompile($this->getNode('value_target'))->raw(") {\n")->indent()->subcompile($this->getNode('body'))->outdent()->write("}\n");
     if (null !== $this->getNode('else')) {
         $compiler->write("if (!\$context['_iterated']) {\n")->indent()->subcompile($this->getNode('else'))->outdent()->write("}\n");
     }
     $compiler->write("\$_parent = \$context['_parent'];\n");
     // remove some "private" loop variables (needed for nested loops)
     $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\'' . $this->getNode('key_target')->getAttribute('name') . '\'], $context[\'' . $this->getNode('value_target')->getAttribute('name') . '\'], $context[\'_parent\'], $context[\'loop\']);' . "\n");
     // keep the values set in the inner context for variables defined in the outer context
     $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n");
 }
开发者ID:jesusmarket,项目名称:jesusmarket,代码行数:30,代码来源:For.php


注:本文中的Twig_Compiler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。