@@ -288,7 +288,7 @@ public function load(array $configs, ContainerBuilder $container)
288
288
$ this ->registerDebugConfiguration ($ config ['php_errors ' ], $ container , $ loader );
289
289
$ this ->registerRouterConfiguration ($ config ['router ' ], $ container , $ loader );
290
290
$ this ->registerAnnotationsConfiguration ($ config ['annotations ' ], $ container , $ loader );
291
- $ this ->registerPropertyAccessConfiguration ($ config ['property_access ' ], $ container );
291
+ $ this ->registerPropertyAccessConfiguration ($ config ['property_access ' ], $ container, $ loader );
292
292
293
293
if ($ this ->isConfigEnabled ($ container , $ config ['serializer ' ])) {
294
294
$ this ->registerSerializerConfiguration ($ config ['serializer ' ], $ container , $ loader );
@@ -1365,39 +1365,44 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
1365
1365
}
1366
1366
}
1367
1367
1368
- private function registerValidatorMapping (ContainerBuilder $ container , array $ config , array & $ files )
1368
+ private function registerComponentMapping (ContainerBuilder $ container , array $ config , $ component , $ fileRecorder )
1369
1369
{
1370
- $ fileRecorder = function ($ extension , $ path ) use (&$ files ) {
1371
- $ files ['yaml ' === $ extension ? 'yml ' : $ extension ][] = $ path ;
1372
- };
1373
-
1374
- if (interface_exists ('Symfony\Component\Form\FormInterface ' )) {
1375
- $ reflClass = new \ReflectionClass ('Symfony\Component\Form\FormInterface ' );
1376
- $ fileRecorder ('xml ' , dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' );
1377
- }
1378
-
1379
1370
foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ bundle ) {
1380
1371
$ dirname = $ bundle ['path ' ];
1381
1372
1382
1373
if (
1383
1374
$ container ->fileExists ($ file = $ dirname .'/Resources/config/validation.yaml ' , false ) ||
1384
- $ container ->fileExists ($ file = $ dirname .'/Resources/config/validation .yml ' , false )
1375
+ $ container ->fileExists ($ file = $ dirname .'/Resources/config/ ' . $ component . ' .yml ' , false )
1385
1376
) {
1386
1377
$ fileRecorder ('yml ' , $ file );
1387
1378
}
1388
1379
1389
- if ($ container ->fileExists ($ file = $ dirname .'/Resources/config/validation .xml ' , false )) {
1380
+ if ($ container ->fileExists ($ file = $ dirname .'/Resources/config/ ' . $ component . ' .xml ' , false )) {
1390
1381
$ fileRecorder ('xml ' , $ file );
1391
1382
}
1392
1383
1393
- if ($ container ->fileExists ($ dir = $ dirname .'/Resources/config/validation ' , '/^$/ ' )) {
1384
+ if ($ container ->fileExists ($ dir = $ dirname .'/Resources/config/ ' . $ component , '/^$/ ' )) {
1394
1385
$ this ->registerMappingFilesFromDir ($ dir , $ fileRecorder );
1395
1386
}
1396
1387
}
1397
1388
1398
1389
$ this ->registerMappingFilesFromConfig ($ container , $ config , $ fileRecorder );
1399
1390
}
1400
1391
1392
+ private function registerValidatorMapping (ContainerBuilder $ container , array $ config , array &$ files )
1393
+ {
1394
+ $ fileRecorder = function ($ extension , $ path ) use (&$ files ) {
1395
+ $ files ['yaml ' === $ extension ? 'yml ' : $ extension ][] = $ path ;
1396
+ };
1397
+
1398
+ if (interface_exists ('Symfony\Component\Form\FormInterface ' )) {
1399
+ $ reflClass = new \ReflectionClass ('Symfony\Component\Form\FormInterface ' );
1400
+ $ fileRecorder ('xml ' , dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' );
1401
+ }
1402
+
1403
+ $ this ->registerComponentMapping ($ container , $ config , 'validator ' , $ fileRecorder );
1404
+ }
1405
+
1401
1406
private function registerMappingFilesFromDir ($ dir , callable $ fileRecorder )
1402
1407
{
1403
1408
foreach (Finder::create ()->followLinks ()->files ()->in ($ dir )->name ('/\.(xml|ya?ml)$/ ' ) as $ file ) {
@@ -1483,12 +1488,42 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
1483
1488
}
1484
1489
}
1485
1490
1486
- private function registerPropertyAccessConfiguration (array $ config , ContainerBuilder $ container )
1491
+ private function registerPropertyAccessConfiguration (array $ config , ContainerBuilder $ container, XmlFileLoader $ loader )
1487
1492
{
1493
+ $ loader ->load ('property_access.xml ' );
1494
+
1495
+ $ chainLoader = $ container ->getDefinition ('property_access.mapping.chain_loader ' );
1496
+
1497
+ $ serializerLoaders = array ();
1498
+ if (isset ($ config ['enable_annotations ' ]) && $ config ['enable_annotations ' ]) {
1499
+ if (!class_exists (Doctrine \Common \Annotations \Annotation::class)) {
1500
+ throw new LogicException ('Annotations cannot be enabled as the Doctrine Annotation library is not installed. ' );
1501
+ }
1502
+
1503
+ $ annotationLoader = new Definition (
1504
+ Symfony \Component \PropertyAccess \Mapping \Loader \AnnotationLoader::class,
1505
+ array (new Reference ('annotation_reader ' ))
1506
+ );
1507
+ $ annotationLoader ->setPublic (false );
1508
+
1509
+ $ serializerLoaders [] = $ annotationLoader ;
1510
+ }
1511
+
1512
+ $ fileRecorder = function ($ extension , $ path ) use (&$ serializerLoaders ) {
1513
+ $ definition = new Definition (in_array ($ extension , array ('yaml ' , 'yml ' )) ? 'Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader ' : 'Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader ' , array ($ path ));
1514
+ $ definition ->setPublic (false );
1515
+ $ serializerLoaders [] = $ definition ;
1516
+ };
1517
+
1518
+ $ this ->registerComponentMapping ($ container , $ config , 'property_access ' , $ fileRecorder );
1519
+
1520
+ $ chainLoader ->replaceArgument (0 , $ serializerLoaders );
1521
+
1488
1522
$ container
1489
1523
->getDefinition ('property_accessor ' )
1490
1524
->replaceArgument (0 , $ config ['magic_call ' ])
1491
1525
->replaceArgument (1 , $ config ['throw_exception_on_invalid_index ' ])
1526
+ ->replaceArgument (2 , $ chainLoader )
1492
1527
;
1493
1528
}
1494
1529
0 commit comments