Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion extra/intl-extra/IntlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use Twig\TwigFilter;
use Twig\TwigFunction;

use function Twig\Extension\Core\Functions\twig_date_converter;

final class IntlExtension extends AbstractExtension
{
private const DATE_FORMATS = [
Expand Down Expand Up @@ -279,7 +281,7 @@ public function formatNumberStyle(string $style, $number, array $attrs = [], str
*/
public function formatDateTime(Environment $env, $date, ?string $dateFormat = 'medium', ?string $timeFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', string $locale = null): string
{
$date = \twig_date_converter($env, $date, $timezone);
$date = twig_date_converter($env, $date, $timezone);
$formatter = $this->createDateFormatter($locale, $dateFormat, $timeFormat, $pattern, $date->getTimezone(), $calendar);

if (false === $ret = $formatter->format($date)) {
Expand Down
6 changes: 3 additions & 3 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function setCache($cache)
*
* @internal
*/
public function getTemplateClass(string $name, int $index = null): string
public function getTemplateClass(string $name, ?int $index = null): string
{
$key = $this->getLoader()->getCacheKey($name).$this->optionsHash;

Expand Down Expand Up @@ -327,7 +327,7 @@ public function load($name): TemplateWrapper
*
* @internal
*/
public function loadTemplate(string $cls, string $name, int $index = null): Template
public function loadTemplate(string $cls, string $name, ?int $index = null): Template
{
$mainCls = $cls;
if (null !== $index) {
Expand Down Expand Up @@ -383,7 +383,7 @@ public function loadTemplate(string $cls, string $name, int $index = null): Temp
* @throws LoaderError When the template cannot be found
* @throws SyntaxError When an error occurred during compilation
*/
public function createTemplate(string $template, string $name = null): TemplateWrapper
public function createTemplate(string $template, ?string $name = null): TemplateWrapper
{
$hash = hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $template, false);
if (null !== $name) {
Expand Down
2 changes: 1 addition & 1 deletion src/Error/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Error extends \Exception
* @param int $lineno The template line where the error occurred
* @param Source|null $source The source context where the error occurred
*/
public function __construct(string $message, int $lineno = -1, Source $source = null, \Exception $previous = null)
public function __construct(string $message, int $lineno = -1, ?Source $source = null, ?\Exception $previous = null)
{
parent::__construct('', 0, $previous);

Expand Down
82 changes: 41 additions & 41 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,50 +175,50 @@ public function getFilters(): array
{
return [
// 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', 'twig_sprintf'),
new TwigFilter('replace', 'twig_replace_filter'),
new TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]),
new TwigFilter('date', '\Twig\Extension\Core\Functions\twig_date_format_filter', ['needs_environment' => true]),
new TwigFilter('date_modify', '\Twig\Extension\Core\Functions\twig_date_modify_filter', ['needs_environment' => true]),
new TwigFilter('format', '\Twig\Extension\Core\Functions\twig_sprintf'),
new TwigFilter('replace', '\Twig\Extension\Core\Functions\twig_replace_filter'),
new TwigFilter('number_format', '\Twig\Extension\Core\Functions\twig_number_format_filter', ['needs_environment' => true]),
new TwigFilter('abs', 'abs'),
new TwigFilter('round', 'twig_round'),
new TwigFilter('round', '\Twig\Extension\Core\Functions\twig_round'),

// encoding
new TwigFilter('url_encode', 'twig_urlencode_filter'),
new TwigFilter('url_encode', '\Twig\Extension\Core\Functions\twig_urlencode_filter'),
new TwigFilter('json_encode', 'json_encode'),
new TwigFilter('convert_encoding', 'twig_convert_encoding'),
new TwigFilter('convert_encoding', '\Twig\Extension\Core\Functions\twig_convert_encoding'),

// string filters
new TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]),
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', 'twig_striptags'),
new TwigFilter('trim', 'twig_trim_filter'),
new TwigFilter('nl2br', 'twig_nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]),
new TwigFilter('spaceless', 'twig_spaceless', ['is_safe' => ['html']]),
new TwigFilter('title', '\Twig\Extension\Core\Functions\twig_title_string_filter', ['needs_environment' => true]),
new TwigFilter('capitalize', '\Twig\Extension\Core\Functions\twig_capitalize_string_filter', ['needs_environment' => true]),
new TwigFilter('upper', '\Twig\Extension\Core\Functions\twig_upper_filter', ['needs_environment' => true]),
new TwigFilter('lower', '\Twig\Extension\Core\Functions\twig_lower_filter', ['needs_environment' => true]),
new TwigFilter('striptags', '\Twig\Extension\Core\Functions\twig_striptags'),
new TwigFilter('trim', '\Twig\Extension\Core\Functions\twig_trim_filter'),
new TwigFilter('nl2br', '\Twig\Extension\Core\Functions\twig_nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]),
new TwigFilter('spaceless', '\Twig\Extension\Core\Functions\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', ['needs_environment' => true]),
new TwigFilter('merge', 'twig_array_merge'),
new TwigFilter('batch', 'twig_array_batch'),
new TwigFilter('column', 'twig_array_column'),
new TwigFilter('filter', 'twig_array_filter', ['needs_environment' => true]),
new TwigFilter('map', 'twig_array_map', ['needs_environment' => true]),
new TwigFilter('reduce', 'twig_array_reduce', ['needs_environment' => true]),
new TwigFilter('join', '\Twig\Extension\Core\Functions\twig_join_filter'),
new TwigFilter('split', '\Twig\Extension\Core\Functions\twig_split_filter', ['needs_environment' => true]),
new TwigFilter('sort', '\Twig\Extension\Core\Functions\twig_sort_filter', ['needs_environment' => true]),
new TwigFilter('merge', '\Twig\Extension\Core\Functions\twig_array_merge'),
new TwigFilter('batch', '\Twig\Extension\Core\Functions\twig_array_batch'),
new TwigFilter('column', '\Twig\Extension\Core\Functions\twig_array_column'),
new TwigFilter('filter', '\Twig\Extension\Core\Functions\twig_array_filter', ['needs_environment' => true]),
new TwigFilter('map', '\Twig\Extension\Core\Functions\twig_array_map', ['needs_environment' => true]),
new TwigFilter('reduce', '\Twig\Extension\Core\Functions\twig_array_reduce', ['needs_environment' => true]),

// string/array filters
new TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]),
new TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]),
new TwigFilter('slice', 'twig_slice', ['needs_environment' => true]),
new TwigFilter('first', 'twig_first', ['needs_environment' => true]),
new TwigFilter('last', 'twig_last', ['needs_environment' => true]),
new TwigFilter('reverse', '\Twig\Extension\Core\Functions\twig_reverse_filter', ['needs_environment' => true]),
new TwigFilter('length', '\Twig\Extension\Core\Functions\twig_length_filter', ['needs_environment' => true]),
new TwigFilter('slice', '\Twig\Extension\Core\Functions\twig_slice', ['needs_environment' => true]),
new TwigFilter('first', '\Twig\Extension\Core\Functions\twig_first', ['needs_environment' => true]),
new TwigFilter('last', '\Twig\Extension\Core\Functions\twig_last', ['needs_environment' => true]),

// iteration and runtime
new TwigFilter('default', '_twig_default_filter', ['node_class' => DefaultFilter::class]),
new TwigFilter('keys', 'twig_get_array_keys_filter'),
new TwigFilter('default', '\Twig\Extension\Core\Functions\_twig_default_filter', ['node_class' => DefaultFilter::class]),
new TwigFilter('keys', '\Twig\Extension\Core\Functions\twig_get_array_keys_filter'),
];
}

Expand All @@ -228,12 +228,12 @@ public function getFunctions(): array
new TwigFunction('max', 'max'),
new TwigFunction('min', 'min'),
new TwigFunction('range', 'range'),
new TwigFunction('constant', 'twig_constant'),
new TwigFunction('cycle', 'twig_cycle'),
new TwigFunction('random', 'twig_random', ['needs_environment' => true]),
new TwigFunction('date', 'twig_date_converter', ['needs_environment' => true]),
new TwigFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]),
new TwigFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]),
new TwigFunction('constant', '\Twig\Extension\Core\Functions\twig_constant'),
new TwigFunction('cycle', '\Twig\Extension\Core\Functions\twig_cycle'),
new TwigFunction('random', '\Twig\Extension\Core\Functions\twig_random', ['needs_environment' => true]),
new TwigFunction('date', '\Twig\Extension\Core\Functions\twig_date_converter', ['needs_environment' => true]),
new TwigFunction('include', '\Twig\Extension\Core\Functions\twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]),
new TwigFunction('source', '\Twig\Extension\Core\Functions\twig_source', ['needs_environment' => true, 'is_safe' => ['all']]),
];
}

