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


PHP Twig_Compiler::repr方法代码示例

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


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

示例1: 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, (bool) $vars);
     $method = null === $this->getNode('count') ? 'trans' : 'transChoice';
     $compiler->write('echo $this->env->getExtension(\'translator\')->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(', ');
     if (null === $this->getNode('domain')) {
         $compiler->repr('messages');
     } else {
         $compiler->subcompile($this->getNode('domain'));
     }
     if (null !== $this->getNode('locale')) {
         $compiler->raw(', ')->subcompile($this->getNode('locale'));
     }
     $compiler->raw(");\n");
 }
开发者ID:neteasy-work,项目名称:hkgbf_crm,代码行数:37,代码来源:TransNode.php

示例2: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $compiler->addDebugInfo($this);
     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 {
         if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
             $compiler->raw('(isset($context[')->string($name)->raw(']) ? $context[')->string($name)->raw('] : null)');
         } else {
             // When Twig will require PHP 7.0, the Template::notFound() method
             // will be removed and the code inlined like this:
             // (function () { throw new Exception(...); })();
             $compiler->raw('(isset($context[')->string($name)->raw(']) || array_key_exists(')->string($name)->raw(', $context) ? $context[')->string($name)->raw('] : $this->notFound(')->string($name)->raw(', ')->repr($this->lineno)->raw('))');
         }
     }
 }
开发者ID:rjagadishsingh,项目名称:Twig,代码行数:25,代码来源:Name.php

示例3: compileDefaults

 protected function compileDefaults(\Twig_Compiler $compiler, \Twig_Node_Expression_Array $defaults)
 {
     $compiler->raw('array(');
     foreach ($defaults as $name => $default) {
         $compiler->repr($name)->raw(' => ')->subcompile($default)->raw(', ');
     }
     $compiler->raw(')');
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:8,代码来源:TransNode.php

示例4: compileAssetUrl

 private function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset)
 {
     $compiler->repr($asset->getTargetPath());
     if (file_exists(PUB_DIR . DS . $asset->getTargetPath())) {
         return;
     }
     $writer = new \Assetic\AssetWriter(PUB_DIR . DS);
     $writer->writeAsset($asset);
 }
开发者ID:hidekscorporation,项目名称:hideksframework2,代码行数:9,代码来源:AsseticNode.php

示例5: compile

 /**
  * Compiles the node to PHP.
  *
  * @param Twig_Compiler A Twig_Compiler instance
  */
 public function compile(Twig_Compiler $compiler)
 {
     $compiler->raw('array(');
     $first = true;
     foreach ($this->nodes as $name => $node) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $first = false;
         $compiler->repr($name)->raw(' => ')->subcompile($node);
     }
     $compiler->raw(')');
 }
开发者ID:bigjoevtrj,项目名称:codeigniter-bootstrap,代码行数:18,代码来源:Array.php

示例6: testReprNumericValueWithLocale

 public function testReprNumericValueWithLocale()
 {
     $compiler = new Twig_Compiler(new Twig_Environment());
     $locale = setlocale(LC_NUMERIC, 0);
     if (false === $locale) {
         $this->markTestSkipped('Your platform does not support locales.');
     }
     $required_locales = ['fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252'];
     if (false === setlocale(LC_NUMERIC, $required_locales)) {
         $this->markTestSkipped('Could not set any of required locales: ' . implode(", ", $required_locales));
     }
     $this->assertEquals('1.2', $compiler->repr(1.2)->getSource());
     $this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0)));
     setlocale(LC_NUMERIC, $locale);
 }
开发者ID:DeDoOozZz,项目名称:brighterycms,代码行数:15,代码来源:CompilerTest.php

示例7: 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]);
     } else {
         $compiler->raw('$this->getContext($context, ')->string($name)->raw(')');
     }
 }
开发者ID:ryanhughes,项目名称:Twig,代码行数:15,代码来源:Name.php

示例8: compile

 public function compile(Twig_Compiler $compiler)
 {
     $compiler->raw('$this->env->view->getHelper(');
     $compiler->repr($this->getAttribute('helper'));
     $compiler->raw(')->' . $this->getAttribute('helper') . '(');
     $first = true;
     foreach ($this->getNode('args') as $arg) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $first = false;
         $compiler->subcompile($arg);
     }
     $compiler->raw(")");
 }
开发者ID:BGCX262,项目名称:zwig-svn-to-git,代码行数:15,代码来源:ViewHelper.php

示例9: compile

 public function compile(Twig_Compiler $compiler)
 {
     static $specialVars = array('_self' => '$this', '_context' => '$context', '_charset' => '$this->env->getCharset()');
     $name = $this->getAttribute('name');
     if ($this->hasAttribute('is_defined_test')) {
         if (isset($specialVars[$name])) {
             $compiler->repr(true);
         } else {
             $compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
         }
     } elseif (isset($specialVars[$name])) {
         $compiler->raw($specialVars[$name]);
     } else {
         $compiler->raw(sprintf('$this->getContext($context, \'%s\')', $name));
     }
 }
开发者ID:kuslahne,项目名称:rapid-slim-php-blog-application,代码行数:16,代码来源:Name.php

示例10: compileAssetUrl

 protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
 {
     if (!($vars = $asset->getVars())) {
         $compiler->repr($asset->getTargetPath());
         return;
     }
     $compiler->raw("strtr(")->string($asset->getTargetPath())->raw(", array(");
     $first = true;
     foreach ($vars as $var) {
         if (!$first) {
             $compiler->raw(", ");
         }
         $first = false;
         $compiler->string("{" . $var . "}")->raw(" => \$context['assetic']['vars']['{$var}']");
     }
     $compiler->raw("))");
 }
开发者ID:ccq18,项目名称:EduSoho,代码行数:17,代码来源:AsseticNode.php

示例11: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $compiler->addDebugInfo($this);
     if ($this->getAttribute('is_defined_test')) {
         if ($this->isSpecial()) {
             if ('_self' === $name) {
                 @trigger_error(sprintf('Global variable "_self" is deprecated in %s at line %d', '?', $this->getLine()), E_USER_DEPRECATED);
             }
             $compiler->repr(true);
         } else {
             $compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
         }
     } elseif ($this->isSpecial()) {
         if ('_self' === $name) {
             @trigger_error(sprintf('Global variable "_self" is deprecated in %s at line %d', '?', $this->getLine()), E_USER_DEPRECATED);
         }
         $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 (PHP_VERSION_ID >= 50400) {
             // 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(')');
         }
     }
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:41,代码来源:Name.php

示例12: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $compiler->addDebugInfo($this);
     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 {
         if (PHP_VERSION_ID >= 70000) {
             // use PHP 7 null coalescing operator
             $compiler->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('))');
             }
         } elseif (PHP_VERSION_ID >= 50400) {
             // 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(')');
         }
     }
 }
开发者ID:naldz,项目名称:cyberden,代码行数:40,代码来源:Name.php

示例13: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $compiler->addDebugInfo($this);
     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 {
         $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('))');
         }
     }
 }
开发者ID:JohnnyEstilles,项目名称:Twig,代码行数:23,代码来源:Name.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]);
     } else {
         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:carlesgutierrez,项目名称:libreobjet.org,代码行数:24,代码来源:Name.php

示例15: compileAssetUrl

 protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
 {
     $compiler->repr($asset->getTargetPath());
 }
开发者ID:artz20,项目名称:Tv-shows-zone,代码行数:4,代码来源:AsseticNode.php


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