本文整理汇总了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
}
}
示例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");
}
}
示例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");
}
}
示例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(')');
}
示例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");
}
示例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(')');
}
示例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");
}
示例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");
}
}
示例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");
}
示例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");
}
示例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(')');
}
示例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("))");
}
示例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(')');
}