Use first class callable syntax

This commit is contained in:
Fabien Potencier
2024-07-13 18:36:01 +02:00
parent fcb36ec18a
commit 8b47fc319a
18 changed files with 64 additions and 64 deletions
@@ -54,7 +54,7 @@ class CacheTokenParser extends AbstractTokenParser
}
$stream->expect(Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideCacheEnd'], true);
$body = $this->parser->subparse($this->decideCacheEnd(...), true);
$stream->expect(Token::BLOCK_END_TYPE);
$body = new CacheNode($key, $ttl, $tags, $body, $token->getLine(), $this->getTag());
@@ -20,7 +20,7 @@ class CssInlinerExtension extends AbstractExtension
public function getFilters()
{
return [
new TwigFilter('inline_css', [self::class, 'inlineCss'], ['is_safe' => ['all']]),
new TwigFilter('inline_css', self::inlineCss(...), ['is_safe' => ['all']]),
];
}
+1 -1
View File
@@ -36,7 +36,7 @@ final class HtmlExtension extends AbstractExtension
public function getFunctions(): array
{
return [
new TwigFunction('html_classes', [self::class, 'htmlClasses']),
new TwigFunction('html_classes', self::htmlClasses(...)),
];
}
+1 -1
View File
@@ -20,7 +20,7 @@ class InkyExtension extends AbstractExtension
public function getFilters()
{
return [
new TwigFilter('inky_to_html', [self::class, 'inky'], ['is_safe' => ['html']]),
new TwigFilter('inky_to_html', self::inky(...), ['is_safe' => ['html']]),
];
}
+1 -1
View File
@@ -21,7 +21,7 @@ final class MarkdownExtension extends AbstractExtension
{
return [
new TwigFilter('markdown_to_html', ['Twig\\Extra\\Markdown\\MarkdownRuntime', 'convert'], ['is_safe' => ['all']]),
new TwigFilter('html_to_markdown', [self::class, 'htmlToMarkdown'], ['is_safe' => ['all']]),
new TwigFilter('html_to_markdown', self::htmlToMarkdown(...), ['is_safe' => ['all']]),
];
}
+42 -42
View File
@@ -185,51 +185,51 @@ final class CoreExtension extends AbstractExtension
{
return [
// formatting filters
new TwigFilter('date', [$this, 'formatDate']),
new TwigFilter('date_modify', [$this, 'modifyDate']),
new TwigFilter('format', [self::class, 'sprintf']),
new TwigFilter('replace', [self::class, 'replace']),
new TwigFilter('number_format', [$this, 'formatNumber']),
new TwigFilter('date', $this->formatDate(...)),
new TwigFilter('date_modify', $this->modifyDate(...)),
new TwigFilter('format', self::sprintf(...)),
new TwigFilter('replace', self::replace(...)),
new TwigFilter('number_format', $this->formatNumber(...)),
new TwigFilter('abs', 'abs'),
new TwigFilter('round', [self::class, 'round']),
new TwigFilter('round', self::round(...)),
// encoding
new TwigFilter('url_encode', [self::class, 'urlencode']),
new TwigFilter('url_encode', self::urlencode(...)),
new TwigFilter('json_encode', 'json_encode'),
new TwigFilter('convert_encoding', [self::class, 'convertEncoding']),
new TwigFilter('convert_encoding', self::convertEncoding(...)),
// string filters
new TwigFilter('title', [self::class, 'titleCase'], ['needs_charset' => true]),
new TwigFilter('capitalize', [self::class, 'capitalize'], ['needs_charset' => true]),
new TwigFilter('upper', [self::class, 'upper'], ['needs_charset' => true]),
new TwigFilter('lower', [self::class, 'lower'], ['needs_charset' => true]),
new TwigFilter('striptags', [self::class, 'striptags']),
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']]),
new TwigFilter('title', self::titleCase(...), ['needs_charset' => true]),
new TwigFilter('capitalize', self::capitalize(...), ['needs_charset' => true]),
new TwigFilter('upper', self::upper(...), ['needs_charset' => true]),
new TwigFilter('lower', self::lower(...), ['needs_charset' => true]),
new TwigFilter('striptags', self::striptags(...)),
new TwigFilter('trim', self::trim(...)),
new TwigFilter('nl2br', self::nl2br(...), ['pre_escape' => 'html', 'is_safe' => ['html']]),
new TwigFilter('spaceless', self::spaceless(...), ['is_safe' => ['html']]),
// array helpers
new TwigFilter('join', [self::class, 'join']),
new TwigFilter('split', [self::class, 'split'], ['needs_charset' => 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]),
new TwigFilter('join', self::join(...)),
new TwigFilter('split', self::split(...), ['needs_charset' => true]),
new TwigFilter('sort', self::sort(...), ['needs_environment' => true]),
new TwigFilter('merge', self::merge(...)),
new TwigFilter('batch', self::batch(...)),
new TwigFilter('column', self::column(...)),
new TwigFilter('filter', self::filter(...), ['needs_environment' => true]),
new TwigFilter('map', self::map(...), ['needs_environment' => true]),
new TwigFilter('reduce', self::reduce(...), ['needs_environment' => true]),
// string/array filters
new TwigFilter('reverse', [self::class, 'reverse'], ['needs_charset' => true]),
new TwigFilter('shuffle', [self::class, 'shuffle'], ['needs_charset' => true]),
new TwigFilter('length', [self::class, 'length'], ['needs_charset' => true]),
new TwigFilter('slice', [self::class, 'slice'], ['needs_charset' => true]),
new TwigFilter('first', [self::class, 'first'], ['needs_charset' => true]),
new TwigFilter('last', [self::class, 'last'], ['needs_charset' => true]),
new TwigFilter('reverse', self::reverse(...), ['needs_charset' => true]),
new TwigFilter('shuffle', self::shuffle(...), ['needs_charset' => true]),
new TwigFilter('length', self::length(...), ['needs_charset' => true]),
new TwigFilter('slice', self::slice(...), ['needs_charset' => true]),
new TwigFilter('first', self::first(...), ['needs_charset' => true]),
new TwigFilter('last', self::last(...), ['needs_charset' => true]),
// iteration and runtime
new TwigFilter('default', [self::class, 'default'], ['node_class' => DefaultFilter::class]),
new TwigFilter('keys', [self::class, 'keys']),
new TwigFilter('default', self::default(...), ['node_class' => DefaultFilter::class]),
new TwigFilter('keys', self::keys(...)),
];
}
@@ -239,12 +239,12 @@ final class CoreExtension extends AbstractExtension
new TwigFunction('max', 'max'),
new TwigFunction('min', 'min'),
new TwigFunction('range', 'range'),
new TwigFunction('constant', [self::class, 'constant']),
new TwigFunction('cycle', [self::class, 'cycle']),
new TwigFunction('random', [self::class, 'random'], ['needs_charset' => true]),
new TwigFunction('date', [$this, 'convertDate']),
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']]),
new TwigFunction('constant', self::constant(...)),
new TwigFunction('cycle', self::cycle(...)),
new TwigFunction('random', self::random(...), ['needs_charset' => true]),
new TwigFunction('date', $this->convertDate(...)),
new TwigFunction('include', self::include(...), ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]),
new TwigFunction('source', self::source(...), ['needs_environment' => true, 'is_safe' => ['all']]),
];
}
@@ -259,10 +259,10 @@ final class CoreExtension extends AbstractExtension
new TwigTest('null', null, ['node_class' => NullTest::class]),
new TwigTest('divisible by', null, ['node_class' => DivisiblebyTest::class, 'one_mandatory_argument' => true]),
new TwigTest('constant', null, ['node_class' => ConstantTest::class]),
new TwigTest('empty', [self::class, 'testEmpty']),
new TwigTest('empty', self::testEmpty(...)),
new TwigTest('iterable', 'is_iterable'),
new TwigTest('sequence', [self::class, 'testSequence']),
new TwigTest('mapping', [self::class, 'testMapping']),
new TwigTest('sequence', self::testSequence(...)),
new TwigTest('mapping', self::testMapping(...)),
];
}
+1 -1
View File
@@ -31,7 +31,7 @@ final class DebugExtension extends AbstractExtension
;
return [
new TwigFunction('dump', [self::class, 'dump'], ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true, 'is_variadic' => true]),
new TwigFunction('dump', self::dump(...), ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true, 'is_variadic' => true]),
];
}
+3 -3
View File
@@ -45,9 +45,9 @@ final class EscaperExtension extends AbstractExtension
public function getFilters(): array
{
return [
new TwigFilter('escape', [EscaperRuntime::class, 'escape'], ['is_safe_callback' => [self::class, 'escapeFilterIsSafe']]),
new TwigFilter('e', [EscaperRuntime::class, 'escape'], ['is_safe_callback' => [self::class, 'escapeFilterIsSafe']]),
new TwigFilter('raw', [self::class, 'raw'], ['is_safe' => ['all']]),
new TwigFilter('escape', [EscaperRuntime::class, 'escape'], ['is_safe_callback' => self::escapeFilterIsSafe(...)]),
new TwigFilter('e', [EscaperRuntime::class, 'escape'], ['is_safe_callback' => self::escapeFilterIsSafe(...)]),
new TwigFilter('raw', self::raw(...), ['is_safe' => ['all']]),
];
}
+1 -1
View File
@@ -20,7 +20,7 @@ final class StringLoaderExtension extends AbstractExtension
public function getFunctions(): array
{
return [
new TwigFunction('template_from_string', [self::class, 'templateFromString'], ['needs_environment' => true]),
new TwigFunction('template_from_string', self::templateFromString(...), ['needs_environment' => true]),
];
}
+1 -1
View File
@@ -39,7 +39,7 @@ final class ApplyTokenParser extends AbstractTokenParser
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideApplyEnd'], true);
$body = $this->parser->subparse($this->decideApplyEnd(...), true);
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
return new Node([
+1 -1
View File
@@ -40,7 +40,7 @@ final class AutoEscapeTokenParser extends AbstractTokenParser
}
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
$body = $this->parser->subparse($this->decideBlockEnd(...), true);
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
return new AutoEscapeNode($value, $body, $lineno, $this->getTag());
+1 -1
View File
@@ -44,7 +44,7 @@ final class BlockTokenParser extends AbstractTokenParser
$this->parser->pushBlockStack($name);
if ($stream->nextIf(/* Token::BLOCK_END_TYPE */ 3)) {
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
$body = $this->parser->subparse($this->decideBlockEnd(...), true);
if ($token = $stream->nextIf(/* Token::NAME_TYPE */ 5)) {
$value = $token->getValue();
+2 -2
View File
@@ -39,10 +39,10 @@ final class ForTokenParser extends AbstractTokenParser
$seq = $this->parser->getExpressionParser()->parseExpression();
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
$body = $this->parser->subparse([$this, 'decideForFork']);
$body = $this->parser->subparse($this->decideForFork(...));
if ('else' == $stream->next()->getValue()) {
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
$else = $this->parser->subparse([$this, 'decideForEnd'], true);
$else = $this->parser->subparse($this->decideForEnd(...), true);
} else {
$else = null;
}
+3 -3
View File
@@ -38,7 +38,7 @@ final class IfTokenParser extends AbstractTokenParser
$expr = $this->parser->getExpressionParser()->parseExpression();
$stream = $this->parser->getStream();
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
$body = $this->parser->subparse([$this, 'decideIfFork']);
$body = $this->parser->subparse($this->decideIfFork(...));
$tests = [$expr, $body];
$else = null;
@@ -47,13 +47,13 @@ final class IfTokenParser extends AbstractTokenParser
switch ($stream->next()->getValue()) {
case 'else':
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
$else = $this->parser->subparse([$this, 'decideIfEnd']);
$else = $this->parser->subparse($this->decideIfEnd(...));
break;
case 'elseif':
$expr = $this->parser->getExpressionParser()->parseExpression();
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
$body = $this->parser->subparse([$this, 'decideIfFork']);
$body = $this->parser->subparse($this->decideIfFork(...));
$tests[] = $expr;
$tests[] = $body;
break;
+1 -1
View File
@@ -38,7 +38,7 @@ final class MacroTokenParser extends AbstractTokenParser
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
$this->parser->pushLocalScope();
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
$body = $this->parser->subparse($this->decideBlockEnd(...), true);
if ($token = $stream->nextIf(/* Token::NAME_TYPE */ 5)) {
$value = $token->getValue();
+1 -1
View File
@@ -35,7 +35,7 @@ final class SandboxTokenParser extends AbstractTokenParser
{
$stream = $this->parser->getStream();
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
$body = $this->parser->subparse($this->decideBlockEnd(...), true);
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
// in a sandbox tag, only include tags are allowed
+1 -1
View File
@@ -54,7 +54,7 @@ final class SetTokenParser extends AbstractTokenParser
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
$values = $this->parser->subparse([$this, 'decideBlockEnd'], true);
$values = $this->parser->subparse($this->decideBlockEnd(...), true);
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
}
+1 -1
View File
@@ -37,7 +37,7 @@ final class WithTokenParser extends AbstractTokenParser
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
$body = $this->parser->subparse([$this, 'decideWithEnd'], true);
$body = $this->parser->subparse($this->decideWithEnd(...), true);
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);