Expand All @@ -248,8 +248,8 @@ public function getTests(): array
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', 'twig_test_empty'),
new TwigTest('iterable', 'twig_test_iterable'),
new TwigTest('empty', '\Twig\Extension\Core\Functions\twig_test_empty'),
new TwigTest('iterable', '\Twig\Extension\Core\Functions\twig_test_iterable'),
];
}

Expand Down Expand Up @@ -302,7 +302,7 @@ public function getOperators(): array
}
}

namespace {
namespace Twig\Extension\Core\Functions {
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/DebugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public function getFunctions(): array
;

return [
new TwigFunction('dump', 'twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true, 'is_variadic' => true]),
new TwigFunction('dump', '\Twig\Extension\Debug\Functions\twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true, 'is_variadic' => true]),
];
}
}
}

namespace {
namespace Twig\Extension\Debug\Functions {
use Twig\Environment;
use Twig\Template;
use Twig\TemplateWrapper;
Expand Down
12 changes: 7 additions & 5 deletions src/Extension/EscaperExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function getNodeVisitors(): array
public function getFilters(): array
{
return [
new TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
new TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
new TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]),
new TwigFilter('escape', '\Twig\Extension\Escaper\Functions\twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => '\Twig\Extension\Escaper\Functions\twig_escape_filter_is_safe']),
new TwigFilter('e', '\Twig\Extension\Escaper\Functions\twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => '\Twig\Extension\Escaper\Functions\twig_escape_filter_is_safe']),
new TwigFilter('raw', '\Twig\Extension\Escaper\Functions\twig_raw_filter', ['is_safe' => ['all']]),
];
}

Expand Down Expand Up @@ -135,15 +135,17 @@ public function addSafeClass(string $class, array $strategies)
}
}

namespace {
namespace Twig\Extension\Escaper\Functions {
use Twig\Environment;
use Twig\Error\RuntimeError;
use Twig\Extension\EscaperExtension;
use Twig\Markup;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Node;

/**
use function Twig\Extension\Core\Functions\twig_convert_encoding;

/**
* Marks a variable as being safe.
*
* @param string $string A PHP variable
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/StringLoaderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ final class StringLoaderExtension extends AbstractExtension
public function getFunctions(): array
{
return [
new TwigFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]),
new TwigFunction('template_from_string', '\Twig\Extension\StringLoader\Functions\twig_template_from_string', ['needs_environment' => true]),
];
}
}
}

namespace {
namespace Twig\Extension\StringLoader\Functions {
use Twig\Environment;
use Twig\TemplateWrapper;

Expand Down
2 changes: 1 addition & 1 deletion src/Loader/FilesystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FilesystemLoader implements LoaderInterface
* @param string|array $paths A path or an array of paths where to look for templates
* @param string|null $rootPath The root path common to all relative paths (null for getcwd())
*/
public function __construct($paths = [], string $rootPath = null)
public function __construct($paths = [], ?string $rootPath = null)
{
$this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR;
if (null !== $rootPath && false !== ($realPath = realpath($rootPath))) {
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Binary/EqualBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function compile(Compiler $compiler): void
}

$compiler
->raw('(0 === twig_compare(')
->raw('(0 === \Twig\Extension\Core\Functions\twig_compare(')
->subcompile($this->getNode('left'))
->raw(', ')
->subcompile($this->getNode('right'))
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Binary/GreaterBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function compile(Compiler $compiler): void
}

$compiler
->raw('(1 === twig_compare(')
->raw('(1 === \Twig\Extension\Core\Functions\twig_compare(')
->subcompile($this->getNode('left'))
->raw(', ')
->subcompile($this->getNode('right'))
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Binary/GreaterEqualBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function compile(Compiler $compiler): void
}

$compiler
->raw('(0 <= twig_compare(')
->raw('(0 <= \Twig\Extension\Core\Functions\twig_compare(')
->subcompile($this->getNode('left'))
->raw(', ')
->subcompile($this->getNode('right'))
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Binary/InBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class InBinary extends AbstractBinary
public function compile(Compiler $compiler): void
{
$compiler
->raw('twig_in_filter(')
->raw('\Twig\Extension\Core\Functions\twig_in_filter(')
->subcompile($this->getNode('left'))
->raw(', ')
->subcompile($this->getNode('right'))
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Binary/LessBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function compile(Compiler $compiler): void
}

$compiler
->raw('(-1 === twig_compare(')
->raw('(-1 === \Twig\Extension\Core\Functions\twig_compare(')
->subcompile($this->getNode('left'))
->raw(', ')
->subcompile($this->getNode('right'))
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Binary/LessEqualBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function compile(Compiler $compiler): void
}

$compiler
->raw('(0 >= twig_compare(')
->raw('(0 >= \Twig\Extension\Core\Functions\twig_compare(')
->subcompile($this->getNode('left'))
->raw(', ')
->subcompile($this->getNode('right'))
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Binary/NotEqualBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function compile(Compiler $compiler): void
}

