Update Twig to v2.15.4

This commit is contained in:
slawkens
2023-02-02 10:37:45 +01:00
parent e552bcfe82
commit 130f7ba405
309 changed files with 3802 additions and 4005 deletions

View File

@@ -31,7 +31,7 @@ abstract class BaseDumper
abstract protected function formatTime(Profile $profile, $percent);
private function dumpProfile(Profile $profile, $prefix = '', $sibling = false)
private function dumpProfile(Profile $profile, $prefix = '', $sibling = false): string
{
if ($profile->isRoot()) {
$this->root = $profile->getDuration();

View File

@@ -15,10 +15,8 @@ use Twig\Profiler\Profile;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/
class BlackfireDumper
final class BlackfireDumper
{
public function dump(Profile $profile)
{
@@ -42,7 +40,7 @@ EOF;
return $str;
}
private function dumpChildren($parent, Profile $profile, &$data)
private function dumpChildren(string $parent, Profile $profile, &$data)
{
foreach ($profile as $p) {
if ($p->isTemplate()) {
@@ -55,7 +53,7 @@ EOF;
}
}
private function dumpProfile($edge, Profile $profile, &$data)
private function dumpProfile(string $edge, Profile $profile, &$data)
{
if (isset($data[$edge])) {
++$data[$edge]['ct'];

View File

@@ -15,10 +15,8 @@ use Twig\Profiler\Profile;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/
class HtmlDumper extends BaseDumper
final class HtmlDumper extends BaseDumper
{
private static $colors = [
'block' => '#dfd',

View File

@@ -15,10 +15,8 @@ use Twig\Profiler\Profile;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/
class TextDumper extends BaseDumper
final class TextDumper extends BaseDumper
{
protected function formatTemplate(Profile $profile, $prefix)
{

View File

@@ -21,7 +21,7 @@ use Twig\Node\Node;
*/
class EnterProfileNode extends Node
{
public function __construct($extensionName, $type, $name, $varName)
public function __construct(string $extensionName, string $type, string $name, string $varName)
{
parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]);
}
@@ -29,9 +29,9 @@ class EnterProfileNode extends Node
public function compile(Compiler $compiler)
{
$compiler
->write(sprintf('$%s = $this->env->getExtension(', $this->getAttribute('var_name')))
->write(sprintf('$%s = $this->extensions[', $this->getAttribute('var_name')))
->repr($this->getAttribute('extension_name'))
->raw(");\n")
->raw("];\n")
->write(sprintf('$%s->enter($%s = new \Twig\Profiler\Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof'))
->repr($this->getAttribute('type'))
->raw(', ')

View File

@@ -21,7 +21,7 @@ use Twig\Node\Node;
*/
class LeaveProfileNode extends Node
{
public function __construct($varName)
public function __construct(string $varName)
{
parent::__construct([], ['var_name' => $varName]);
}

View File

@@ -24,16 +24,16 @@ use Twig\Profiler\Profile;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/
class ProfilerNodeVisitor extends AbstractNodeVisitor
final class ProfilerNodeVisitor extends AbstractNodeVisitor
{
private $extensionName;
private $varName;
public function __construct($extensionName)
public function __construct(string $extensionName)
{
$this->extensionName = $extensionName;
$this->varName = sprintf('__internal_%s', hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $extensionName));
}
protected function doEnterNode(Node $node, Environment $env)
@@ -44,33 +44,25 @@ class ProfilerNodeVisitor extends AbstractNodeVisitor
protected function doLeaveNode(Node $node, Environment $env)
{
if ($node instanceof ModuleNode) {
$varName = $this->getVarName();
$node->setNode('display_start', new Node([new EnterProfileNode($this->extensionName, Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')]));
$node->setNode('display_end', new Node([new LeaveProfileNode($varName), $node->getNode('display_end')]));
$node->setNode('display_start', new Node([new EnterProfileNode($this->extensionName, Profile::TEMPLATE, $node->getTemplateName(), $this->varName), $node->getNode('display_start')]));
$node->setNode('display_end', new Node([new LeaveProfileNode($this->varName), $node->getNode('display_end')]));
} elseif ($node instanceof BlockNode) {
$varName = $this->getVarName();
$node->setNode('body', new BodyNode([
new EnterProfileNode($this->extensionName, Profile::BLOCK, $node->getAttribute('name'), $varName),
new EnterProfileNode($this->extensionName, Profile::BLOCK, $node->getAttribute('name'), $this->varName),
$node->getNode('body'),
new LeaveProfileNode($varName),
new LeaveProfileNode($this->varName),
]));
} elseif ($node instanceof MacroNode) {
$varName = $this->getVarName();
$node->setNode('body', new BodyNode([
new EnterProfileNode($this->extensionName, Profile::MACRO, $node->getAttribute('name'), $varName),
new EnterProfileNode($this->extensionName, Profile::MACRO, $node->getAttribute('name'), $this->varName),
$node->getNode('body'),
new LeaveProfileNode($varName),
new LeaveProfileNode($this->varName),
]));
}
return $node;
}
private function getVarName()
{
return sprintf('__internal_%s', hash('sha256', $this->extensionName));
}
public function getPriority()
{
return 0;

View File

@@ -14,14 +14,14 @@ namespace Twig\Profiler;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final
* @final since Twig 2.4.0
*/
class Profile implements \IteratorAggregate, \Serializable
{
const ROOT = 'ROOT';
const BLOCK = 'block';
const TEMPLATE = 'template';
const MACRO = 'macro';
public const ROOT = 'ROOT';
public const BLOCK = 'block';
public const TEMPLATE = 'template';
public const MACRO = 'macro';
private $template;
private $name;
@@ -30,8 +30,12 @@ class Profile implements \IteratorAggregate, \Serializable
private $ends = [];
private $profiles = [];
public function __construct($template = 'main', $type = self::ROOT, $name = 'main')
public function __construct(string $template = 'main', string $type = self::ROOT, string $name = 'main')
{
if (__CLASS__ !== static::class) {
@trigger_error('Overriding '.__CLASS__.' is deprecated since Twig 2.4.0 and the class will be final in 3.0.', \E_USER_DEPRECATED);
}
$this->template = $template;
$this->type = $type;
$this->name = 0 === strpos($name, '__internal_') ? 'INTERNAL' : $name;
@@ -153,17 +157,18 @@ class Profile implements \IteratorAggregate, \Serializable
$this->enter();
}
public function getIterator()
#[\ReturnTypeWillChange]
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->profiles);
}
public function serialize()
public function serialize(): string
{
return serialize($this->__serialize());
}
public function unserialize($data)
public function unserialize($data): void
{
$this->__unserialize(unserialize($data));
}
@@ -171,7 +176,7 @@ class Profile implements \IteratorAggregate, \Serializable
/**
* @internal
*/
public function __serialize()
public function __serialize(): array
{
return [$this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles];
}
@@ -179,7 +184,7 @@ class Profile implements \IteratorAggregate, \Serializable
/**
* @internal
*/
public function __unserialize(array $data)
public function __unserialize(array $data): void
{
list($this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles) = $data;
}