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

Commitc5c98cb

Browse files
committed
Deprecate XML configuration format
1 parent298e56a commitc5c98cb

File tree

21 files changed

+410
-25
lines changed

21 files changed

+410
-25
lines changed

‎UPGRADE-7.4.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
UPGRADE FROM 7.3 to 7.4
2+
=======================
3+
4+
Symfony 7.4 is a minor release. According to the Symfony release process, there should be no significant
5+
backward compatibility breaks. Minor backward compatibility breaks are prefixed in this document with
6+
`[BC BREAK]`, make sure your code is compatible with these entries before upgrading.
7+
Read more about this in the[Symfony documentation](https://symfony.com/doc/7.4/setup/upgrade_minor.html).
8+
9+
If you're upgrading from a version below 7.3, follow the[7.3 upgrade guide](UPGRADE-7.3.md) first.
10+
11+
DependencyInjection
12+
-------------------
13+
14+
* Deprecate XML configuration format, use YAML or PHP instead
15+
16+
Routing
17+
-------
18+
19+
* Deprecate XML configuration format, use YAML, PHP or attributes instead
20+
21+
Serializer
22+
----------
23+
24+
* Deprecate XML configuration format, use YAML or attributes instead
25+
26+
Validator
27+
---------
28+
29+
* Deprecate XML configuration format, use YAML or attributes instead

‎src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
useSymfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderParentEntity;
2323
useSymfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
2424
useSymfony\Bridge\Doctrine\Validator\DoctrineLoader;
25+
useSymfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
2526
useSymfony\Component\Validator\Constraints\Length;
2627
useSymfony\Component\Validator\Mapping\AutoMappingStrategy;
2728
useSymfony\Component\Validator\Mapping\CascadingStrategy;
@@ -36,6 +37,8 @@
3637
*/
3738
class DoctrineLoaderTestextends TestCase
3839
{
40+
use ExpectUserDeprecationMessageTrait;
41+
3942
publicfunctiontestLoadClassMetadata()
4043
{
4144
$validator = Validation::createValidatorBuilder()
@@ -155,8 +158,13 @@ public function testExtractEnum()
155158
$this->assertCount(0,$enumStringMetadata);// asserts the length constraint is not added to an enum
156159
}
157160

161+
/**
162+
* @group legacy
163+
*/
158164
publicfunctiontestFieldMappingsConfiguration()
159165
{
166+
$this->expectUserDeprecationMessage('Since symfony/validator 7.4: XML configuration format is deprecated, use YAML or attributes instead.');
167+
160168
$validator = Validation::createValidatorBuilder()
161169
->enableAttributeMapping()
162170
->addXmlMappings([__DIR__.'/../Resources/validator/BaseUser.xml'])

‎src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 229 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testLoadEmptyConfiguration()
4242
$container->loadFromExtension('twig');
4343
$this->compileContainer($container);
4444

45-
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.xml file');
45+
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.php file');
4646

4747
$this->assertContains('form_div_layout.html.twig',$container->getParameter('twig.form.resources'),'->load() includes default template for form resources');
4848

@@ -73,7 +73,7 @@ public function testLoadFullConfiguration(string $format, ?string $buildDir)
7373
$this->loadFromFile($container,'full',$format);
7474
$this->compileContainer($container);
7575

76-
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.xml file');
76+
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.php file');
7777

7878
// Form resources
7979
$resources =$container->getParameter('twig.form.resources');
@@ -90,12 +90,51 @@ public function testLoadFullConfiguration(string $format, ?string $buildDir)
9090
$this->assertEquals('@qux',$calls[3][1][1],'->load() allows escaping of service identifiers');
9191
$this->assertEquals('pi',$calls[4][1][0],'->load() registers variables as Twig globals');
9292
$this->assertEquals(3.14,$calls[4][1][1],'->load() registers variables as Twig globals');
93+
$this->assertEquals('bad',$calls[5][1][0],'->load() registers variables as Twig globals');
94+
$this->assertEquals(['key' =>'foo'],$calls[5][1][1],'->load() registers variables as Twig globals');
9395

94-
// Yaml and Php specific configs
95-
if (\in_array($format, ['yml','php'])) {
96-
$this->assertEquals('bad',$calls[5][1][0],'->load() registers variables as Twig globals');
97-
$this->assertEquals(['key' =>'foo'],$calls[5][1][1],'->load() registers variables as Twig globals');
98-
}
96+
// Twig options
97+
$options =$container->getDefinition('twig')->getArgument(1);
98+
$this->assertFalse($options['auto_reload'],'->load() sets the auto_reload option');
99+
$this->assertSame('name',$options['autoescape'],'->load() sets the autoescape option');
100+
$this->assertArrayNotHasKey('base_template_class',$options,'->load() does not set the base_template_class if none is provided');
101+
$this->assertEquals('ISO-8859-1',$options['charset'],'->load() sets the charset option');
102+
$this->assertTrue($options['debug'],'->load() sets the debug option');
103+
$this->assertTrue($options['strict_variables'],'->load() sets the strict_variables option');
104+
$this->assertEquals($buildDir !==null ?newReference('twig.template_cache.chain') :'%kernel.cache_dir%/twig',$options['cache'],'->load() sets the cache option');
105+
}
106+
107+
/**
108+
* @group legacy
109+
*
110+
* @dataProvider getXmlBuildDir
111+
*/
112+
publicfunctiontestLoadFullXmlConfiguration(?string$buildDir)
113+
{
114+
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead.');
115+
116+
$container =$this->createContainer($buildDir);
117+
$container->registerExtension(newTwigExtension());
118+
$this->loadFromFile($container,'full','xml');
119+
$this->compileContainer($container);
120+
121+
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.php file');
122+
123+
// Form resources
124+
$resources =$container->getParameter('twig.form.resources');
125+
$this->assertContains('form_div_layout.html.twig',$resources,'->load() includes default template for form resources');
126+
$this->assertContains('MyBundle::form.html.twig',$resources,'->load() merges new templates into form resources');
127+
128+
// Globals
129+
$calls =$container->getDefinition('twig')->getMethodCalls();
130+
$this->assertEquals('app',$calls[0][1][0],'->load() registers services as Twig globals');
131+
$this->assertEquals(newReference('twig.app_variable'),$calls[0][1][1]);
132+
$this->assertEquals('foo',$calls[2][1][0],'->load() registers services as Twig globals');
133+
$this->assertEquals(newReference('bar'),$calls[2][1][1],'->load() registers services as Twig globals');
134+
$this->assertEquals('baz',$calls[3][1][0],'->load() registers variables as Twig globals');
135+
$this->assertEquals('@qux',$calls[3][1][1],'->load() allows escaping of service identifiers');
136+
$this->assertEquals('pi',$calls[4][1][0],'->load() registers variables as Twig globals');
137+
$this->assertEquals(3.14,$calls[4][1][1],'->load() registers variables as Twig globals');
99138

100139
// Twig options
101140
$options =$container->getDefinition('twig')->getArgument(1);
@@ -118,7 +157,28 @@ public function testLoadNoCacheConfiguration(string $format, ?string $buildDir)
118157
$this->loadFromFile($container,'no-cache',$format);
119158
$this->compileContainer($container);
120159

121-
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.xml file');
160+
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.php file');
161+
162+
// Twig options
163+
$options =$container->getDefinition('twig')->getArgument(1);
164+
$this->assertFalse($options['cache'],'->load() sets cache option to false');
165+
}
166+
167+
/**
168+
* @group legacy
169+
*
170+
* @dataProvider getXmlBuildDir
171+
*/
172+
publicfunctiontestLoadNoCacheXmlConfiguration(?string$buildDir)
173+
{
174+
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead.');
175+
176+
$container =$this->createContainer($buildDir);
177+
$container->registerExtension(newTwigExtension());
178+
$this->loadFromFile($container,'no-cache','xml');
179+
$this->compileContainer($container);
180+
181+
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.php file');
122182

123183
// Twig options
124184
$options =$container->getDefinition('twig')->getArgument(1);
@@ -135,7 +195,28 @@ public function testLoadPathCacheConfiguration(string $format, ?string $buildDir
135195
$this->loadFromFile($container,'path-cache',$format);
136196
$this->compileContainer($container);
137197

138-
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.xml file');
198+
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.php file');
199+
200+
// Twig options
201+
$options =$container->getDefinition('twig')->getArgument(1);
202+
$this->assertSame('random-path',$options['cache'],'->load() sets cache option to string path');
203+
}
204+
205+
/**
206+
* @group legacy
207+
*
208+
* @dataProvider getXmlBuildDir
209+
*/
210+
publicfunctiontestLoadPathCacheXmlConfiguration(?string$buildDir)
211+
{
212+
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead.');
213+
214+
$container =$this->createContainer($buildDir);
215+
$container->registerExtension(newTwigExtension());
216+
$this->loadFromFile($container,'path-cache','xml');
217+
$this->compileContainer($container);
218+
219+
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.php file');
139220

140221
// Twig options
141222
$options =$container->getDefinition('twig')->getArgument(1);
@@ -152,7 +233,28 @@ public function testLoadProdCacheConfiguration(string $format, ?string $buildDir
152233
$this->loadFromFile($container,'prod-cache',$format);
153234
$this->compileContainer($container);
154235

155-
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.xml file');
236+
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.php file');
237+
238+
// Twig options
239+
$options =$container->getDefinition('twig')->getArgument(1);
240+
$this->assertEquals($buildDir !==null ?newReference('twig.template_cache.chain') :'%kernel.cache_dir%/twig',$options['cache'],'->load() sets cache option to CacheChain reference');
241+
}
242+
243+
/**
244+
* @group legacy
245+
*
246+
* @dataProvider getXmlBuildDir
247+
*/
248+
publicfunctiontestLoadProdCacheXmlConfiguration(?string$buildDir)
249+
{
250+
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead.');
251+
252+
$container =$this->createContainer($buildDir);
253+
$container->registerExtension(newTwigExtension());
254+
$this->loadFromFile($container,'prod-cache','xml');
255+
$this->compileContainer($container);
256+
257+
$this->assertEquals(Environment::class,$container->getDefinition('twig')->getClass(),'->load() loads the twig.php file');
156258

157259
// Twig options
158260
$options =$container->getDefinition('twig')->getArgument(1);
@@ -192,6 +294,22 @@ public function testLoadCustomTemplateEscapingGuesserConfiguration(string $forma
192294
$this->assertEquals([newReference('my_project.some_bundle.template_escaping_guesser'),'guess'],$options['autoescape']);
193295
}
194296

297+
/**
298+
* @group legacy
299+
*/
300+
publicfunctiontestLoadCustomTemplateEscapingGuesserXmlConfiguration()
301+
{
302+
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead.');
303+
304+
$container =$this->createContainer();
305+
$container->registerExtension(newTwigExtension());
306+
$this->loadFromFile($container,'customTemplateEscapingGuesser','xml');
307+
$this->compileContainer($container);
308+
309+
$options =$container->getDefinition('twig')->getArgument(1);
310+
$this->assertEquals([newReference('my_project.some_bundle.template_escaping_guesser'),'guess'],$options['autoescape']);
311+
}
312+
195313
/**
196314
* @dataProvider getFormats
197315
*/
@@ -206,6 +324,22 @@ public function testLoadDefaultTemplateEscapingGuesserConfiguration(string $form
206324
$this->assertEquals('name',$options['autoescape']);
207325
}
208326

327+
/**
328+
* @group legacy
329+
*/
330+
publicfunctiontestLoadDefaultTemplateEscapingGuesserXmlConfiguration()
331+
{
332+
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead.');
333+
334+
$container =$this->createContainer();
335+
$container->registerExtension(newTwigExtension());
336+
$this->loadFromFile($container,'empty','xml');
337+
$this->compileContainer($container);
338+
339+
$options =$container->getDefinition('twig')->getArgument(1);
340+
$this->assertEquals('name',$options['autoescape']);
341+
}
342+
209343
/**
210344
* @dataProvider getFormats
211345
*/
@@ -226,6 +360,28 @@ public function testLoadCustomDateFormats(string $fileFormat)
226360
$this->assertSame('.',$environmentConfigurator->getArgument(5));
227361
}
228362

363+
/**
364+
* @group legacy
365+
*/
366+
publicfunctiontestLoadXmlCustomDateFormats()
367+
{
368+
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead.');
369+
370+
$container =$this->createContainer();
371+
$container->registerExtension(newTwigExtension());
372+
$this->loadFromFile($container,'formats','xml');
373+
$this->compileContainer($container);
374+
375+
$environmentConfigurator =$container->getDefinition('twig.configurator.environment');
376+
377+
$this->assertSame('Y-m-d',$environmentConfigurator->getArgument(0));
378+
$this->assertSame('%d',$environmentConfigurator->getArgument(1));
379+
$this->assertSame('Europe/Berlin',$environmentConfigurator->getArgument(2));
380+
$this->assertSame(2,$environmentConfigurator->getArgument(3));
381+
$this->assertSame(',',$environmentConfigurator->getArgument(4));
382+
$this->assertSame('.',$environmentConfigurator->getArgument(5));
383+
}
384+
229385
publicfunctiontestGlobalsWithDifferentTypesAndValues()
230386
{
231387
$globals = [
@@ -287,12 +443,45 @@ public function testTwigLoaderPaths(string $format)
287443
],$paths);
288444
}
289445

446+
/**
447+
* @group legacy
448+
*/
449+
publicfunctiontestTwigXmlLoaderPaths()
450+
{
451+
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead.');
452+
453+
$container =$this->createContainer();
454+
$container->registerExtension(newTwigExtension());
455+
$this->loadFromFile($container,'full','xml');
456+
$this->loadFromFile($container,'extra','xml');
457+
$this->compileContainer($container);
458+
459+
$def =$container->getDefinition('twig.loader.native_filesystem');
460+
$paths = [];
461+
foreach ($def->getMethodCalls()as$call) {
462+
if ('addPath' ===$call[0] && !str_contains($call[1][0],'Form')) {
463+
$paths[] =$call[1];
464+
}
465+
}
466+
467+
$this->assertEquals([
468+
['path1'],
469+
['path2'],
470+
['namespaced_path1','namespace1'],
471+
['namespaced_path2','namespace2'],
472+
['namespaced_path3','namespace3'],
473+
[__DIR__.'/Fixtures/templates/bundles/AcmeBundle','Acme'],
474+
[__DIR__.'/AcmeBundle/Resources/views','Acme'],
475+
[__DIR__.'/AcmeBundle/Resources/views','!Acme'],
476+
[__DIR__.'/Fixtures/templates'],
477+
],$paths);
478+
}
479+
290480
publicstaticfunctiongetFormats():array
291481
{
292482
return [
293483
['php'],
294484
['yml'],
295-
['xml'],
296485
];
297486
}
298487

@@ -303,8 +492,14 @@ public static function getFormatsAndBuildDir(): array
303492
['php',__DIR__.'/build'],
304493
['yml',null],
305494
['yml',__DIR__.'/build'],
306-
['xml',null],
307-
['xml',__DIR__.'/build'],
495+
];
496+
}
497+
498+
publicstaticfunctiongetXmlBuildDir():array
499+
{
500+
return [
501+
[null],
502+
[__DIR__.'/build'],
308503
];
309504
}
310505

@@ -383,6 +578,27 @@ public function testCustomHtmlToTextConverterService(string $format)
383578
$this->assertEquals(newReference('my_converter'),$bodyRenderer->getArgument('$converter'));
384579
}
385580

581+
/**
582+
* @group legacy
583+
*/
584+
publicfunctiontestXmlCustomHtmlToTextConverterService()
585+
{
586+
if (!class_exists(Mailer::class)) {
587+
$this->markTestSkipped('The "twig.mime_body_renderer" service requires the Mailer component');
588+
}
589+
590+
$this->expectUserDeprecationMessage('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead.');
591+
592+
$container =$this->createContainer();
593+
$container->registerExtension(newTwigExtension());
594+
$this->loadFromFile($container,'mailer','xml');
595+
$this->compileContainer($container);
596+
597+
$bodyRenderer =$container->getDefinition('twig.mime_body_renderer');
598+
$this->assertCount(3,$bodyRenderer->getArguments());
599+
$this->assertEquals(newReference('my_converter'),$bodyRenderer->getArgument('$converter'));
600+
}
601+
386602
privatefunctioncreateContainer(?string$buildDir =null):ContainerBuilder
387603
{
388604
$container =newContainerBuilder(newParameterBag([

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp