本文整理汇总了PHP中Twig_Compiler::addDebugInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Compiler::addDebugInfo方法的具体用法?PHP Twig_Compiler::addDebugInfo怎么用?PHP Twig_Compiler::addDebugInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Compiler
的用法示例。
在下文中一共展示了Twig_Compiler::addDebugInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
public function compile(\Twig_Compiler $compiler)
{
if ($this->getNode('default')) {
$compiler->addDebugInfo($this)->write('echo $this->env->getExtension(\'defer\')->has(')->string($this->getAttribute('name'))->raw(") ? ")->write('$this->env->getExtension(\'defer\')->flush(')->string($this->getAttribute('name'))->raw(") : ")->subcompile($this->getNode('default'))->raw(";\n");
} else {
$compiler->addDebugInfo($this)->write('echo $this->env->getExtension(\'defer\')->flush(')->string($this->getAttribute('name'))->raw(");\n");
}
}
示例2: compile
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$attributes = $this->getAttribute('holder_attributes');
if ($attributes) {
$compiler->addDebugInfo($this)->write('$this->env->getView()->placeholder(')->string($this->placeholder)->raw(')->set(')->subcompile($attributes)->raw(');');
} else {
$compiler->addDebugInfo($this)->write('echo $this->env->getView()->placeholder(')->string($this->placeholder)->raw(');');
}
}
示例3: compile
public function compile(\Twig_Compiler $compiler)
{
if ($this->value instanceof \Twig_Node_Expression) {
$compiler->addDebugInfo($this)->write('$this->env->getExtension(\'defer\')->defer(')->string($this->getAttribute('name'))->raw(', ')->subcompile($this->getNode('value'))->raw(");\n");
} else {
// This is very ugly, but I don't know how else to handle \Twig_Node that compiles into this: echo "constant expression";
$compiler->write("\$deferred = function() use (\$context, \$blocks) {")->indent()->write("ob_start();\n")->write("try {\n")->indent()->subcompile($this->getNode('value'))->write("return ob_get_clean();")->outdent()->write("} catch (Exception \$e) {\n")->indent()->write("ob_end_clean();\n\n")->write("throw \$e;\n")->outdent()->write("} catch (Throwable \$e) {\n")->indent()->write("ob_end_clean();\n\n")->write("throw \$e;\n")->outdent()->write("}\n\n")->outdent()->write("};");
$compiler->addDebugInfo($this)->write('$this->env->getExtension(\'defer\')->defer(')->string($this->getAttribute('name'))->raw(', ')->write("\$deferred()")->raw(");\n");
}
}
示例4: compile
public function compile(\Twig_Compiler $compiler)
{
foreach ($this->getAttribute('above_dumps') as $aboveDump) {
$compiler->subcompile($aboveDump);
}
$compiler->addDebugInfo($this)->write("ob_start();\n")->subcompile($this->getAttribute('below_dump'));
$compiler->write("\$buffer = ob_get_clean();\n");
// echo $this->env->getExtension('stamp')->dumpStamp('svg');
$compiler->addDebugInfo($this)->write("echo \$this->env->getExtension('stamp')->dumpStamp(")->string($this->getAttribute('name'))->raw(");\n");
$compiler->write("echo \$buffer;\n");
}
示例5: compile
public function compile(\Twig_Compiler $compiler)
{
// @codingStandardsIgnoreEnd
$compiler->addDebugInfo($this);
if ($this->assign) {
$compiler->raw('$context[\'' . $this->getAttribute('variable') . '\'] = ');
// @codingStandardsIgnoreStart
} else {
// @codingStandardsIgnoreEnd
$compiler->raw('echo ');
}
$compiler->raw('$context[\'_view\']->cell(');
$compiler->subcompile($this->getNode('name'));
$data = $this->getNode('data');
if ($data !== null) {
$compiler->raw(',');
$compiler->subcompile($data);
}
$options = $this->getNode('options');
if ($data !== null) {
$compiler->raw(',');
$compiler->subcompile($options);
}
$compiler->raw(");\n");
}
示例6: 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')))
;
}
示例7: 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");
}
示例8: 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")
;
}
示例9: 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('))');
}
}
}
示例10: 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");
}
示例11: compile
/**
* {@inheritDoc}
*/
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$this->compileAsset($compiler, $this->compressedAsset, $this->nameCompress);
$this->compileDebug($compiler);
$compiler->write('unset($context[')->repr($this->getAttribute('var_name'))->raw("]);\n");
}
示例12: compile
public function compile(\Twig_Compiler $compiler)
{
$count = count($this->getNode('params'));
if ($count == 1) {
throw new \Twig_Error_Runtime('Content identifier is missing.');
} else {
if ($count > 2) {
throw new \Twig_Error_Runtime('Too many arguments.');
}
}
$compiler->addDebugInfo($this);
for ($i = 0; $i < $count; $i++) {
// argument is not an expression (such as, a \Twig_Node_Textbody)
// we should trick with output buffering to get a valid argument to pass
// to the functionToCall() function.
if (!$this->getNode('params')->getNode($i) instanceof \Twig_Node_Expression) {
$compiler->write('ob_start();')->raw(PHP_EOL);
$compiler->subcompile($this->getNode('params')->getNode($i));
$compiler->write('$_content[] = ob_get_clean();')->raw(PHP_EOL);
} else {
$compiler->write('$_content[] = ')->subcompile($this->getNode('params')->getNode($i))->raw(';')->raw(PHP_EOL);
}
}
$rawText = $this->retriever->render($this->getNode('params')->getNode(1)->getAttribute('value'), $this->getNode('params')->getNode(0)->getAttribute('data'));
$compiler->raw('echo "' . str_replace('"', '\\"', $rawText) . '";')->raw(PHP_EOL);
}
示例13: 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");
}
}
示例14: 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");
}
}
示例15: compile
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this)->write(sprintf('public function macro_%s(', $this->getAttribute('name')));
$count = count($this->getNode('arguments'));
$pos = 0;
foreach ($this->getNode('arguments') as $name => $default) {
$compiler->raw('$__' . $name . '__ = ')->subcompile($default);
if (++$pos < $count) {
$compiler->raw(', ');
}
}
if (PHP_VERSION_ID >= 50600) {
if ($count) {
$compiler->raw(', ');
}
$compiler->raw('...$__varargs__');
}
$compiler->raw(")\n")->write("{\n")->indent();
$compiler->write("\$context = \$this->env->mergeGlobals(array(\n")->indent();
foreach ($this->getNode('arguments') as $name => $default) {
$compiler->addIndentation()->string($name)->raw(' => $__' . $name . '__')->raw(",\n");
}
$compiler->addIndentation()->string(self::VARARGS_NAME)->raw(' => ');
if (PHP_VERSION_ID >= 50600) {
$compiler->raw("\$__varargs__,\n");
} else {
$compiler->raw('func_num_args() > ')->repr($count)->raw(' ? array_slice(func_get_args(), ')->repr($count)->raw(") : array(),\n");
}
$compiler->outdent()->write("));\n\n")->write("\$blocks = array();\n\n")->write("ob_start();\n")->write("try {\n")->indent()->subcompile($this->getNode('body'))->raw("\n")->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")->outdent()->write("} finally {\n")->indent()->write("ob_end_clean();\n")->outdent()->write("}\n")->outdent()->write("}\n\n");
}