mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-13 23:35:49 +00:00
Optimize sprintf() calls for PHP 8.4
This commit is contained in:
+11
-11
@@ -191,14 +191,14 @@ final class ModuleNode extends Node
|
||||
|
||||
$compiler
|
||||
->addDebugInfo($node)
|
||||
->write(sprintf('$_trait_%s = $this->loadTemplate(', $i))
|
||||
->write(\sprintf('$_trait_%s = $this->loadTemplate(', $i))
|
||||
->subcompile($node)
|
||||
->raw(', ')
|
||||
->repr($node->getTemplateName())
|
||||
->raw(', ')
|
||||
->repr($node->getTemplateLine())
|
||||
->raw(");\n")
|
||||
->write(sprintf("if (!\$_trait_%s->unwrap()->isTraitable()) {\n", $i))
|
||||
->write(\sprintf("if (!\$_trait_%s->unwrap()->isTraitable()) {\n", $i))
|
||||
->indent()
|
||||
->write("throw new RuntimeError('Template \"'.")
|
||||
->subcompile($trait->getNode('template'))
|
||||
@@ -207,12 +207,12 @@ final class ModuleNode extends Node
|
||||
->raw(", \$this->source);\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->unwrap()->getBlocks();\n\n", $i, $i))
|
||||
->write(\sprintf("\$_trait_%s_blocks = \$_trait_%s->unwrap()->getBlocks();\n\n", $i, $i))
|
||||
;
|
||||
|
||||
foreach ($trait->getNode('targets') as $key => $value) {
|
||||
$compiler
|
||||
->write(sprintf('if (!isset($_trait_%s_blocks[', $i))
|
||||
->write(\sprintf('if (!isset($_trait_%s_blocks[', $i))
|
||||
->string($key)
|
||||
->raw("])) {\n")
|
||||
->indent()
|
||||
@@ -226,11 +226,11 @@ final class ModuleNode extends Node
|
||||
->outdent()
|
||||
->write("}\n\n")
|
||||
|
||||
->write(sprintf('$_trait_%s_blocks[', $i))
|
||||
->write(\sprintf('$_trait_%s_blocks[', $i))
|
||||
->subcompile($value)
|
||||
->raw(sprintf('] = $_trait_%s_blocks[', $i))
|
||||
->raw(\sprintf('] = $_trait_%s_blocks[', $i))
|
||||
->string($key)
|
||||
->raw(sprintf(']; unset($_trait_%s_blocks[', $i))
|
||||
->raw(\sprintf(']; unset($_trait_%s_blocks[', $i))
|
||||
->string($key)
|
||||
->raw("]);\n\n")
|
||||
;
|
||||
@@ -245,7 +245,7 @@ final class ModuleNode extends Node
|
||||
|
||||
for ($i = 0; $i < $countTraits; ++$i) {
|
||||
$compiler
|
||||
->write(sprintf('$_trait_%s_blocks'.($i == $countTraits - 1 ? '' : ',')."\n", $i))
|
||||
->write(\sprintf('$_trait_%s_blocks'.($i == $countTraits - 1 ? '' : ',')."\n", $i))
|
||||
;
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ final class ModuleNode extends Node
|
||||
|
||||
foreach ($this->getNode('blocks') as $name => $node) {
|
||||
$compiler
|
||||
->write(sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name))
|
||||
->write(\sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name))
|
||||
;
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ final class ModuleNode extends Node
|
||||
->write(" */\n")
|
||||
->write("public function getDebugInfo()\n", "{\n")
|
||||
->indent()
|
||||
->write(sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true))))
|
||||
->write(\sprintf("return %s;\n", str_replace("\n", '', var_export(array_reverse($compiler->getDebugInfo(), true), true))))
|
||||
->outdent()
|
||||
->write("}\n\n")
|
||||
;
|
||||
@@ -470,7 +470,7 @@ final class ModuleNode extends Node
|
||||
{
|
||||
if ($node instanceof ConstantExpression) {
|
||||
$compiler
|
||||
->write(sprintf('%s = $this->loadTemplate(', $var))
|
||||
->write(\sprintf('%s = $this->loadTemplate(', $var))
|
||||
->subcompile($node)
|
||||
->raw(', ')
|
||||
->repr($node->getTemplateName())
|
||||
|
||||
Reference in New Issue
Block a user