Rename some internal methods

This commit is contained in:
Fabien Potencier
2024-05-01 10:00:34 +02:00
parent c2c2058c33
commit 16acdf69fe
8 changed files with 98 additions and 177 deletions
+64 -143
View File
@@ -185,50 +185,50 @@ final class CoreExtension extends AbstractExtension
{
return [
// formatting filters
new TwigFilter('date', [self::class, 'dateFormatFilter'], ['needs_environment' => true]),
new TwigFilter('date_modify', [self::class, 'dateModifyFilter'], ['needs_environment' => true]),
new TwigFilter('date', [self::class, 'formatDate'], ['needs_environment' => true]),
new TwigFilter('date_modify', [self::class, 'modifyDate'], ['needs_environment' => true]),
new TwigFilter('format', [self::class, 'sprintf']),
new TwigFilter('replace', [self::class, 'replaceFilter']),
new TwigFilter('number_format', [self::class, 'numberFormatFilter'], ['needs_environment' => true]),
new TwigFilter('replace', [self::class, 'replace']),
new TwigFilter('number_format', [self::class, 'formatNumber'], ['needs_environment' => true]),
new TwigFilter('abs', 'abs'),
new TwigFilter('round', [self::class, 'round']),
// encoding
new TwigFilter('url_encode', [self::class, 'urlencodeFilter']),
new TwigFilter('url_encode', [self::class, 'urlencode']),
new TwigFilter('json_encode', 'json_encode'),
new TwigFilter('convert_encoding', [self::class, 'convertEncoding']),
// string filters
new TwigFilter('title', [self::class, 'titleStringFilter'], ['needs_environment' => true]),
new TwigFilter('capitalize', [self::class, 'capitalizeStringFilter'], ['needs_environment' => true]),
new TwigFilter('upper', [self::class, 'upperFilter'], ['needs_environment' => true]),
new TwigFilter('lower', [self::class, 'lowerFilter'], ['needs_environment' => true]),
new TwigFilter('title', [self::class, 'titleCase'], ['needs_environment' => true]),
new TwigFilter('capitalize', [self::class, 'capitalize'], ['needs_environment' => true]),
new TwigFilter('upper', [self::class, 'upper'], ['needs_environment' => true]),
new TwigFilter('lower', [self::class, 'lower'], ['needs_environment' => true]),
new TwigFilter('striptags', [self::class, 'striptags']),
new TwigFilter('trim', [self::class, 'trimFilter']),
new TwigFilter('trim', [self::class, 'trim']),
new TwigFilter('nl2br', [self::class, 'nl2br'], ['pre_escape' => 'html', 'is_safe' => ['html']]),
new TwigFilter('spaceless', [self::class, 'spaceless'], ['is_safe' => ['html']]),
// array helpers
new TwigFilter('join', [self::class, 'joinFilter']),
new TwigFilter('split', [self::class, 'splitFilter'], ['needs_environment' => true]),
new TwigFilter('sort', [self::class, 'sortFilter'], ['needs_environment' => true]),
new TwigFilter('merge', [self::class, 'arrayMerge']),
new TwigFilter('batch', [self::class, 'arrayBatch']),
new TwigFilter('column', [self::class, 'arrayColumn']),
new TwigFilter('filter', [self::class, 'arrayFilter'], ['needs_environment' => true]),
new TwigFilter('map', [self::class, 'arrayMap'], ['needs_environment' => true]),
new TwigFilter('reduce', [self::class, 'arrayReduce'], ['needs_environment' => true]),
new TwigFilter('join', [self::class, 'join']),
new TwigFilter('split', [self::class, 'split'], ['needs_environment' => true]),
new TwigFilter('sort', [self::class, 'sort'], ['needs_environment' => true]),
new TwigFilter('merge', [self::class, 'merge']),
new TwigFilter('batch', [self::class, 'batch']),
new TwigFilter('column', [self::class, 'column']),
new TwigFilter('filter', [self::class, 'filter'], ['needs_environment' => true]),
new TwigFilter('map', [self::class, 'map'], ['needs_environment' => true]),
new TwigFilter('reduce', [self::class, 'reduce'], ['needs_environment' => true]),
// string/array filters
new TwigFilter('reverse', [self::class, 'reverseFilter'], ['needs_environment' => true]),
new TwigFilter('length', [self::class, 'lengthFilter'], ['needs_environment' => true]),
new TwigFilter('reverse', [self::class, 'reverse'], ['needs_environment' => true]),
new TwigFilter('length', [self::class, 'length'], ['needs_environment' => true]),
new TwigFilter('slice', [self::class, 'slice'], ['needs_environment' => true]),
new TwigFilter('first', [self::class, 'first'], ['needs_environment' => true]),
new TwigFilter('last', [self::class, 'last'], ['needs_environment' => true]),
// iteration and runtime
new TwigFilter('default', [self::class, 'defaultFilter'], ['node_class' => DefaultFilter::class]),
new TwigFilter('keys', [self::class, 'getArrayKeysFilter']),
new TwigFilter('default', [self::class, 'default'], ['node_class' => DefaultFilter::class]),
new TwigFilter('keys', [self::class, 'keys']),
];
}
@@ -241,7 +241,7 @@ final class CoreExtension extends AbstractExtension
new TwigFunction('constant', [self::class, 'constant']),
new TwigFunction('cycle', [self::class, 'cycle']),
new TwigFunction('random', [self::class, 'random'], ['needs_environment' => true]),
new TwigFunction('date', [self::class, 'dateConverter'], ['needs_environment' => true]),
new TwigFunction('date', [self::class, 'convertDate'], ['needs_environment' => true]),
new TwigFunction('include', [self::class, 'include'], ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]),
new TwigFunction('source', [self::class, 'source'], ['needs_environment' => true, 'is_safe' => ['all']]),
];
@@ -322,7 +322,7 @@ final class CoreExtension extends AbstractExtension
*
* @internal
*/
public static function cycle($values, $position)
public static function cycle($values, $position): string
{
if (!\is_array($values) && !$values instanceof \ArrayAccess) {
return $values;
@@ -408,7 +408,7 @@ final class CoreExtension extends AbstractExtension
}
/**
* Converts a date to the given format.
* Formats a date.
*
* {{ post.published_at|date("m/d/Y") }}
*
@@ -416,11 +416,9 @@ final class CoreExtension extends AbstractExtension
* @param string|null $format The target format, null to use the default
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
*
* @return string The formatted date
*
* @internal
*/
public static function dateFormatFilter(Environment $env, $date, $format = null, $timezone = null)
public static function formatDate(Environment $env, $date, $format = null, $timezone = null): string
{
if (null === $format) {
$formats = $env->getExtension(self::class)->getDateFormat();
@@ -431,7 +429,7 @@ final class CoreExtension extends AbstractExtension
return $date->format($format);
}
return self::dateConverter($env, $date, $timezone)->format($format);
return self::convertDate($env, $date, $timezone)->format($format);
}
/**
@@ -442,15 +440,13 @@ final class CoreExtension extends AbstractExtension
* @param \DateTimeInterface|string $date A date
* @param string $modifier A modifier string
*
* @return \DateTimeInterface
* @return \DateTime|\DateTimeImmutable
*
* @internal
*/
public static function dateModifyFilter(Environment $env, $date, $modifier)
public static function modifyDate(Environment $env, $date, $modifier)
{
$date = self::dateConverter($env, $date, false);
return $date->modify($modifier);
return self::convertDate($env, $date, false)->modify($modifier);
}
/**
@@ -459,11 +455,9 @@ final class CoreExtension extends AbstractExtension
* @param string|null $format
* @param ...$values
*
* @return string
*
* @internal
*/
public static function sprintf($format, ...$values)
public static function sprintf($format, ...$values): string
{
return sprintf($format ?? '', ...$values);
}
@@ -482,7 +476,7 @@ final class CoreExtension extends AbstractExtension
*
* @internal
*/
public static function dateConverter(Environment $env, $date = null, $timezone = null)
public static function convertDate(Environment $env, $date = null, $timezone = null)
{
// determine the timezone
if (false !== $timezone) {
@@ -535,11 +529,9 @@ final class CoreExtension extends AbstractExtension
* @param string|null $str String to replace in
* @param array|\Traversable $from Replace values
*
* @return string
*
* @internal
*/
public static function replaceFilter($str, $from)
public static function replace($str, $from): string
{
if (!is_iterable($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)));
@@ -586,11 +578,9 @@ final class CoreExtension extends AbstractExtension
* @param string|null $decimalPoint the character(s) to use for the decimal point
* @param string|null $thousandSep the character(s) to use for the thousands separator
*
* @return string The formatted number
*
* @internal
*/
public static function numberFormatFilter(Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null)
public static function formatNumber(Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null): string
{
$defaults = $env->getExtension(self::class)->getNumberFormat();
if (null === $decimal) {
@@ -613,11 +603,9 @@ final class CoreExtension extends AbstractExtension
*
* @param string|array|null $url A URL or an array of query parameters
*
* @return string The URL encoded value
*
* @internal
*/
public static function urlencodeFilter($url)
public static function urlencode($url): string
{
if (\is_array($url)) {
return http_build_query($url, '', '&', \PHP_QUERY_RFC3986);
@@ -637,11 +625,9 @@ final class CoreExtension extends AbstractExtension
*
* @param array|\Traversable ...$arrays Any number of arrays or Traversable objects to merge
*
* @return array The merged array
*
* @internal
*/
public static function arrayMerge(...$arrays)
public static function merge(...$arrays): array
{
$result = [];
@@ -743,11 +729,9 @@ final class CoreExtension extends AbstractExtension
* @param string $glue The separator
* @param string|null $and The separator for the last pair
*
* @return string The concatenated string
*
* @internal
*/
public static function joinFilter($value, $glue = '', $and = null)
public static function join($value, $glue = '', $and = null): string
{
if (!is_iterable($value)) {
$value = (array) $value;
@@ -789,11 +773,9 @@ final class CoreExtension extends AbstractExtension
* @param string $delimiter The delimiter
* @param int|null $limit The limit
*
* @return array The split string as an array
*
* @internal
*/
public static function splitFilter(Environment $env, $value, $delimiter, $limit = null)
public static function split(Environment $env, $value, $delimiter, $limit = null): array
{
$value = $value ?? '';
@@ -824,7 +806,7 @@ final class CoreExtension extends AbstractExtension
/**
* @internal
*/
public static function defaultFilter($value, $default = '')
public static function default($value, $default = '')
{
if (self::testEmpty($value)) {
return $default;
@@ -842,13 +824,9 @@ final class CoreExtension extends AbstractExtension
* {# ... #}
* {% endfor %}
*
* @param array $array An array
*
* @return array The keys
*
* @internal
*/
public static function getArrayKeysFilter($array)
public static function keys($array): array
{
if ($array instanceof \Traversable) {
while ($array instanceof \IteratorAggregate) {
@@ -890,7 +868,7 @@ final class CoreExtension extends AbstractExtension
*
* @internal
*/
public static function reverseFilter(Environment $env, $item, $preserveKeys = false)
public static function reverse(Environment $env, $item, $preserveKeys = false)
{
if ($item instanceof \Traversable) {
return array_reverse(iterator_to_array($item), $preserveKeys);
@@ -924,11 +902,9 @@ final class CoreExtension extends AbstractExtension
*
* @param array|\Traversable $array
*
* @return array
*
* @internal
*/
public static function sortFilter(Environment $env, $array, $arrow = null)
public static function sort(Environment $env, $array, $arrow = null): array
{
if ($array instanceof \Traversable) {
$array = iterator_to_array($array);
@@ -1057,13 +1033,11 @@ final class CoreExtension extends AbstractExtension
}
/**
* @return int
*
* @throws RuntimeError When an invalid pattern is used
*
* @internal
*/
public static function matches(string $regexp, ?string $str)
public static function matches(string $regexp, ?string $str): int
{
set_error_handler(function ($t, $m) use ($regexp) {
throw new RuntimeError(sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
@@ -1082,13 +1056,11 @@ final class CoreExtension extends AbstractExtension
* @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')
*
* @internal
*/
public static function trimFilter($string, $characterMask = null, $side = 'both')
public static function trim($string, $characterMask = null, $side = 'both'): string
{
if (null === $characterMask) {
$characterMask = " \t\n\r\0\x0B";
@@ -1111,11 +1083,9 @@ final class CoreExtension extends AbstractExtension
*
* @param string|null $string
*
* @return string
*
* @internal
*/
public static function nl2br($string)
public static function nl2br($string): string
{
return nl2br($string ?? '');
}
@@ -1125,11 +1095,9 @@ final class CoreExtension extends AbstractExtension
*
* @param string|null $content
*
* @return string
*
* @internal
*/
public static function spaceless($content)
public static function spaceless($content): string
{
return trim(preg_replace('/>\s+</', '><', $content ?? ''));
}
@@ -1139,11 +1107,9 @@ final class CoreExtension extends AbstractExtension
* @param string $to
* @param string $from
*
* @return string
*
* @internal
*/
public static function convertEncoding($string, $to, $from)
public static function convertEncoding($string, $to, $from): string
{
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.');
@@ -1157,11 +1123,9 @@ final class CoreExtension extends AbstractExtension
*
* @param mixed $thing A variable
*
* @return int The length of the value
*
* @internal
*/
public static function lengthFilter(Environment $env, $thing)
public static function length(Environment $env, $thing): int
{
if (null === $thing) {
return 0;
@@ -1191,11 +1155,9 @@ final class CoreExtension extends AbstractExtension
*
* @param string|null $string A string
*
* @return string The uppercased string
*
* @internal
*/
public static function upperFilter(Environment $env, $string)
public static function upper(Environment $env, $string): string
{
return mb_strtoupper($string ?? '', $env->getCharset());
}
@@ -1205,11 +1167,9 @@ final class CoreExtension extends AbstractExtension
*
* @param string|null $string A string
*
* @return string The lowercased string
*
* @internal
*/
public static function lowerFilter(Environment $env, $string)
public static function lower(Environment $env, $string): string
{
return mb_strtolower($string ?? '', $env->getCharset());
}
@@ -1220,11 +1180,9 @@ final class CoreExtension extends AbstractExtension
* @param string|null $string
* @param string[]|string|null $allowable_tags
*
* @return string
*
* @internal
*/
public static function striptags($string, $allowable_tags = null)
public static function striptags($string, $allowable_tags = null): string
{
return strip_tags($string ?? '', $allowable_tags);
}
@@ -1234,11 +1192,9 @@ final class CoreExtension extends AbstractExtension
*
* @param string|null $string A string
*
* @return string The titlecased string
*
* @internal
*/
public static function titleStringFilter(Environment $env, $string)
public static function titleCase(Environment $env, $string): string
{
return mb_convert_case($string ?? '', \MB_CASE_TITLE, $env->getCharset());
}
@@ -1248,11 +1204,9 @@ final class CoreExtension extends AbstractExtension
*
* @param string|null $string A string
*
* @return string The capitalized string
*
* @internal
*/
public static function capitalizeStringFilter(Environment $env, $string)
public static function capitalize(Environment $env, $string): string
{
$charset = $env->getCharset();
@@ -1316,11 +1270,9 @@ final class CoreExtension extends AbstractExtension
*
* @param mixed $value A variable
*
* @return bool true if the value is empty, false otherwise
*
* @internal
*/
public static function testEmpty($value)
public static function testEmpty($value): bool
{
if ($value instanceof \Countable) {
return 0 === \count($value);
@@ -1337,27 +1289,6 @@ final class CoreExtension extends AbstractExtension
return '' === $value || false === $value || null === $value || [] === $value;
}
/**
* Checks if a variable is traversable.
*
* {# evaluates to true if the foo variable is an array or a traversable object #}
* {% if foo is iterable %}
* {# ... #}
* {% endif %}
*
* @param mixed $value A variable
*
* @return bool true if the value is traversable
*
* @deprecated since Twig 3.8, to be removed in 4.0 (use the native "is_iterable" function instead)
*
* @internal
*/
public static function testIterable($value)
{
return is_iterable($value);
}
/**
* Renders a template.
*
@@ -1368,11 +1299,9 @@ final class CoreExtension extends AbstractExtension
* @param bool $ignoreMissing Whether to ignore missing templates or not
* @param bool $sandboxed Whether to sandbox the template or not
*
* @return string The rendered template
*
* @internal
*/
public static function include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false)
public static function include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false): string
{
$alreadySandboxed = false;
$sandbox = null;
@@ -1418,11 +1347,9 @@ final class CoreExtension extends AbstractExtension
* @param string $name The template name
* @param bool $ignoreMissing Whether to ignore missing templates or not
*
* @return string The template source
*
* @internal
*/
public static function source(Environment $env, $name, $ignoreMissing = false)
public static function source(Environment $env, $name, $ignoreMissing = false): string
{
$loader = $env->getLoader();
try {
@@ -1442,11 +1369,9 @@ final class CoreExtension extends AbstractExtension
* @param string $constant The name of the constant
* @param object|null $object The object to get the constant from
*
* @return string
*
* @internal
*/
public static function constant($constant, $object = null)
public static function constant($constant, $object = null): string
{
if (null !== $object) {
if ('class' === $constant) {
@@ -1473,11 +1398,9 @@ final class CoreExtension extends AbstractExtension
* @param string $constant The name of the constant
* @param object|null $object The object to get the constant from
*
* @return bool
*
* @internal
*/
public static function constantIsDefined($constant, $object = null)
public static function constantIsDefined($constant, $object = null): bool
{
if (null !== $object) {
if ('class' === $constant) {
@@ -1497,11 +1420,9 @@ final class CoreExtension extends AbstractExtension
* @param int $size The size of the batch
* @param mixed $fill A value used to fill missing items
*
* @return array
*
* @internal
*/
public static function arrayBatch($items, $size, $fill = null, $preserveKeys = true)
public static function batch($items, $size, $fill = null, $preserveKeys = true): array
{
if (!is_iterable($items)) {
throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items)));
@@ -1736,7 +1657,7 @@ final class CoreExtension extends AbstractExtension
*
* @internal
*/
public static function arrayColumn($array, $name, $index = null): array
public static function column($array, $name, $index = null): array
{
if ($array instanceof \Traversable) {
$array = iterator_to_array($array);
@@ -1750,7 +1671,7 @@ final class CoreExtension extends AbstractExtension
/**
* @internal
*/
public static function arrayFilter(Environment $env, $array, $arrow)
public static function filter(Environment $env, $array, $arrow)
{
if (!is_iterable($array)) {
throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array)));
@@ -1769,7 +1690,7 @@ final class CoreExtension extends AbstractExtension
/**
* @internal
*/
public static function arrayMap(Environment $env, $array, $arrow)
public static function map(Environment $env, $array, $arrow)
{
self::checkArrowInSandbox($env, $arrow, 'map', 'filter');
@@ -1784,7 +1705,7 @@ final class CoreExtension extends AbstractExtension
/**
* @internal
*/
public static function arrayReduce(Environment $env, $array, $arrow, $initial = null)
public static function reduce(Environment $env, $array, $arrow, $initial = null)
{
self::checkArrowInSandbox($env, $arrow, 'reduce', 'filter');
+1 -1
View File
@@ -70,7 +70,7 @@ class ArrayExpression extends AbstractExpression
$needsArrayMergeSpread = \PHP_VERSION_ID < 80100 && $this->hasSpreadItem($keyValuePairs);
if ($needsArrayMergeSpread) {
$compiler->raw('CoreExtension::arrayMerge(');
$compiler->raw('CoreExtension::merge(');
}
$compiler->raw('[');
$first = true;
+1 -1
View File
@@ -97,7 +97,7 @@ class IncludeNode extends Node implements NodeOutputInterface
$compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]');
} elseif (false === $this->getAttribute('only')) {
$compiler
->raw('CoreExtension::arrayMerge($context, ')
->raw('CoreExtension::merge($context, ')
->subcompile($this->getNode('variables'))
->raw(')')
;
+23 -23
View File
@@ -42,7 +42,7 @@ function twig_date_format_filter(Environment $env, $date, $format = null, $timez
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::dateFormatFilter($env, $date, $format, $timezone);
return CoreExtension::formatDate($env, $date, $format, $timezone);
}
/**
@@ -53,7 +53,7 @@ function twig_date_modify_filter(Environment $env, $date, $modifier)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::dateModifyFilter($env, $date, $modifier);
return CoreExtension::modifyDate($env, $date, $modifier);
}
/**
@@ -75,7 +75,7 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::dateConverter($env, $date, $timezone);
return CoreExtension::convertDate($env, $date, $timezone);
}
/**
@@ -86,7 +86,7 @@ function twig_replace_filter($str, $from)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::replaceFilter($str, $from);
return CoreExtension::replace($str, $from);
}
/**
@@ -108,7 +108,7 @@ function twig_number_format_filter(Environment $env, $number, $decimal = null, $
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::numberFormatFilter($env, $number, $decimal, $decimalPoint, $thousandSep);
return CoreExtension::formatNumber($env, $number, $decimal, $decimalPoint, $thousandSep);
}
/**
@@ -119,7 +119,7 @@ function twig_urlencode_filter($url)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::urlencodeFilter($url);
return CoreExtension::urlencode($url);
}
/**
@@ -130,7 +130,7 @@ function twig_array_merge(...$arrays)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::arrayMerge(...$arrays);
return CoreExtension::merge(...$arrays);
}
/**
@@ -174,7 +174,7 @@ function twig_join_filter($value, $glue = '', $and = null)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::joinFilter($value, $glue, $and);
return CoreExtension::join($value, $glue, $and);
}
/**
@@ -185,7 +185,7 @@ function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::splitFilter($env, $value, $delimiter, $limit);
return CoreExtension::split($env, $value, $delimiter, $limit);
}
/**
@@ -196,7 +196,7 @@ function twig_get_array_keys_filter($array)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::getArrayKeysFilter($array);
return CoreExtension::keys($array);
}
/**
@@ -207,7 +207,7 @@ function twig_reverse_filter(Environment $env, $item, $preserveKeys = false)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::reverseFilter($env, $item, $preserveKeys);
return CoreExtension::reverse($env, $item, $preserveKeys);
}
/**
@@ -218,7 +218,7 @@ function twig_sort_filter(Environment $env, $array, $arrow = null)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::sortFilter($env, $array, $arrow);
return CoreExtension::sort($env, $array, $arrow);
}
/**
@@ -240,7 +240,7 @@ function twig_trim_filter($string, $characterMask = null, $side = 'both')
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::trimFilter($string, $characterMask, $side);
return CoreExtension::trim($string, $characterMask, $side);
}
/**
@@ -284,7 +284,7 @@ function twig_length_filter(Environment $env, $thing)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::lengthFilter($env, $thing);
return CoreExtension::length($env, $thing);
}
/**
@@ -295,7 +295,7 @@ function twig_upper_filter(Environment $env, $string)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::upperFilter($env, $string);
return CoreExtension::upper($env, $string);
}
/**
@@ -306,7 +306,7 @@ function twig_lower_filter(Environment $env, $string)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::lowerFilter($env, $string);
return CoreExtension::lower($env, $string);
}
/**
@@ -328,7 +328,7 @@ function twig_title_string_filter(Environment $env, $string)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::titleStringFilter($env, $string);
return CoreExtension::titleCase($env, $string);
}
/**
@@ -339,7 +339,7 @@ function twig_capitalize_string_filter(Environment $env, $string)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::capitalizeStringFilter($env, $string);
return CoreExtension::capitalize($env, $string);
}
/**
@@ -416,7 +416,7 @@ function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::arrayBatch($items, $size, $fill, $preserveKeys);
return CoreExtension::batch($items, $size, $fill, $preserveKeys);
}
/**
@@ -427,7 +427,7 @@ function twig_array_column($array, $name, $index = null): array
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::arrayColumn($array, $name, $index);
return CoreExtension::column($array, $name, $index);
}
/**
@@ -438,7 +438,7 @@ function twig_array_filter(Environment $env, $array, $arrow)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::arrayFilter($env, $array, $arrow);
return CoreExtension::filter($env, $array, $arrow);
}
/**
@@ -449,7 +449,7 @@ function twig_array_map(Environment $env, $array, $arrow)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::arrayMap($env, $array, $arrow);
return CoreExtension::map($env, $array, $arrow);
}
/**
@@ -460,7 +460,7 @@ function twig_array_reduce(Environment $env, $array, $arrow, $initial = null)
{
trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
return CoreExtension::arrayReduce($env, $array, $arrow, $initial);
return CoreExtension::reduce($env, $array, $arrow, $initial);
}
/**
+2 -2
View File
@@ -123,7 +123,7 @@ class CoreTest extends TestCase
$twig->setCharset('ISO-8859-1');
$input = iconv('UTF-8', 'ISO-8859-1', 'Äé');
$output = iconv('ISO-8859-1', 'UTF-8', CoreExtension::reverseFilter($twig, $input));
$output = iconv('ISO-8859-1', 'UTF-8', CoreExtension::reverse($twig, $input));
$this->assertEquals($output, 'éÄ');
}
@@ -177,7 +177,7 @@ class CoreTest extends TestCase
*/
public function testArrayKeysFilter(array $expected, $input)
{
$this->assertSame($expected, CoreExtension::getArrayKeysFilter($input));
$this->assertSame($expected, CoreExtension::keys($input));
}
public function provideArrayKeyCases()
+5 -5
View File
@@ -69,7 +69,7 @@ class FilterTest extends NodeTestCase
$node = $this->createFilter($expr, 'upper');
$node = $this->createFilter($node, 'number_format', [new ConstantExpression(2, 1), new ConstantExpression('.', 1), new ConstantExpression(',', 1)]);
$tests[] = [$node, 'Twig\Extension\CoreExtension::numberFormatFilter($this->env, Twig\Extension\CoreExtension::upperFilter($this->env, "foo"), 2, ".", ",")'];
$tests[] = [$node, 'Twig\Extension\CoreExtension::formatNumber($this->env, Twig\Extension\CoreExtension::upper($this->env, "foo"), 2, ".", ",")'];
// named arguments
$date = new ConstantExpression(0, 1);
@@ -77,25 +77,25 @@ class FilterTest extends NodeTestCase
'timezone' => new ConstantExpression('America/Chicago', 1),
'format' => new ConstantExpression('d/m/Y H:i:s P', 1),
]);
$tests[] = [$node, 'Twig\Extension\CoreExtension::dateFormatFilter($this->env, 0, "d/m/Y H:i:s P", "America/Chicago")'];
$tests[] = [$node, 'Twig\Extension\CoreExtension::formatDate($this->env, 0, "d/m/Y H:i:s P", "America/Chicago")'];
// skip an optional argument
$date = new ConstantExpression(0, 1);
$node = $this->createFilter($date, 'date', [
'timezone' => new ConstantExpression('America/Chicago', 1),
]);
$tests[] = [$node, 'Twig\Extension\CoreExtension::dateFormatFilter($this->env, 0, null, "America/Chicago")'];
$tests[] = [$node, 'Twig\Extension\CoreExtension::formatDate($this->env, 0, null, "America/Chicago")'];
// underscores vs camelCase for named arguments
$string = new ConstantExpression('abc', 1);
$node = $this->createFilter($string, 'reverse', [
'preserve_keys' => new ConstantExpression(true, 1),
]);
$tests[] = [$node, 'Twig\Extension\CoreExtension::reverseFilter($this->env, "abc", true)'];
$tests[] = [$node, 'Twig\Extension\CoreExtension::reverse($this->env, "abc", true)'];
$node = $this->createFilter($string, 'reverse', [
'preserveKeys' => new ConstantExpression(true, 1),
]);
$tests[] = [$node, 'Twig\Extension\CoreExtension::reverseFilter($this->env, "abc", true)'];
$tests[] = [$node, 'Twig\Extension\CoreExtension::reverse($this->env, "abc", true)'];
// filter as an anonymous function
$node = $this->createFilter(new ConstantExpression('foo', 1), 'anonymous');
+1 -1
View File
@@ -76,7 +76,7 @@ class FunctionTest extends NodeTestCase
'timezone' => new ConstantExpression('America/Chicago', 1),
'date' => new ConstantExpression(0, 1),
]);
$tests[] = [$node, 'Twig\Extension\CoreExtension::dateConverter($this->env, 0, "America/Chicago")'];
$tests[] = [$node, 'Twig\Extension\CoreExtension::convertDate($this->env, 0, "America/Chicago")'];
// arbitrary named arguments
$node = $this->createFunction('barbar');
+1 -1
View File
@@ -64,7 +64,7 @@ EOF
$node = new IncludeNode($expr, $vars, false, false, 1);
$tests[] = [$node, <<<'EOF'
// line 1
yield from $this->loadTemplate("foo.twig", null, 1)->unwrap()->yield(CoreExtension::arrayMerge($context, ["foo" => true]));
yield from $this->loadTemplate("foo.twig", null, 1)->unwrap()->yield(CoreExtension::merge($context, ["foo" => true]));
EOF
];