$compiler
->raw('(0 !== twig_compare(')
->raw('(0 !== \Twig\Extension\Core\Functions\twig_compare(')
->subcompile($this->getNode('left'))
->raw(', ')
->subcompile($this->getNode('right'))
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Binary/NotInBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NotInBinary extends AbstractBinary
public function compile(Compiler $compiler): void
{
$compiler
->raw('!twig_in_filter(')
->raw('!\Twig\Extension\Core\Functions\twig_in_filter(')
->subcompile($this->getNode('left'))
->raw(', ')
->subcompile($this->getNode('right'))
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/FunctionExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function compile(Compiler $compiler)
$this->setAttribute('arguments', $function->getArguments());
$callable = $function->getCallable();
if ('constant' === $name && $this->getAttribute('is_defined_test')) {
$callable = 'twig_constant_is_defined';
$callable = '\Twig\Extension\Core\Functions\twig_constant_is_defined';
}
$this->setAttribute('callable', $callable);
$this->setAttribute('is_variadic', $function->isVariadic());
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/GetAttrExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function compile(Compiler $compiler): void
return;
}

$compiler->raw('twig_get_attribute($this->env, $this->source, ');
$compiler->raw('\Twig\Extension\Core\Functions\twig_get_attribute($this->env, $this->source, ');

