Skip to content

Commit ed71ee6

Browse files
committed
[Serializer] Deprecate XML configuration format
1 parent 6df1a43 commit ed71ee6

File tree

5 files changed

+97
-11
lines changed

5 files changed

+97
-11
lines changed

UPGRADE-7.4.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ Security
5151
* Deprecate `AbstractListener::__invoke`
5252
* Deprecate `LazyFirewallContext::__invoke()`
5353

54+
Serializer
55+
----------
56+
57+
* Deprecate XML configuration format, use YAML or attributes instead
58+
5459
Translation
5560
-----------
5661

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/SerializerCacheWarmerTest.php

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer;
1313

1414
use PHPUnit\Framework\Attributes\DataProvider;
15+
use PHPUnit\Framework\Attributes\Group;
16+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1517
use Symfony\Bundle\FrameworkBundle\CacheWarmer\SerializerCacheWarmer;
1618
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1719
use Symfony\Component\Cache\Adapter\NullAdapter;
@@ -39,8 +41,26 @@ private function getArrayPool(string $file): PhpArrayAdapter
3941
return $this->arrayPool = new PhpArrayAdapter($file, new NullAdapter());
4042
}
4143

42-
#[DataProvider('loaderProvider')]
43-
public function testWarmUp(array $loaders)
44+
#[DataProvider('yamlLoaderProvider')]
45+
public function testYamlWarmUp(array $loaders)
46+
{
47+
$file = sys_get_temp_dir().'/cache-serializer.php';
48+
@unlink($file);
49+
50+
$warmer = new SerializerCacheWarmer($loaders, $file);
51+
$warmer->warmUp(\dirname($file), \dirname($file));
52+
53+
$this->assertFileExists($file);
54+
55+
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
56+
57+
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
58+
}
59+
60+
#[IgnoreDeprecations]
61+
#[Group('legacy')]
62+
#[DataProvider('xmlLoaderProvider')]
63+
public function testXmlWarmUp(array $loaders)
4464
{
4565
$file = sys_get_temp_dir().'/cache-serializer.php';
4666
@unlink($file);
@@ -53,11 +73,31 @@ public function testWarmUp(array $loaders)
5373
$arrayPool = $this->getArrayPool($file);
5474

5575
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
76+
}
77+
78+
#[DataProvider('yamlLoaderProvider')]
79+
public function testYamlWarmUpAbsoluteFilePath(array $loaders)
80+
{
81+
$file = sys_get_temp_dir().'/0/cache-serializer.php';
82+
@unlink($file);
83+
84+
$cacheDir = sys_get_temp_dir().'/1';
85+
86+
$warmer = new SerializerCacheWarmer($loaders, $file);
87+
$warmer->warmUp($cacheDir, $cacheDir);
88+
89+
$this->assertFileExists($file);
90+
$this->assertFileDoesNotExist($cacheDir.'/cache-serializer.php');
91+
92+
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
93+
5694
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
5795
}
5896

59-
#[DataProvider('loaderProvider')]
60-
public function testWarmUpAbsoluteFilePath(array $loaders)
97+
#[IgnoreDeprecations]
98+
#[Group('legacy')]
99+
#[DataProvider('xmlLoaderProvider')]
100+
public function testXmlWarmUpAbsoluteFilePath(array $loaders)
61101
{
62102
$file = sys_get_temp_dir().'/0/cache-serializer.php';
63103
@unlink($file);
@@ -73,11 +113,10 @@ public function testWarmUpAbsoluteFilePath(array $loaders)
73113
$arrayPool = $this->getArrayPool($file);
74114

75115
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
76-
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
77116
}
78117

79-
#[DataProvider('loaderProvider')]
80-
public function testWarmUpWithoutBuildDir(array $loaders)
118+
#[DataProvider('yamlLoaderProvider')]
119+
public function testYamlWarmUpWithoutBuildDir(array $loaders)
81120
{
82121
$file = sys_get_temp_dir().'/cache-serializer.php';
83122
@unlink($file);
@@ -89,30 +128,63 @@ public function testWarmUpWithoutBuildDir(array $loaders)
89128

90129
$arrayPool = $this->getArrayPool($file);
91130

92-
$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
93131
$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
94132
}
95133

96-
public static function loaderProvider(): array
134+
#[IgnoreDeprecations]
135+
#[Group('legacy')]
136+
#[DataProvider('xmlLoaderProvider')]
137+
public function testXmlWarmUpWithoutBuildDir(array $loaders)
138+
{
139+
$file = sys_get_temp_dir().'/cache-serializer.php';
140+
@unlink($file);
141+
142+
$warmer = new SerializerCacheWarmer($loaders, $file);
143+
$warmer->warmUp(\dirname($file));
144+
145+
$this->assertFileDoesNotExist($file);
146+
147+
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
148+
149+
$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
150+
}
151+
152+
public static function yamlLoaderProvider(): array
97153
{
98154
return [
99155
[
100156
[
101157
new LoaderChain([
102-
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
103158
new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
104159
]),
105160
],
106161
],
107162
[
108163
[
109-
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
110164
new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
111165
],
112166
],
113167
];
114168
}
115169

170+
public static function xmlLoaderProvider(): array
171+
{
172+
return [
173+
[
174+
[
175+
new LoaderChain([
176+
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
177+
]),
178+
],
179+
],
180+
[
181+
[
182+
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
183+
],
184+
],
185+
];
186+
}
187+
116188
public function testWarmUpWithoutLoader()
117189
{
118190
$file = sys_get_temp_dir().'/cache-serializer-without-loader.php';

src/Symfony/Component/Serializer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add `CDATA_WRAPPING_NAME_PATTERN` support to `XmlEncoder`
88
* Add support for `can*()` methods to `AttributeLoader`
9+
* Deprecate XML configuration format, use YAML or attributes instead
910

1011
7.3
1112
---

src/Symfony/Component/Serializer/Mapping/Loader/XmlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* Loads XML mapping files.
2424
*
2525
* @author Kévin Dunglas <dunglas@gmail.com>
26+
*
27+
* @deprecated since Symfony 7.4, use another loader instead
2628
*/
2729
class XmlFileLoader extends FileLoader
2830
{
@@ -42,6 +44,8 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
4244
$attributesMetadata = $classMetadata->getAttributesMetadata();
4345

4446
if (isset($this->classes[$classMetadata->getName()])) {
47+
trigger_deprecation('symfony/serializer', '7.4', 'XML configuration format is deprecated, use YAML or attributes instead.');
48+
4549
$xml = $this->classes[$classMetadata->getName()];
4650

4751
foreach ($xml->attribute as $attribute) {

src/Symfony/Component/Serializer/Tests/Mapping/Loader/XmlFileLoaderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Serializer\Tests\Mapping\Loader;
1313

14+
use PHPUnit\Framework\Attributes\Group;
15+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1416
use PHPUnit\Framework\TestCase;
1517
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
1618
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
@@ -32,6 +34,8 @@
3234
/**
3335
* @author Kévin Dunglas <dunglas@gmail.com>
3436
*/
37+
#[IgnoreDeprecations]
38+
#[Group('legacy')]
3539
class XmlFileLoaderTest extends TestCase
3640
{
3741
use ContextMappingTestTrait;

0 commit comments

Comments
 (0)