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

Commitfb6549d

Browse files
committed
handle error results of DateTime::modify()
Depending on the version of PHP the modify() method will either throw anexception or issue a warning.
1 parent2c7c4ba commitfb6549d

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