Skip to content

[Serializer] Deprecate XML configuration format #61287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-7.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ Security
* Deprecate `AbstractListener::__invoke`
* Deprecate `LazyFirewallContext::__invoke()`

Serializer
----------

* Deprecate XML configuration format, use YAML or attributes instead

Translation
-----------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\SerializerCacheWarmer;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\Cache\Adapter\NullAdapter;
Expand Down Expand Up @@ -39,8 +41,26 @@ private function getArrayPool(string $file): PhpArrayAdapter
return $this->arrayPool = new PhpArrayAdapter($file, new NullAdapter());
}

#[DataProvider('loaderProvider')]
public function testWarmUp(array $loaders)
#[DataProvider('yamlLoaderProvider')]
public function testYamlWarmUp(array $loaders)
{
$file = sys_get_temp_dir().'/cache-serializer.php';
@unlink($file);

$warmer = new SerializerCacheWarmer($loaders, $file);
$warmer->warmUp(\dirname($file), \dirname($file));

$this->assertFileExists($file);

$arrayPool = new PhpArrayAdapter($file, new NullAdapter());

$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
}

#[IgnoreDeprecations]
#[Group('legacy')]
#[DataProvider('xmlLoaderProvider')]
public function testXmlWarmUp(array $loaders)
{
$file = sys_get_temp_dir().'/cache-serializer.php';
@unlink($file);
Expand All @@ -53,11 +73,31 @@ public function testWarmUp(array $loaders)
$arrayPool = $this->getArrayPool($file);

$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
}

#[DataProvider('yamlLoaderProvider')]
public function testYamlWarmUpAbsoluteFilePath(array $loaders)
{
$file = sys_get_temp_dir().'/0/cache-serializer.php';
@unlink($file);

$cacheDir = sys_get_temp_dir().'/1';

$warmer = new SerializerCacheWarmer($loaders, $file);
$warmer->warmUp($cacheDir, $cacheDir);

$this->assertFileExists($file);
$this->assertFileDoesNotExist($cacheDir.'/cache-serializer.php');

$arrayPool = new PhpArrayAdapter($file, new NullAdapter());

$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
}

#[DataProvider('loaderProvider')]
public function testWarmUpAbsoluteFilePath(array $loaders)
#[IgnoreDeprecations]
#[Group('legacy')]
#[DataProvider('xmlLoaderProvider')]
public function testXmlWarmUpAbsoluteFilePath(array $loaders)
{
$file = sys_get_temp_dir().'/0/cache-serializer.php';
@unlink($file);
Expand All @@ -73,11 +113,10 @@ public function testWarmUpAbsoluteFilePath(array $loaders)
$arrayPool = $this->getArrayPool($file);

$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
}

#[DataProvider('loaderProvider')]
public function testWarmUpWithoutBuildDir(array $loaders)
#[DataProvider('yamlLoaderProvider')]
public function testYamlWarmUpWithoutBuildDir(array $loaders)
{
$file = sys_get_temp_dir().'/cache-serializer.php';
@unlink($file);
Expand All @@ -89,30 +128,63 @@ public function testWarmUpWithoutBuildDir(array $loaders)

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

$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
}

public static function loaderProvider(): array
#[IgnoreDeprecations]
#[Group('legacy')]
#[DataProvider('xmlLoaderProvider')]
public function testXmlWarmUpWithoutBuildDir(array $loaders)
{
$file = sys_get_temp_dir().'/cache-serializer.php';
@unlink($file);

$warmer = new SerializerCacheWarmer($loaders, $file);
$warmer->warmUp(\dirname($file));

$this->assertFileDoesNotExist($file);

$arrayPool = new PhpArrayAdapter($file, new NullAdapter());

$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
}

public static function yamlLoaderProvider(): array
{
return [
[
[
new LoaderChain([
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
]),
],
],
[
[
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
],
],
];
}

public static function xmlLoaderProvider(): array
{
return [
[
[
new LoaderChain([
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
]),
],
],
[
[
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
],
],
];
}

public function testWarmUpWithoutLoader()
{
$file = sys_get_temp_dir().'/cache-serializer-without-loader.php';
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Serializer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

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

7.3
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* Loads XML mapping files.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*
* @deprecated since Symfony 7.4, use another loader instead
*/
class XmlFileLoader extends FileLoader
{
Expand All @@ -42,6 +44,8 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
$attributesMetadata = $classMetadata->getAttributesMetadata();

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

$xml = $this->classes[$classMetadata->getName()];

foreach ($xml->attribute as $attribute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

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

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
Expand All @@ -32,6 +34,8 @@
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[IgnoreDeprecations]
#[Group('legacy')]
class XmlFileLoaderTest extends TestCase
{
use ContextMappingTestTrait;
Expand Down
Loading