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

Commit52360c1

Browse files
[Form] fix passing null $pattern to IntlDateFormatter
1 parent40677a0 commit52360c1

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected function getIntlDateFormatter($ignoreTimezone = false)
172172
$calendar =$this->calendar;
173173
$pattern =$this->pattern;
174174

175-
$intlDateFormatter =new \IntlDateFormatter(\Locale::getDefault(),$dateFormat,$timeFormat,$timezone,$calendar,$pattern);
175+
$intlDateFormatter =new \IntlDateFormatter(\Locale::getDefault(),$dateFormat,$timeFormat,$timezone,$calendar,$pattern ??'');
176176

177177
// new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/66323
178178
if (!$intlDateFormatter) {

‎src/Symfony/Component/Form/Extension/Core/Type/DateType.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5151
$dateFormat =\is_int($options['format']) ?$options['format'] :self::DEFAULT_FORMAT;
5252
$timeFormat = \IntlDateFormatter::NONE;
5353
$calendar = \IntlDateFormatter::GREGORIAN;
54-
$pattern =\is_string($options['format']) ?$options['format'] :null;
54+
$pattern =\is_string($options['format']) ?$options['format'] :'';
5555

5656
if (!\in_array($dateFormat,self::$acceptedFormats,true)) {
5757
thrownewInvalidOptionsException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.');
5858
}
5959

6060
if ('single_text' ===$options['widget']) {
61-
if (null !==$pattern &&false ===strpos($pattern,'y') &&false ===strpos($pattern,'M') &&false ===strpos($pattern,'d')) {
61+
if ('' !==$pattern &&false ===strpos($pattern,'y') &&false ===strpos($pattern,'M') &&false ===strpos($pattern,'d')) {
6262
thrownewInvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" or "d". Its current value is "%s".',$pattern));
6363
}
6464

@@ -71,7 +71,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7171
$pattern
7272
));
7373
}else {
74-
if (null !==$pattern && (false ===strpos($pattern,'y') ||false ===strpos($pattern,'M') ||false ===strpos($pattern,'d'))) {
74+
if ('' !==$pattern && (false ===strpos($pattern,'y') ||false ===strpos($pattern,'M') ||false ===strpos($pattern,'d'))) {
7575
thrownewInvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".',$pattern));
7676
}
7777

‎src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public function __construct(?string $locale, ?int $datetype, ?int $timetype, $ti
145145
$this->datetype =null !==$datetype ?$datetype :self::FULL;
146146
$this->timetype =null !==$timetype ?$timetype :self::FULL;
147147

148+
if ('' === ($pattern ??'')) {
149+
$pattern =$this->getDefaultPattern();
150+
}
151+
148152
$this->setPattern($pattern);
149153
$this->setTimeZone($timezone);
150154
}
@@ -485,7 +489,7 @@ public function setLenient($lenient)
485489
/**
486490
* Set the formatter's pattern.
487491
*
488-
* @param string|null $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation
492+
* @param string $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation
489493
*
490494
* @return bool true on success or false on failure
491495
*
@@ -494,11 +498,7 @@ public function setLenient($lenient)
494498
*/
495499
publicfunctionsetPattern($pattern)
496500
{
497-
if (null ===$pattern) {
498-
$pattern =$this->getDefaultPattern();
499-
}
500-
501-
$this->pattern =$pattern;
501+
$this->pattern = (string)$pattern;
502502

503503
returntrue;
504504
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp