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


PHP Twig_Compiler::string方法代码示例

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


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

示例1: compile

 /**
  * Compiles the node to PHP.
  *
  * @param Twig_Compiler A Twig_Compiler instance
  */
 public function compile(Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     list($msg, $vars) = $this->compileString($this->nodes['body']);
     if (null !== $this->nodes['plural']) {
         list($msg1, $vars1) = $this->compileString($this->nodes['plural']);
         $vars = array_merge($vars, $vars1);
     }
     $function = null === $this->nodes['plural'] ? '__' : '__n';
     if ($vars) {
         $compiler->write('echo strtr(' . $function . '(')->subcompile($msg);
         if (null !== $this->nodes['plural']) {
             $compiler->raw(', ')->subcompile($msg1)->raw(', abs(')->subcompile($this->nodes['count'])->raw(')');
         }
         $compiler->raw(', true), array(');
         // modified: cakephp $return flag
         foreach ($vars as $var) {
             if ('count' === $var->getAttribute('name')) {
                 $compiler->string('%count%')->raw(' => abs(')->subcompile($this->nodes['count'])->raw('), ');
             } else {
                 $compiler->string('%' . $var->getAttribute('name') . '%')->raw(' => ')->subcompile($var)->raw(', ');
             }
         }
         $compiler->raw("));\n");
     } else {
         $compiler->write('echo ' . $function . '(')->subcompile($msg);
         if (null !== $this->nodes['plural']) {
             $compiler->raw(', ')->subcompile($msg1)->raw(', abs(')->subcompile($this->nodes['count'])->raw(')');
         }
         $compiler->raw(', true);');
         // modified: cakephp $return flag
     }
 }
开发者ID:visonforcoding,项目名称:TwigView,代码行数:38,代码来源:Twig_Node_Trans.php

示例2: compile

 /**
  * Compiles the node to PHP.
  *
  * @param Twig_Compiler A Twig_Compiler instance
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     list($msg, $vars) = $this->compileString($this->getNode('body'));
     if (null !== $this->getNode('plural')) {
         list($msg1, $vars1) = $this->compileString($this->getNode('plural'));
         $vars = array_merge($vars, $vars1);
     }
     $function = null === $this->getNode('plural') ? '\\Skeleton\\I18n\\Translation::translate' : '\\Skeleton\\I18n\\Translation::translate_plural';
     if ($vars) {
         $compiler->write('echo strtr(' . $function . '(')->subcompile($msg);
         if (null !== $this->getNode('plural')) {
             $compiler->raw(', ')->subcompile($msg1)->raw(', abs(')->subcompile($this->getNode('count'))->raw(')');
         }
         $compiler->raw(', $context[\'env\'][\'translation\']), array(');
         foreach ($vars as $var) {
             if ('count' === $var->getAttribute('name')) {
                 $compiler->string('%count%')->raw(' => abs(')->subcompile($this->getNode('count'))->raw('), ');
             } else {
                 $compiler->string('%' . $var->getAttribute('name') . '%')->raw(' => ')->subcompile($var)->raw(', ');
             }
         }
         $compiler->raw("));\n");
     } else {
         $compiler->write('echo ' . $function . '(')->subcompile($msg);
         if (null !== $this->getNode('plural')) {
             $compiler->raw(', ')->subcompile($msg1)->raw(', abs(')->subcompile($this->getNode('count'))->raw(')');
         }
         $compiler->raw(", " . '$context[\'env\'][\'translation\']' . ");\n");
     }
 }
开发者ID:tigron,项目名称:skeleton-i18n,代码行数:36,代码来源:Tigron.php

示例3: compile

 /**
  * Compiles the node to PHP.
  *
  * @param Twig_Compiler A Twig_Compiler instance
  */
 public function compile(Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     list($msg, $vars) = $this->compileString($this->getNode('body'));
     if (null !== $this->getNode('plural')) {
         list($msg1, $vars1) = $this->compileString($this->getNode('plural'));
         $vars = array_merge($vars, $vars1);
     }
     $function = null === $this->getNode('plural') ? 'gettext' : 'ngettext';
     if ($vars) {
         $compiler->write('echo strtr(' . $function . '(')->subcompile($msg);
         if (null !== $this->getNode('plural')) {
             $compiler->raw(', ')->subcompile($msg1)->raw(', abs(')->subcompile($this->getNode('count'))->raw(')');
         }
         $compiler->raw('), array(');
         foreach ($vars as $var) {
             if ('count' === $var->getAttribute('name')) {
                 $compiler->string('%count%')->raw(' => abs(')->subcompile($this->getNode('count'))->raw('), ');
             } else {
                 $compiler->string('%' . $var->getAttribute('name') . '%')->raw(' => ')->subcompile($var)->raw(', ');
             }
         }
         $compiler->raw("));\n");
     } else {
         $compiler->write('echo ' . $function . '(')->subcompile($msg);
         if (null !== $this->getNode('plural')) {
             $compiler->raw(', ')->subcompile($msg1)->raw(', abs(')->subcompile($this->getNode('count'))->raw(')');
         }
         $compiler->raw(");\n");
     }
 }