if ($this->getAttribute('ignore_strict_check')) {
$this->getNode('node')->setAttribute('ignore_strict_check', true);
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/MethodCallExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function compile(Compiler $compiler): void
}

$compiler
->raw('twig_call_macro($macros[')
->raw('\Twig\Extension\Core\Functions\twig_call_macro($macros[')
->repr($this->getNode('node')->getAttribute('name'))
->raw('], ')
->repr($this->getAttribute('method'))
Expand Down
2 changes: 1 addition & 1 deletion src/Node/ForNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function compile(Compiler $compiler): void
$compiler
->addDebugInfo($this)
->write("\$context['_parent'] = \$context;\n")
->write("\$context['_seq'] = twig_ensure_traversable(")
->write("\$context['_seq'] = \Twig\Extension\Core\Functions\\twig_ensure_traversable(")
->subcompile($this->getNode('seq'))
->raw(");\n")
;
Expand Down
4 changes: 2 additions & 2 deletions src/Node/IncludeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ protected function addTemplateArguments(Compiler $compiler)
$compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]');
} elseif (false === $this->getAttribute('only')) {
$compiler
->raw('twig_array_merge($context, ')
->raw('\Twig\Extension\Core\Functions\twig_array_merge($context, ')
->subcompile($this->getNode('variables'))
->raw(')')
;
} else {
$compiler->raw('twig_to_array(');
$compiler->raw('\Twig\Extension\Core\Functions\twig_to_array(');
$compiler->subcompile($this->getNode('variables'));
$compiler->raw(')');
}
Expand Down
Loading
Loading