From b46e93c7257fb01b7c77768210997b1e00643b91 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 15 Feb 2024 12:09:06 +0100 Subject: [PATCH 1/3] Minor fixes --- src/Node/ModuleNode.php | 4 ++-- src/Profiler/Node/EnterProfileNode.php | 2 ++ src/Profiler/Node/LeaveProfileNode.php | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Node/ModuleNode.php b/src/Node/ModuleNode.php index 6a76ed1ea..10e94f681 100644 --- a/src/Node/ModuleNode.php +++ b/src/Node/ModuleNode.php @@ -153,14 +153,14 @@ final class ModuleNode extends Node ->write("use Twig\Sandbox\SecurityNotAllowedFilterError;\n") ->write("use Twig\Sandbox\SecurityNotAllowedFunctionError;\n") ->write("use Twig\Source;\n") - ->write(sprintf("use Twig\%s;\n\n", 'Template')) + ->write("use Twig\Template;\n\n") ; } $compiler // if the template name contains */, add a blank to avoid a PHP parse error ->write('/* '.str_replace('*/', '* /', $this->getSourceContext()->getName())." */\n") ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getSourceContext()->getName(), $this->getAttribute('index'))) - ->raw(sprintf(" extends %s\n", 'Template')) + ->raw(" extends Template\n") ->write("{\n") ->indent() ->write("private \$source;\n") diff --git a/src/Profiler/Node/EnterProfileNode.php b/src/Profiler/Node/EnterProfileNode.php index 1494baf44..7b71f8b30 100644 --- a/src/Profiler/Node/EnterProfileNode.php +++ b/src/Profiler/Node/EnterProfileNode.php @@ -11,6 +11,7 @@ namespace Twig\Profiler\Node; +use Twig\Attribute\YieldReady; use Twig\Compiler; use Twig\Node\Node; @@ -19,6 +20,7 @@ use Twig\Node\Node; * * @author Fabien Potencier */ +#[YieldReady] class EnterProfileNode extends Node { public function __construct(string $extensionName, string $type, string $name, string $varName) diff --git a/src/Profiler/Node/LeaveProfileNode.php b/src/Profiler/Node/LeaveProfileNode.php index 94cebbaa8..7e9ef9b64 100644 --- a/src/Profiler/Node/LeaveProfileNode.php +++ b/src/Profiler/Node/LeaveProfileNode.php @@ -11,6 +11,7 @@ namespace Twig\Profiler\Node; +use Twig\Attribute\YieldReady; use Twig\Compiler; use Twig\Node\Node; @@ -19,6 +20,7 @@ use Twig\Node\Node; * * @author Fabien Potencier */ +#[YieldReady] class LeaveProfileNode extends Node { public function __construct(string $varName) From 2d262bc35f7d4393b7df05b9a4ae84cb7ad6ad99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Andr=C3=A9?= Date: Wed, 3 Apr 2024 08:23:11 +0200 Subject: [PATCH 2/3] Fix param name in docblock (minor) --- src/Environment.php | 8 ++++---- src/Extension/CoreExtension.php | 20 ++++++++++---------- src/Extension/StringLoaderExtension.php | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Environment.php b/src/Environment.php index c6ba8b2c0..ec9c39da5 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -337,8 +337,8 @@ class Environment * This method is for internal use only and should never be called * directly. * - * @param string $name The template name - * @param int $index The index if it is an embedded template + * @param string $name The template name + * @param int|null $index The index if it is an embedded template * * @throws LoaderError When the template cannot be found * @throws RuntimeError When a previously generated cache is corrupted @@ -395,8 +395,8 @@ class Environment * * This method should not be used as a generic way to load templates. * - * @param string $template The template source - * @param string $name An optional name of the template to be used in error messages + * @param string $template The template source + * @param string|null $name An optional name of the template to be used in error messages * * @throws LoaderError When the template cannot be found * @throws SyntaxError When an error occurred during compilation diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index b11e2e5e2..dbc5f6144 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -89,8 +89,8 @@ final class CoreExtension extends AbstractExtension /** * Sets the default format to be used by the date filter. * - * @param string $format The default date format string - * @param string $dateIntervalFormat The default date interval format string + * @param string|null $format The default date format string + * @param string|null $dateIntervalFormat The default date interval format string */ public function setDateFormat($format = null, $dateIntervalFormat = null) { @@ -581,10 +581,10 @@ final class CoreExtension extends AbstractExtension * 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 - * @param int $decimal the number of decimal points to display - * @param string $decimalPoint the character(s) to use for the decimal point - * @param string $thousandSep the character(s) to use for the thousands separator + * @param mixed $number A float/int/string of the number to format + * @param int|null $decimal the number of decimal points to display + * @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 * @@ -787,7 +787,7 @@ final class CoreExtension extends AbstractExtension * * @param string|null $value A string * @param string $delimiter The delimiter - * @param int $limit The limit + * @param int|null $limit The limit * * @return array The split string as an array * @@ -1218,7 +1218,7 @@ final class CoreExtension extends AbstractExtension * Strips HTML and PHP tags from a string. * * @param string|null $string - * @param string[]|string|null $string + * @param string[]|string|null $allowable_tags * * @return string * @@ -1729,8 +1729,8 @@ final class CoreExtension extends AbstractExtension * * * @param array|\Traversable $array An array - * @param mixed $name The column name - * @param mixed $index The column to use as the index/keys for the returned array + * @param int|string $name The column name + * @param int|string|null $index The column to use as the index/keys for the returned array * * @return array The array of values * diff --git a/src/Extension/StringLoaderExtension.php b/src/Extension/StringLoaderExtension.php index 0945678a8..12f5c30aa 100644 --- a/src/Extension/StringLoaderExtension.php +++ b/src/Extension/StringLoaderExtension.php @@ -29,8 +29,8 @@ final class StringLoaderExtension extends AbstractExtension * * {{ include(template_from_string("Hello {{ name }}")) }} * - * @param string $template A template as a string or object implementing __toString() - * @param string $name An optional name of the template to be used in error messages + * @param string $template A template as a string or object implementing __toString() + * @param string|null $name An optional name of the template to be used in error messages * * @internal */ From 7e8f5eb1a555833768b6ec96a6ab1133478ff3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alfaiate?= Date: Mon, 1 Apr 2024 14:39:28 +0700 Subject: [PATCH 3/3] Fix exception when timezone is false --- extra/intl-extra/IntlExtension.php | 2 +- extra/intl-extra/Tests/IntlExtensionTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/extra/intl-extra/IntlExtension.php b/extra/intl-extra/IntlExtension.php index 0b33331f6..d932e7f7f 100644 --- a/extra/intl-extra/IntlExtension.php +++ b/extra/intl-extra/IntlExtension.php @@ -372,7 +372,7 @@ final class IntlExtension extends AbstractExtension $date = CoreExtension::dateConverter($env, $date, $timezone); $formatterTimezone = $timezone; - if (null === $formatterTimezone) { + if (null === $formatterTimezone || false === $formatterTimezone) { $formatterTimezone = $date->getTimezone(); } elseif (\is_string($formatterTimezone)) { $formatterTimezone = new \DateTimeZone($timezone); diff --git a/extra/intl-extra/Tests/IntlExtensionTest.php b/extra/intl-extra/Tests/IntlExtensionTest.php index 688a415f4..91aa9e84f 100644 --- a/extra/intl-extra/Tests/IntlExtensionTest.php +++ b/extra/intl-extra/Tests/IntlExtensionTest.php @@ -45,6 +45,20 @@ class IntlExtensionTest extends TestCase ); } + public function testFormatterWithoutProtoSkipTimezoneConverter() + { + $ext = new IntlExtension(); + $env = new Environment(new ArrayLoader()); + // EET is always +2 without changes for daylight saving time + // so it has a fixed difference to UTC + $env->getExtension(CoreExtension::class)->setTimezone('EET'); + + $this->assertStringStartsWith( + 'Feb 20, 2020, 1:37:00', + $ext->formatDateTime($env, new \DateTime('2020-02-20T13:37:00+00:00', new \DateTimeZone('UTC')), 'medium', 'medium', '', false) + ); + } + public function testFormatterProto() { $dateFormatterProto = new \IntlDateFormatter('fr', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, new \DateTimeZone('Europe/Paris'));