开发者ID:nzzdev,项目名称:Twig-extensions,代码行数:36,代码来源:Trans.php

示例4: compile

 public function compile(Twig_Compiler $compiler)
 {
     $function = $compiler->getEnvironment()->getFunction($this->getAttribute('name'));
     $compiler->raw($function->compile() . '(');
     $first = true;
     if ($function->needsEnvironment()) {
         $compiler->raw('$this->env');
         $first = false;
     }
     if ($function->needsContext()) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $compiler->raw('$context');
         $first = false;
     }
     foreach ($function->getArguments() as $argument) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $compiler->string($argument);
         $first = false;
     }
     foreach ($this->getNode('arguments') as $node) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $compiler->subcompile($node);
         $first = false;
     }
     $compiler->raw(')');
 }
开发者ID:necromuncher,项目名称:Twig,代码行数:32,代码来源:Function.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);
     list($msg, $vars) = $this->compileString($this->getNode('body'));
     $compiler->write('echo __(trim(')->subcompile($msg)->write('), array(');
     foreach ($vars as $var) {
         $compiler->string(':' . $var['name'])->raw(' => ')->subcompile($var)->raw(', ');
     }
     $compiler->raw("));\n");
 }
开发者ID:nexeck,项目名称:kohana-twig,代码行数:15,代码来源:node.php

示例6: compileFilter

 protected function compileFilter(Twig_Compiler $compiler, Twig_FilterInterface $filter)
 {
     $compiler->raw($filter->compile() . '(')->raw($filter->needsEnvironment() ? '$this->env, ' : '')->raw($filter->needsContext() ? '$context, ' : '');
     foreach ($filter->getArguments() as $argument) {
         $compiler->string($argument)->raw(', ');
     }
     $compiler->subcompile($this->getNode('node'));
     foreach ($this->getNode('arguments') as $node) {
         $compiler->raw(', ')->subcompile($node);
     }
     $compiler->raw(')');
 }
开发者ID:ceroberoz,项目名称:kurs,代码行数:12,代码来源:Filter.php

