本文整理汇总了PHP中Twig_Compiler::raw方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Compiler::raw方法的具体用法?PHP Twig_Compiler::raw怎么用?PHP Twig_Compiler::raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Compiler
的用法示例。
在下文中一共展示了Twig_Compiler::raw方法的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);
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");
}
}
示例2: 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");
}
示例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)
{
$testMap = $compiler->getEnvironment()->getTests();
if (!isset($testMap[$this->getAttribute('name')])) {
throw new Twig_Error_Syntax(sprintf('The test "%s" does not exist', $this->getAttribute('name')), $this->getLine());
}
$name = $this->getAttribute('name');
$node = $this->getNode('node');
// defined is a special case
if ('defined' === $name) {
$compiler->subcompile($node);
return;
}
$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(')');
}
示例5: 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('))');
}
}
}
示例6: compile
public function compile(Twig_Compiler $compiler)
{
$testMap = $compiler->getEnvironment()->getTests();
if (!isset($testMap[$this->getAttribute('name')])) {
throw new Twig_Error_Syntax(sprintf('The test "%s" does not exist', $this->getAttribute('name')), $this->getLine());
}
$name = $this->getAttribute('name');
$node = $this->getNode('node');
// defined is a special case
if ('defined' === $name) {
if ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr) {
$node->setAttribute('is_defined_test', true);
$compiler->subcompile($node);
$node->removeAttribute('is_defined_test');
} else {
throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
}
return;
}
$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(')');
}
示例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());
}
$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(')');
}
示例8: compile
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
if ($this->getAttribute('as_string')) {
$compiler->raw('(string) ');
}
$compiler->raw("\$this->renderBlock(")->subcompile($this->getNode('name'))->raw(", \$context, \$blocks)");
}
示例9: compile
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
if ($this->getAttribute('ignore_missing')) {
$compiler->write("try {\n")->indent();
}
if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) {
$compiler->write("\$this->env->loadTemplate(")->subcompile($this->getNode('expr'))->raw(")->display(");
} else {
$compiler->write("\$template = \$this->env->resolveTemplate(")->subcompile($this->getNode('expr'))->raw(");\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");
if ($this->getAttribute('ignore_missing')) {
$compiler->outdent()->write("} catch (Twig_Error_Loader \$e) {\n")->indent()->write("// ignore missing template\n")->outdent()->write("}\n\n");
}
}
示例10: 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
}
}
示例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() . '(')->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(')');
}
示例12: compile
public function compile(Twig_Compiler $compiler)
{
$function = $compiler->getEnvironment()->getFunction($this->getNode('name')->getAttribute('name'));
if (!$function) {
throw new Twig_Error_Syntax(sprintf('The function "%s" does not exist', $this->getNode('name')->getAttribute('name')), $this->getLine());
}
$compiler
->raw($function->compile().'(')
->raw($function->needsEnvironment() ? '$this->env, ' : '')
->raw($function->needsContext() ? '$context, ' : '')
;
$first = true;
foreach ($this->getNode('arguments') as $node) {
if (!$first) {
$compiler->raw(', ');
} else {
$first = false;
}
$compiler->subcompile($node);
}
$compiler->raw(')');
}
示例13: compileBlockArguments
private function compileBlockArguments(Twig_Compiler $compiler)
{
$compiler->raw('(')->subcompile($this->getNode('name'))->raw(', $context');
if (!$this->hasNode('template')) {
$compiler->raw(', $blocks');
}
return $compiler->raw(')');
}
示例14: compile
public function compile(Twig_Compiler $compiler)
{
$compiler->raw('$this->getAttribute(')->subcompile($this->getNode('node'))->raw(', ')->subcompile($this->getNode('attribute'))->raw(', array(');
foreach ($this->getNode('arguments') as $node) {
$compiler->subcompile($node)->raw(', ');
}
$compiler->raw('), ')->repr($this->getAttribute('type'))->raw($this->hasAttribute('is_defined_test') ? ', true' : ', false')->raw(sprintf(', %d', $this->lineno))->raw(')');
}
示例15: compile
public function compile(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('))');
}