Skip to content

Commit 068726c

Browse files
Merge branch '6.4' into 7.2
* 6.4: Improve docblock on compile() [VarDumper] Fix dumping LazyObjectState when using VarExporter v8 Allow NumberToLocalizedStringTransformer empty values [Intl] Ensure data consistency between alpha and numeric codes [Intl] Add missing currency (NOK) localization (en_NO)
2 parents 16efe96 + ac67b6a commit 068726c

File tree

10 files changed

+55
-125
lines changed

10 files changed

+55
-125
lines changed

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,11 @@ public function parameterCannotBeEmpty(string $name, string $message): void
791791
* * The parameter bag is frozen;
792792
* * Extension loading is disabled.
793793
*
794-
* @param bool $resolveEnvPlaceholders Whether %env()% parameters should be resolved using the current
795-
* env vars or be replaced by uniquely identifiable placeholders.
796-
* Set to "true" when you want to use the current ContainerBuilder
797-
* directly, keep to "false" when the container is dumped instead.
794+
* @param bool $resolveEnvPlaceholders Whether %env()% parameters should be resolved at build time using
795+
* the current env var values (true), or be resolved at runtime based
796+
* on the environment (false). In general, this should be set to "true"
797+
* when you want to use the current ContainerBuilder directly, and to
798+
* "false" when the container is dumped instead.
798799
*/
799800
public function compile(bool $resolveEnvPlaceholders = false): void
800801
{

src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public function __construct(
3939
/**
4040
* Transforms a normalized format into a localized money string.
4141
*
42-
* @param int|float|null $value Normalized number
42+
* @param int|float|string|null $value Normalized number
4343
*
4444
* @throws TransformationFailedException if the given value is not numeric or
4545
* if the value cannot be transformed
4646
*/
4747
public function transform(mixed $value): string
4848
{
49-
if (null !== $value && 1 !== $this->divisor) {
49+
if (null !== $value && '' !== $value && 1 !== $this->divisor) {
5050
if (!is_numeric($value)) {
5151
throw new TransformationFailedException('Expected a numeric.');
5252
}

src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function __construct(
4141
/**
4242
* Transforms a number type into localized number.
4343
*
44-
* @param int|float|null $value Number value
44+
* @param int|float|string|null $value Number value
4545
*
4646
* @throws TransformationFailedException if the given value is not numeric
4747
* or if the value cannot be transformed
4848
*/
4949
public function transform(mixed $value): string
5050
{
51-
if (null === $value) {
51+
if (null === $value || '' === $value) {
5252
return '';
5353
}
5454

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ public function testTransformExpectsNumeric()
5454
$transformer->transform('abcd');
5555
}
5656

57+
public function testTransformEmptyString()
58+
{
59+
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
60+
61+
$this->assertSame('', $transformer->transform(''));
62+
}
63+
5764
public function testTransformEmpty()
5865
{
5966
$transformer = new MoneyToLocalizedStringTransformer();

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static function provideTransformations()
4949
{
5050
return [
5151
[null, '', 'de_AT'],
52+
['', '', 'de_AT'],
5253
[1, '1', 'de_AT'],
5354
[1.5, '1,5', 'de_AT'],
5455
[1234.5, '1234,5', 'de_AT'],

src/Symfony/Component/Intl/Data/Generator/RegionDataGenerator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, strin
160160
$alpha3ToAlpha2 = array_flip($alpha2ToAlpha3);
161161
asort($alpha3ToAlpha2);
162162

163-
$alpha2ToNumeric = $this->generateAlpha2ToNumericMapping($metadataBundle);
163+
$alpha2ToNumeric = $this->generateAlpha2ToNumericMapping(array_flip($this->regionCodes), $metadataBundle);
164164
$numericToAlpha2 = [];
165165
foreach ($alpha2ToNumeric as $alpha2 => $numeric) {
166166
// Add underscore prefix to force keys with leading zeros to remain as string keys.
@@ -231,7 +231,7 @@ private function generateAlpha2ToAlpha3Mapping(array $countries, ArrayAccessible
231231
return $alpha2ToAlpha3;
232232
}
233233

234-
private function generateAlpha2ToNumericMapping(ArrayAccessibleResourceBundle $metadataBundle): array
234+
private function generateAlpha2ToNumericMapping(array $countries, ArrayAccessibleResourceBundle $metadataBundle): array
235235
{
236236
$aliases = iterator_to_array($metadataBundle['alias']['territory']);
237237

@@ -250,6 +250,10 @@ private function generateAlpha2ToNumericMapping(ArrayAccessibleResourceBundle $m
250250
continue;
251251
}
252252

253+
if (!isset($countries[$data['replacement']])) {
254+
continue;
255+
}
256+
253257
if ('deprecated' === $data['reason']) {
254258
continue;
255259
}

src/Symfony/Component/Intl/Resources/data/currencies/en_NO.php

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/Intl/Resources/data/regions/meta.php

Lines changed: 0 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/Intl/Tests/CountriesTest.php

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@ class CountriesTest extends ResourceBundleTestCase
527527
];
528528

529529
private const ALPHA2_TO_NUMERIC = [
530-
'AA' => '958',
531530
'AD' => '020',
532531
'AE' => '784',
533532
'AF' => '004',
@@ -715,18 +714,6 @@ class CountriesTest extends ResourceBundleTestCase
715714
'PW' => '585',
716715
'PY' => '600',
717716
'QA' => '634',
718-
'QM' => '959',
719-
'QN' => '960',
720-
'QP' => '962',
721-
'QQ' => '963',
722-
'QR' => '964',
723-
'QS' => '965',
724-
'QT' => '966',
725-
'QV' => '968',
726-
'QW' => '969',
727-
'QX' => '970',
728-
'QY' => '971',
729-
'QZ' => '972',
730717
'RE' => '638',
731718
'RO' => '642',
732719
'RS' => '688',
@@ -784,36 +771,26 @@ class CountriesTest extends ResourceBundleTestCase
784771
'VU' => '548',
785772
'WF' => '876',
786773
'WS' => '882',
787-
'XC' => '975',
788-
'XD' => '976',
789-
'XE' => '977',
790-
'XF' => '978',
791-
'XG' => '979',
792-
'XH' => '980',
793-
'XI' => '981',
794-
'XJ' => '982',
795-
'XL' => '984',
796-
'XM' => '985',
797-
'XN' => '986',
798-
'XO' => '987',
799-
'XP' => '988',
800-
'XQ' => '989',
801-
'XR' => '990',
802-
'XS' => '991',
803-
'XT' => '992',
804-
'XU' => '993',
805-
'XV' => '994',
806-
'XW' => '995',
807-
'XX' => '996',
808-
'XY' => '997',
809-
'XZ' => '998',
810774
'YE' => '887',
811775
'YT' => '175',
812776
'ZA' => '710',
813777
'ZM' => '894',
814778
'ZW' => '716',
815779
];
816780

781+
public function testAllGettersGenerateTheSameDataSetCount()
782+
{
783+
$alpha2Count = count(Countries::getCountryCodes());
784+
$alpha3Count = count(Countries::getAlpha3Codes());
785+
$numericCodesCount = count(Countries::getNumericCodes());
786+
$namesCount = count(Countries::getNames());
787+
788+
// we base all on Name count since it is the first to be generated
789+
$this->assertEquals($namesCount, $alpha2Count, 'Alpha 2 count does not match');
790+
$this->assertEquals($namesCount, $alpha3Count, 'Alpha 3 count does not match');
791+
$this->assertEquals($namesCount, $numericCodesCount, 'Numeric codes count does not match');
792+
}
793+
817794
public function testGetCountryCodes()
818795
{
819796
$this->assertSame(self::COUNTRIES, Countries::getCountryCodes());
@@ -992,7 +969,7 @@ public function testGetNumericCode()
992969
public function testNumericCodeExists()
993970
{
994971
$this->assertTrue(Countries::numericCodeExists('250'));
995-
$this->assertTrue(Countries::numericCodeExists('982'));
972+
$this->assertTrue(Countries::numericCodeExists('008'));
996973
$this->assertTrue(Countries::numericCodeExists('716'));
997974
$this->assertTrue(Countries::numericCodeExists('036'));
998975
$this->assertFalse(Countries::numericCodeExists('667'));

src/Symfony/Component/VarDumper/Caster/SymfonyCaster.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ public static function castLazyObjectState($state, array $a, Stub $stub, bool $i
7878

7979
$instance = $a['realInstance'] ?? null;
8080

81-
$a = ['status' => new ConstStub(match ($a['status']) {
82-
LazyObjectState::STATUS_INITIALIZED_FULL => 'INITIALIZED_FULL',
83-
LazyObjectState::STATUS_INITIALIZED_PARTIAL => 'INITIALIZED_PARTIAL',
84-
LazyObjectState::STATUS_UNINITIALIZED_FULL => 'UNINITIALIZED_FULL',
85-
LazyObjectState::STATUS_UNINITIALIZED_PARTIAL => 'UNINITIALIZED_PARTIAL',
86-
}, $a['status'])];
81+
if (isset($a['status'])) { // forward-compat with Symfony 8
82+
$a = ['status' => new ConstStub(match ($a['status']) {
83+
LazyObjectState::STATUS_INITIALIZED_FULL => 'INITIALIZED_FULL',
84+
LazyObjectState::STATUS_INITIALIZED_PARTIAL => 'INITIALIZED_PARTIAL',
85+
LazyObjectState::STATUS_UNINITIALIZED_FULL => 'UNINITIALIZED_FULL',
86+
LazyObjectState::STATUS_UNINITIALIZED_PARTIAL => 'UNINITIALIZED_PARTIAL',
87+
}, $a['status'])];
88+
}
8789

8890
if ($instance) {
8991
$a['realInstance'] = $instance;

0 commit comments

Comments
 (0)