示例7: compile

 /**
  * {@inheritdoc}
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $options = $this->getNode('options');
     list($singular, $tokens) = $this->compileString($this->getNode('body'));
     $plural = NULL;
     if (NULL !== $this->getNode('plural')) {
         list($plural, $pluralTokens) = $this->compileString($this->getNode('plural'));
         $tokens = array_merge($tokens, $pluralTokens);
     }
     // Start writing with the function to be called.
     $compiler->write('echo ' . (empty($plural) ? 't' : '\\Drupal::translation()->formatPlural') . '(');
     // Move the count to the beginning of the parameters list.
     if (!empty($plural)) {
         $compiler->raw('abs(')->subcompile($this->getNode('count'))->raw('), ');
     }
     // Write the singular text parameter.
     $compiler->subcompile($singular);
     // Write the plural text parameter, if necessary.
     if (!empty($plural)) {
         $compiler->raw(', ')->subcompile($plural);
     }
     // Write any tokens found as an associative array parameter, otherwise just
     // leave as an empty array.
     $compiler->raw(', array(');
     foreach ($tokens as $token) {
         $compiler->string($token->getAttribute('placeholder'))->raw(' => ')->subcompile($token)->raw(', ');
     }
     $compiler->raw(')');
     // Write any options passed.
     if (!empty($options)) {
         $compiler->raw(', ')->subcompile($options);
     }
     // Write function closure.
     $compiler->raw(')');
     // Append translation debug markup, if necessary.
     if ($compiler->getEnvironment()->isDebug()) {
         $compiler->raw(" . '\n<!-- TRANSLATION: ");
         $compiler->subcompile($singular);
         if (!empty($plural)) {
             $compiler->raw(', PLURAL: ')->subcompile($plural);
         }
         if (!empty($options)) {
             foreach ($options->getKeyValuePairs() as $pair) {
                 $compiler->raw(', ' . Unicode::strtoupper($pair['key']->getAttribute('value')) . ': ')->subcompile($pair['value']);
             }
         }
         $compiler->raw(" -->\n'");
     }
     // End writing.
     $compiler->raw(";\n");
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:55,代码来源:TwigNodeTrans.php

示例8: compile

 /**
  * Compiles the node to PHP.
  *
  * @param Twig_Compiler $compiler A Twig_Compiler instance
  */
 public function compile(Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     list($msg, $vars) = $this->compileString($this->getNode('body'));
     if (null !== $this->getNode('plural')) {
         list($msg1, $vars1) = $this->compileString($this->getNode('plural'));
         $vars = array_merge($vars, $vars1);
     }
     $function = null === $this->getNode('plural') ? 'gettext' : 'ngettext';
     if (null !== ($notes = $this->getNode('notes'))) {
         $message = trim($notes->getAttribute('data'));
         // line breaks are not allowed cause we want a single line comment
         $message = str_replace(array("\n", "\r"), ' ', $message);
         $compiler->write("// notes: {$message}\n");
     }
     if ($vars) {
         $compiler->write('echo strtr(' . $function . '(')->subcompile($msg);
         if (null !== $this->getNode('plural')) {
             $compiler->raw(', ')->subcompile($msg1)->raw(', abs(')->subcompile($this->getNode('count'))->raw(')');
         }
         $compiler->raw('), array(');
         foreach ($vars as $var) {
             if ('count' === $var->getAttribute('name')) {
                 $compiler->string('%count%')->raw(' => abs(')->subcompile($this->getNode('count'))->raw('), ');
             } else {
                 $compiler->string('%' . $var->getAttribute('name') . '%')->raw(' => ')->subcompile($var)->raw(', ');
             }
         }
         $compiler->raw("));\n");
     } else {
         $compiler->write('echo ' . $function . '(')->subcompile($msg);
         if (null !== $this->getNode('plural')) {
             $compiler->raw(', ')->subcompile($msg1)->raw(', abs(')->subcompile($this->getNode('count'))->raw(')');
         }
         $compiler->raw(");\n");
     }
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:42,代码来源:Trans.php

示例9: compile

 /**
  * {@inheritdoc}
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->write("if (\$this->env->isDebug()) {\n")->indent();
     if (!$this->hasNode('values')) {
         // remove embedded templates (macros) from the context
         $compiler->write(sprintf('$%svars = array();' . "\n", $this->varPrefix))->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {' . "\n", $this->varPrefix))->indent()->write(sprintf('if (!$%sval instanceof \\Twig_Template) {' . "\n", $this->varPrefix))->indent()->write(sprintf('$%1$svars[$%1$skey] = $%1$sval;' . "\n", $this->varPrefix))->outdent()->write("}\n")->outdent()->write("}\n")->addDebugInfo($this)->write(sprintf('\\Symfony\\Component\\VarDumper\\VarDumper::dump($%svars);' . "\n", $this->varPrefix));
     } elseif (($values = $this->getNode('values')) && 1 === $values->count()) {
         $compiler->addDebugInfo($this)->write('\\Symfony\\Component\\VarDumper\\VarDumper::dump(')->subcompile($values->getNode(0))->raw(");\n");
     } else {
         $compiler->addDebugInfo($this)->write('\\Symfony\\Component\\VarDumper\\VarDumper::dump(array(' . "\n")->indent();
         foreach ($values as $node) {
             $compiler->addIndentation();
             if ($node->hasAttribute('name')) {
                 $compiler->string($node->getAttribute('name'))->raw(' => ');
             }
             $compiler->subcompile($node)->raw(",\n");
         }
         $compiler->outdent()->write("));\n");
     }
     $compiler->outdent()->write("}\n");
 }
开发者ID:ayoah,项目名称:symfony,代码行数:24,代码来源:DumpNode.php

示例10: compile

 /**
  * {@inheritdoc}
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $options = $this->getNode('options');
     list($singular, $tokens) = $this->compileString($this->getNode('body'));
     $plural = NULL;
     if (NULL !== $this->getNode('plural')) {
         list($plural, $pluralTokens) = $this->compileString($this->getNode('plural'));
         $tokens = array_merge($tokens, $pluralTokens);
     }
     // Start writing with the function to be called.
     $compiler->write('echo ' . (empty($plural) ? 't' : '\\Drupal::translation()->formatPlural') . '(');
     // Move the count to the beginning of the parameters list.
     if (!empty($plural)) {
         $compiler->raw('abs(')->subcompile($this->getNode('count'))->raw('), ');
     }
     // Write the singular text parameter.
     $compiler->subcompile($singular);
     // Write the plural text parameter, if necessary.
     if (!empty($plural)) {
         $compiler->raw(', ')->subcompile($plural);
     }
     // Write any tokens found as an associative array parameter, otherwise just
     // leave as an empty array.
     $compiler->raw(', array(');
     foreach ($tokens as $token) {
         $compiler->string($token->getAttribute('placeholder'))->raw(' => ')->subcompile($token)->raw(', ');
     }
     $compiler->raw(')');
     // Write any options passed.
     if (!empty($options)) {
         $compiler->raw(', ')->subcompile($options);
     }
     // Write function closure.
     $compiler->raw(')');
     // @todo Add debug output, see https://www.drupal.org/node/2512672
     // End writing.
     $compiler->raw(";\n");
 }
开发者ID:318io,项目名称:318-io,代码行数:42,代码来源:TwigNodeTrans.php

示例11: 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() . '(');
     $first = true;
     if ($function->needsEnvironment()) {
         $compiler->raw('$this->env');
         $first = false;
     }
     if ($function->needsContext()) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $compiler->raw('$context');
         $first = false;
     }
     foreach ($function->getArguments() as $argument) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $compiler->string($argument);
         $first = false;
     }
     foreach ($this->getNode('arguments') as $node) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $compiler->subcompile($node);
         $first = false;
     }
     $compiler->raw(')');
 }
开发者ID:Zyko0,项目名称:Baikal,代码行数:39,代码来源:Function.php

示例12: 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

示例13: compileArguments

 /**
  * Compile arguments to be used by the node.
  *
  * @param  \Twig_Compiler $compiler A Twig compiler instance.
  */
 protected function compileArguments(\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->raw('$compiled');
         $first = false;
     }
     $compiler->raw(')');
 }
开发者ID:Sommerregen,项目名称:grav-plugin-shortcodes,代码行数:38,代码来源:NodeExpressionShortcode.php


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