[Web] Update composer libs
- Removing symfony/deprecation-contracts (v2.4.0) - Upgrading ddeboer/imap (1.12.1 => 1.13.1) - Upgrading directorytree/ldaprecord (v2.6.3 => v2.10.1) - Upgrading illuminate/contracts (v8.53.1 => v9.3.0) - Upgrading nesbot/carbon (2.51.1 => 2.57.0) - Upgrading phpmailer/phpmailer (v6.5.0 => v6.6.0) - Upgrading psr/container (1.1.1 => 2.0.2) - Upgrading psr/log (1.1.4 => 3.0.0) - Upgrading psr/simple-cache (1.0.1 => 2.0.0) - Upgrading robthree/twofactorauth (1.8.0 => 1.8.1) - Upgrading symfony/polyfill-ctype (v1.23.0 => v1.24.0) - Upgrading symfony/polyfill-mbstring (v1.23.1 => v1.24.0) - Upgrading symfony/polyfill-php80 (v1.23.1 => v1.24.0) - Upgrading symfony/translation (v5.3.4 => v6.0.5) - Upgrading symfony/translation-contracts (v2.4.0 => v3.0.0) - Upgrading symfony/var-dumper (v5.3.6 => v6.0.5) - Upgrading tightenco/collect (v8.34.0 => v8.83.2) - Upgrading twig/twig (v3.3.2 => v3.3.8)
This commit is contained in:
@@ -31,7 +31,7 @@ class FilesystemCache implements CacheInterface
|
||||
|
||||
public function generateKey(string $name, string $className): string
|
||||
{
|
||||
$hash = hash('sha256', $className);
|
||||
$hash = hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $className);
|
||||
|
||||
return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php';
|
||||
}
|
||||
|
||||
+1
-1
@@ -209,6 +209,6 @@ class Compiler
|
||||
|
||||
public function getVarName(): string
|
||||
{
|
||||
return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->varNameSalt++));
|
||||
return sprintf('__internal_compile_%d', $this->varNameSalt++);
|
||||
}
|
||||
}
|
||||
|
||||
+28
-10
@@ -38,11 +38,11 @@ use Twig\TokenParser\TokenParserInterface;
|
||||
*/
|
||||
class Environment
|
||||
{
|
||||
public const VERSION = '3.3.2';
|
||||
public const VERSION_ID = 30302;
|
||||
public const VERSION = '3.3.8';
|
||||
public const VERSION_ID = 30308;
|
||||
public const MAJOR_VERSION = 3;
|
||||
public const MINOR_VERSION = 3;
|
||||
public const RELEASE_VERSION = 2;
|
||||
public const RELEASE_VERSION = 8;
|
||||
public const EXTRA_VERSION = '';
|
||||
|
||||
private $charset;
|
||||
@@ -260,7 +260,7 @@ class Environment
|
||||
{
|
||||
$key = $this->getLoader()->getCacheKey($name).$this->optionsHash;
|
||||
|
||||
return $this->templateClassPrefix.hash('sha256', $key).(null === $index ? '' : '___'.$index);
|
||||
return $this->templateClassPrefix.hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $key).(null === $index ? '' : '___'.$index);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,7 +382,7 @@ class Environment
|
||||
*/
|
||||
public function createTemplate(string $template, string $name = null): TemplateWrapper
|
||||
{
|
||||
$hash = hash('sha256', $template, false);
|
||||
$hash = hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $template, false);
|
||||
if (null !== $name) {
|
||||
$name = sprintf('%s (string template %s)', $name, $hash);
|
||||
} else {
|
||||
@@ -433,11 +433,20 @@ class Environment
|
||||
return $this->load($names);
|
||||
}
|
||||
|
||||
$count = \count($names);
|
||||
foreach ($names as $name) {
|
||||
try {
|
||||
return $this->load($name);
|
||||
} catch (LoaderError $e) {
|
||||
if ($name instanceof Template) {
|
||||
return $name;
|
||||
}
|
||||
if ($name instanceof TemplateWrapper) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
if (1 !== $count && !$this->getLoader()->exists($name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $this->load($name);
|
||||
}
|
||||
|
||||
throw new LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names)));
|
||||
@@ -548,6 +557,13 @@ class Environment
|
||||
$this->runtimeLoaders[] = $loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TExtension of ExtensionInterface
|
||||
*
|
||||
* @param class-string<TExtension> $class
|
||||
*
|
||||
* @return TExtension
|
||||
*/
|
||||
public function getExtension(string $class): ExtensionInterface
|
||||
{
|
||||
return $this->extensionSet->getExtension($class);
|
||||
@@ -556,9 +572,11 @@ class Environment
|
||||
/**
|
||||
* Returns the runtime implementation of a Twig element (filter/function/tag/test).
|
||||
*
|
||||
* @param string $class A runtime class name
|
||||
* @template TRuntime of object
|
||||
*
|
||||
* @return object The runtime implementation
|
||||
* @param class-string<TRuntime> $class A runtime class name
|
||||
*
|
||||
* @return TRuntime The runtime implementation
|
||||
*
|
||||
* @throws RuntimeError When the template cannot be found
|
||||
*/
|
||||
|
||||
+104
-48
@@ -177,7 +177,7 @@ final class CoreExtension extends AbstractExtension
|
||||
// formatting filters
|
||||
new TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]),
|
||||
new TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]),
|
||||
new TwigFilter('format', 'sprintf'),
|
||||
new TwigFilter('format', 'twig_sprintf'),
|
||||
new TwigFilter('replace', 'twig_replace_filter'),
|
||||
new TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]),
|
||||
new TwigFilter('abs', 'abs'),
|
||||
@@ -193,15 +193,15 @@ final class CoreExtension extends AbstractExtension
|
||||
new TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]),
|
||||
new TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]),
|
||||
new TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]),
|
||||
new TwigFilter('striptags', 'strip_tags'),
|
||||
new TwigFilter('striptags', 'twig_striptags'),
|
||||
new TwigFilter('trim', 'twig_trim_filter'),
|
||||
new TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]),
|
||||
new TwigFilter('nl2br', 'twig_nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]),
|
||||
new TwigFilter('spaceless', 'twig_spaceless', ['is_safe' => ['html']]),
|
||||
|
||||
// array helpers
|
||||
new TwigFilter('join', 'twig_join_filter'),
|
||||
new TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]),
|
||||
new TwigFilter('sort', 'twig_sort_filter'),
|
||||
new TwigFilter('sort', 'twig_sort_filter', ['needs_environment' => true]),
|
||||
new TwigFilter('merge', 'twig_array_merge'),
|
||||
new TwigFilter('batch', 'twig_array_batch'),
|
||||
new TwigFilter('column', 'twig_array_column'),
|
||||
@@ -346,7 +346,7 @@ function twig_cycle($values, $position)
|
||||
function twig_random(Environment $env, $values = null, $max = null)
|
||||
{
|
||||
if (null === $values) {
|
||||
return null === $max ? mt_rand() : mt_rand(0, $max);
|
||||
return null === $max ? mt_rand() : mt_rand(0, (int) $max);
|
||||
}
|
||||
|
||||
if (\is_int($values) || \is_float($values)) {
|
||||
@@ -363,7 +363,7 @@ function twig_random(Environment $env, $values = null, $max = null)
|
||||
$max = $max;
|
||||
}
|
||||
|
||||
return mt_rand($min, $max);
|
||||
return mt_rand((int) $min, (int) $max);
|
||||
}
|
||||
|
||||
if (\is_string($values)) {
|
||||
@@ -443,6 +443,19 @@ function twig_date_modify_filter(Environment $env, $date, $modifier)
|
||||
return $date->modify($modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted string.
|
||||
*
|
||||
* @param string|null $format
|
||||
* @param ...$values
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function twig_sprintf($format, ...$values)
|
||||
{
|
||||
return sprintf($format ?? '', ...$values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an input to a \DateTime instance.
|
||||
*
|
||||
@@ -505,7 +518,7 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null)
|
||||
/**
|
||||
* Replaces strings within a string.
|
||||
*
|
||||
* @param string $str String to replace in
|
||||
* @param string|null $str String to replace in
|
||||
* @param array|\Traversable $from Replace values
|
||||
*
|
||||
* @return string
|
||||
@@ -516,20 +529,22 @@ function twig_replace_filter($str, $from)
|
||||
throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from)));
|
||||
}
|
||||
|
||||
return strtr($str, twig_to_array($from));
|
||||
return strtr($str ?? '', twig_to_array($from));
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds a number.
|
||||
*
|
||||
* @param int|float $value The value to round
|
||||
* @param int|float $precision The rounding precision
|
||||
* @param string $method The method to use for rounding
|
||||
* @param int|float|string|null $value The value to round
|
||||
* @param int|float $precision The rounding precision
|
||||
* @param string $method The method to use for rounding
|
||||
*
|
||||
* @return int|float The rounded number
|
||||
*/
|
||||
function twig_round($value, $precision = 0, $method = 'common')
|
||||
{
|
||||
$value = (float) $value;
|
||||
|
||||
if ('common' === $method) {
|
||||
return round($value, $precision);
|
||||
}
|
||||
@@ -545,7 +560,7 @@ function twig_round($value, $precision = 0, $method = 'common')
|
||||
* Number format filter.
|
||||
*
|
||||
* All of the formatting options can be left null, in that case the defaults will
|
||||
* be used. Supplying any of the parameters will override the defaults set in the
|
||||
* be used. Supplying any of the parameters will override the defaults set in the
|
||||
* environment object.
|
||||
*
|
||||
* @param mixed $number A float/int/string of the number to format
|
||||
@@ -576,7 +591,7 @@ function twig_number_format_filter(Environment $env, $number, $decimal = null, $
|
||||
/**
|
||||
* URL encodes (RFC 3986) a string as a path segment or an array as a query string.
|
||||
*
|
||||
* @param string|array $url A URL or an array of query parameters
|
||||
* @param string|array|null $url A URL or an array of query parameters
|
||||
*
|
||||
* @return string The URL encoded value
|
||||
*/
|
||||
@@ -586,7 +601,7 @@ function twig_urlencode_filter($url)
|
||||
return http_build_query($url, '', '&', \PHP_QUERY_RFC3986);
|
||||
}
|
||||
|
||||
return rawurlencode($url);
|
||||
return rawurlencode($url ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -648,9 +663,7 @@ function twig_slice(Environment $env, $item, $start, $length = null, $preserveKe
|
||||
return \array_slice($item, $start, $length, $preserveKeys);
|
||||
}
|
||||
|
||||
$item = (string) $item;
|
||||
|
||||
return mb_substr($item, $start, $length, $env->getCharset());
|
||||
return (string) mb_substr((string) $item, $start, $length, $env->getCharset());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -739,14 +752,16 @@ function twig_join_filter($value, $glue = '', $and = null)
|
||||
* {{ "aabbcc"|split('', 2) }}
|
||||
* {# returns [aa, bb, cc] #}
|
||||
*
|
||||
* @param string $value A string
|
||||
* @param string $delimiter The delimiter
|
||||
* @param int $limit The limit
|
||||
* @param string|null $value A string
|
||||
* @param string $delimiter The delimiter
|
||||
* @param int $limit The limit
|
||||
*
|
||||
* @return array The split string as an array
|
||||
*/
|
||||
function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
|
||||
{
|
||||
$value = $value ?? '';
|
||||
|
||||
if (\strlen($delimiter) > 0) {
|
||||
return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
|
||||
}
|
||||
@@ -831,8 +846,8 @@ function twig_get_array_keys_filter($array)
|
||||
/**
|
||||
* Reverses a variable.
|
||||
*
|
||||
* @param array|\Traversable|string $item An array, a \Traversable instance, or a string
|
||||
* @param bool $preserveKeys Whether to preserve key or not
|
||||
* @param array|\Traversable|string|null $item An array, a \Traversable instance, or a string
|
||||
* @param bool $preserveKeys Whether to preserve key or not
|
||||
*
|
||||
* @return mixed The reversed input
|
||||
*/
|
||||
@@ -851,10 +866,10 @@ function twig_reverse_filter(Environment $env, $item, $preserveKeys = false)
|
||||
$charset = $env->getCharset();
|
||||
|
||||
if ('UTF-8' !== $charset) {
|
||||
$item = twig_convert_encoding($string, 'UTF-8', $charset);
|
||||
$string = twig_convert_encoding($string, 'UTF-8', $charset);
|
||||
}
|
||||
|
||||
preg_match_all('/./us', $item, $matches);
|
||||
preg_match_all('/./us', $string, $matches);
|
||||
|
||||
$string = implode('', array_reverse($matches[0]));
|
||||
|
||||
@@ -872,7 +887,7 @@ function twig_reverse_filter(Environment $env, $item, $preserveKeys = false)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function twig_sort_filter($array, $arrow = null)
|
||||
function twig_sort_filter(Environment $env, $array, $arrow = null)
|
||||
{
|
||||
if ($array instanceof \Traversable) {
|
||||
$array = iterator_to_array($array);
|
||||
@@ -881,6 +896,8 @@ function twig_sort_filter($array, $arrow = null)
|
||||
}
|
||||
|
||||
if (null !== $arrow) {
|
||||
twig_check_arrow_in_sandbox($env, $arrow, 'sort', 'filter');
|
||||
|
||||
uasort($array, $arrow);
|
||||
} else {
|
||||
asort($array);
|
||||
@@ -1001,6 +1018,10 @@ function twig_compare($a, $b)
|
||||
/**
|
||||
* Returns a trimmed string.
|
||||
*
|
||||
* @param string|null $string
|
||||
* @param string|null $characterMask
|
||||
* @param string $side
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws RuntimeError When an invalid trimming side is used (not a string or not 'left', 'right', or 'both')
|
||||
@@ -1013,33 +1034,54 @@ function twig_trim_filter($string, $characterMask = null, $side = 'both')
|
||||
|
||||
switch ($side) {
|
||||
case 'both':
|
||||
return trim($string, $characterMask);
|
||||
return trim($string ?? '', $characterMask);
|
||||
case 'left':
|
||||
return ltrim($string, $characterMask);
|
||||
return ltrim($string ?? '', $characterMask);
|
||||
case 'right':
|
||||
return rtrim($string, $characterMask);
|
||||
return rtrim($string ?? '', $characterMask);
|
||||
default:
|
||||
throw new RuntimeError('Trimming side must be "left", "right" or "both".');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts HTML line breaks before all newlines in a string.
|
||||
*
|
||||
* @param string|null $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function twig_nl2br($string)
|
||||
{
|
||||
return nl2br($string ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes whitespaces between HTML tags.
|
||||
*
|
||||
* @param string|null $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function twig_spaceless($content)
|
||||
{
|
||||
return trim(preg_replace('/>\s+</', '><', $content));
|
||||
return trim(preg_replace('/>\s+</', '><', $content ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $string
|
||||
* @param string $to
|
||||
* @param string $from
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function twig_convert_encoding($string, $to, $from)
|
||||
{
|
||||
if (!\function_exists('iconv')) {
|
||||
throw new RuntimeError('Unable to convert encoding: required function iconv() does not exist. You should install ext-iconv or symfony/polyfill-iconv.');
|
||||
}
|
||||
|
||||
return iconv($from, $to, $string);
|
||||
return iconv($from, $to, $string ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1077,47 +1119,60 @@ function twig_length_filter(Environment $env, $thing)
|
||||
/**
|
||||
* Converts a string to uppercase.
|
||||
*
|
||||
* @param string $string A string
|
||||
* @param string|null $string A string
|
||||
*
|
||||
* @return string The uppercased string
|
||||
*/
|
||||
function twig_upper_filter(Environment $env, $string)
|
||||
{
|
||||
return mb_strtoupper($string, $env->getCharset());
|
||||
return mb_strtoupper($string ?? '', $env->getCharset());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string to lowercase.
|
||||
*
|
||||
* @param string $string A string
|
||||
* @param string|null $string A string
|
||||
*
|
||||
* @return string The lowercased string
|
||||
*/
|
||||
function twig_lower_filter(Environment $env, $string)
|
||||
{
|
||||
return mb_strtolower($string, $env->getCharset());
|
||||
return mb_strtolower($string ?? '', $env->getCharset());
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips HTML and PHP tags from a string.
|
||||
*
|
||||
* @param string|null $string
|
||||
* @param string[]|string|null $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function twig_striptags($string, $allowable_tags = null)
|
||||
{
|
||||
return strip_tags($string ?? '', $allowable_tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a titlecased string.
|
||||
*
|
||||
* @param string $string A string
|
||||
* @param string|null $string A string
|
||||
*
|
||||
* @return string The titlecased string
|
||||
*/
|
||||
function twig_title_string_filter(Environment $env, $string)
|
||||
{
|
||||
if (null !== $charset = $env->getCharset()) {
|
||||
return mb_convert_case($string, \MB_CASE_TITLE, $charset);
|
||||
return mb_convert_case($string ?? '', \MB_CASE_TITLE, $charset);
|
||||
}
|
||||
|
||||
return ucwords(strtolower($string));
|
||||
return ucwords(strtolower($string ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a capitalized string.
|
||||
*
|
||||
* @param string $string A string
|
||||
* @param string|null $string A string
|
||||
*
|
||||
* @return string The capitalized string
|
||||
*/
|
||||
@@ -1125,7 +1180,7 @@ function twig_capitalize_string_filter(Environment $env, $string)
|
||||
{
|
||||
$charset = $env->getCharset();
|
||||
|
||||
return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).mb_strtolower(mb_substr($string, 1, null, $charset), $charset);
|
||||
return mb_strtoupper(mb_substr($string ?? '', 0, 1, $charset), $charset).mb_strtolower(mb_substr($string ?? '', 1, null, $charset), $charset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1586,9 +1641,7 @@ function twig_array_filter(Environment $env, $array, $arrow)
|
||||
throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array)));
|
||||
}
|
||||
|
||||
if (!$arrow instanceof Closure && $env->hasExtension('\Twig\Extension\SandboxExtension') && $env->getExtension('\Twig\Extension\SandboxExtension')->isSandboxed()) {
|
||||
throw new RuntimeError('The callable passed to "filter" filter must be a Closure in sandbox mode.');
|
||||
}
|
||||
twig_check_arrow_in_sandbox($env, $arrow, 'filter', 'filter');
|
||||
|
||||
if (\is_array($array)) {
|
||||
return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH);
|
||||
@@ -1600,9 +1653,7 @@ function twig_array_filter(Environment $env, $array, $arrow)
|
||||
|
||||
function twig_array_map(Environment $env, $array, $arrow)
|
||||
{
|
||||
if (!$arrow instanceof Closure && $env->hasExtension('\Twig\Extension\SandboxExtension') && $env->getExtension('\Twig\Extension\SandboxExtension')->isSandboxed()) {
|
||||
throw new RuntimeError('The callable passed to the "map" filter must be a Closure in sandbox mode.');
|
||||
}
|
||||
twig_check_arrow_in_sandbox($env, $arrow, 'map', 'filter');
|
||||
|
||||
$r = [];
|
||||
foreach ($array as $k => $v) {
|
||||
@@ -1614,9 +1665,7 @@ function twig_array_map(Environment $env, $array, $arrow)
|
||||
|
||||
function twig_array_reduce(Environment $env, $array, $arrow, $initial = null)
|
||||
{
|
||||
if (!$arrow instanceof Closure && $env->hasExtension('\Twig\Extension\SandboxExtension') && $env->getExtension('\Twig\Extension\SandboxExtension')->isSandboxed()) {
|
||||
throw new RuntimeError('The callable passed to the "reduce" filter must be a Closure in sandbox mode.');
|
||||
}
|
||||
twig_check_arrow_in_sandbox($env, $arrow, 'reduce', 'filter');
|
||||
|
||||
if (!\is_array($array)) {
|
||||
if (!$array instanceof \Traversable) {
|
||||
@@ -1628,4 +1677,11 @@ function twig_array_reduce(Environment $env, $array, $arrow, $initial = null)
|
||||
|
||||
return array_reduce($array, $arrow, $initial);
|
||||
}
|
||||
|
||||
function twig_check_arrow_in_sandbox(Environment $env, $arrow, $thing, $type)
|
||||
{
|
||||
if (!$arrow instanceof Closure && $env->hasExtension('\Twig\Extension\SandboxExtension') && $env->getExtension('\Twig\Extension\SandboxExtension')->isSandboxed()) {
|
||||
throw new RuntimeError(sprintf('The callable passed to the "%s" %s must be a Closure in sandbox mode.', $thing, $type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
|
||||
|
||||
switch ($strategy) {
|
||||
case 'html':
|
||||
// see https://secure.php.net/htmlspecialchars
|
||||
// see https://www.php.net/htmlspecialchars
|
||||
|
||||
// Using a static variable to avoid initializing the array
|
||||
// each time the function is called. Moving the declaration on the
|
||||
@@ -277,7 +277,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
|
||||
return $shortMap[$char];
|
||||
}
|
||||
|
||||
$codepoint = mb_ord($char);
|
||||
$codepoint = mb_ord($char, 'UTF-8');
|
||||
if (0x10000 > $codepoint) {
|
||||
return sprintf('\u%04X', $codepoint);
|
||||
}
|
||||
|
||||
@@ -35,11 +35,16 @@ class Markup implements \Countable, \JsonSerializable
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return mb_strlen($this->content, $this->charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->content;
|
||||
|
||||
@@ -148,6 +148,7 @@ class Node implements \Countable, \IteratorAggregate
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return \count($this->nodes);
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ class Parser
|
||||
|
||||
public function getVarName(): string
|
||||
{
|
||||
return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->stream->getSourceContext()->getCode().$this->varNameSalt++));
|
||||
return sprintf('__internal_parse_%d', $this->varNameSalt++);
|
||||
}
|
||||
|
||||
public function parse(TokenStream $stream, $test = null, bool $dropNeedle = false): ModuleNode
|
||||
|
||||
+8
-14
@@ -28,10 +28,12 @@ use Twig\Profiler\Profile;
|
||||
final class ProfilerNodeVisitor implements NodeVisitorInterface
|
||||
{
|
||||
private $extensionName;
|
||||
private $varName;
|
||||
|
||||
public function __construct(string $extensionName)
|
||||
{
|
||||
$this->extensionName = $extensionName;
|
||||
$this->varName = sprintf('__internal_%s', hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $extensionName));
|
||||
}
|
||||
|
||||
public function enterNode(Node $node, Environment $env): Node
|
||||
@@ -42,33 +44,25 @@ final class ProfilerNodeVisitor implements NodeVisitorInterface
|
||||
public function leaveNode(Node $node, Environment $env): ?Node
|
||||
{
|
||||
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(): string
|
||||
{
|
||||
return sprintf('__internal_%s', hash('sha256', $this->extensionName));
|
||||
}
|
||||
|
||||
public function getPriority(): int
|
||||
{
|
||||
return 0;
|
||||
|
||||
@@ -186,7 +186,7 @@ abstract class IntegrationTestCase extends TestCase
|
||||
// avoid using the same PHP class name for different cases
|
||||
$p = new \ReflectionProperty($twig, 'templateClassPrefix');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_');
|
||||
$p->setValue($twig, '__TwigTemplate_'.hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', uniqid(mt_rand(), true), false).'_');
|
||||
|
||||
$deprecations = [];
|
||||
try {
|
||||
|
||||
@@ -16,11 +16,19 @@ namespace Twig\Util;
|
||||
*/
|
||||
class TemplateDirIterator extends \IteratorIterator
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function current()
|
||||
{
|
||||
return file_get_contents(parent::current());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function key()
|
||||
{
|
||||
return (string) parent::key();
|
||||
|
||||
Reference in New Issue
Block a user