Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda4eb8b

Browse files
committed
bug#58791 [RateLimiter] handle error results of DateTime::modify() (xabbuh)
This PR was merged into the 5.4 branch.Discussion----------[RateLimiter] handle error results of DateTime::modify()| Q | A| ------------- | ---| Branch? | 5.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues || License | MITDepending on the version of PHP the `modify()` method will either throw an exception or issue a warning.Commits-------fb6549d handle error results of DateTime::modify()
2 parentsd77f5d9 +fb6549d commitda4eb8b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

‎src/Symfony/Component/RateLimiter/RateLimiterFactory.php‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,21 @@ public function create(?string $key = null): LimiterInterface
6868
protectedstaticfunctionconfigureOptions(OptionsResolver$options):void
6969
{
7070
$intervalNormalizer =staticfunction (Options$options,string$interval):\DateInterval {
71-
try {
72-
// Create DateTimeImmutable from unix timesatmp, so the default timezone is ignored and we don't need to
73-
// deal with quirks happening when modifying dates using a timezone with DST.
74-
$now = \DateTimeImmutable::createFromFormat('U',time());
71+
// Create DateTimeImmutable from unix timesatmp, so the default timezone is ignored and we don't need to
72+
// deal with quirks happening when modifying dates using a timezone with DST.
73+
$now = \DateTimeImmutable::createFromFormat('U',time());
7574

76-
return$now->diff($now->modify('+'.$interval));
77-
}catch (\Exception$e) {
78-
if (!preg_match('/Failed to parse time string \(\+([^)]+)\)/',$e->getMessage(),$m)) {
79-
throw$e;
80-
}
75+
try {
76+
$nowPlusInterval = @$now->modify('+' .$interval);
77+
}catch (\DateMalformedStringException$e) {
78+
thrownew \LogicException(\sprintf('Cannot parse interval "%s", please use a valid unit as described on https://www.php.net/datetime.formats.relative.',$interval),0,$e);
79+
}
8180

82-
thrownew \LogicException(sprintf('Cannot parse interval "%s", please use a valid unit as described on https://www.php.net/datetime.formats.relative.',$m[1]));
81+
if (!$nowPlusInterval) {
82+
thrownew \LogicException(\sprintf('Cannot parse interval "%s", please use a valid unit as described on https://www.php.net/datetime.formats.relative.',$interval));
8383
}
84+
85+
return$now->diff($nowPlusInterval);
8486
};
8587

8688
$options

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp