@@ -295,7 +295,7 @@ public function load(array $configs, ContainerBuilder $container)
295295 $ this ->registerDebugConfiguration ($ config ['php_errors ' ], $ container , $ loader );
296296 $ this ->registerRouterConfiguration ($ config ['router ' ], $ container , $ loader );
297297 $ this ->registerAnnotationsConfiguration ($ config ['annotations ' ], $ container , $ loader );
298- $ this ->registerPropertyAccessConfiguration ($ config ['property_access ' ], $ container );
298+ $ this ->registerPropertyAccessConfiguration ($ config ['property_access ' ], $ container, $ loader );
299299
300300 if ($ this ->isConfigEnabled ($ container , $ config ['serializer ' ])) {
301301 $ this ->registerSerializerConfiguration ($ config ['serializer ' ], $ container , $ loader );
@@ -1309,6 +1309,35 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
13091309 }
13101310 }
13111311
1312+ /**
1313+ * @param ContainerBuilder $container
1314+ * @param array $config
1315+ * @param $component
1316+ * @param $fileRecorder
1317+ */
1318+ private function registerComponentMapping (ContainerBuilder $ container , array $ config , $ component , &$ fileRecorder )
1319+ {
1320+ foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ bundle ) {
1321+ $ dirname = $ bundle ['path ' ];
1322+
1323+ if (
1324+ $ container ->fileExists ($ file = $ dirname .'/Resources/config/ ' .$ component .'.yaml ' , false ) ||
1325+ $ container ->fileExists ($ file = $ dirname .'/Resources/config/ ' .$ component .'.yml ' , false )
1326+ ) {
1327+ $ fileRecorder ('yml ' , $ file );
1328+ }
1329+
1330+ if ($ container ->fileExists ($ file = $ dirname .'/Resources/config/ ' .$ component .'.xml ' , false )) {
1331+ $ fileRecorder ('xml ' , $ file );
1332+ }
1333+
1334+ if ($ container ->fileExists ($ dir = $ dirname .'/Resources/config/ ' .$ component , '/^$/ ' )) {
1335+ $ this ->registerMappingFilesFromDir ($ dir , $ fileRecorder );
1336+ }
1337+ }
1338+ $ this ->registerMappingFilesFromConfig ($ container , $ config , $ fileRecorder );
1339+ }
1340+
13121341 /**
13131342 * Loads the validator configuration.
13141343 *
@@ -1337,7 +1366,17 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
13371366 $ container ->setParameter ('validator.translation_domain ' , $ config ['translation_domain ' ]);
13381367
13391368 $ files = array ('xml ' => array (), 'yml ' => array ());
1340- $ this ->registerValidatorMapping ($ container , $ config , $ files );
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+ $ this ->registerComponentMapping ($ container , $ config , 'validation ' , $ fileRecorder );
13411380
13421381 if (!empty ($ files ['xml ' ])) {
13431382 $ validatorBuilder ->addMethodCall ('addXmlMappings ' , array ($ files ['xml ' ]));
@@ -1363,7 +1402,6 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
13631402 $ validatorBuilder ->addMethodCall ('addMethodMapping ' , array ($ methodName ));
13641403 }
13651404 }
1366-
13671405 if (isset ($ config ['cache ' ]) && $ config ['cache ' ]) {
13681406 $ container ->setParameter (
13691407 'validator.mapping.cache.prefix ' ,
@@ -1376,39 +1414,6 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
13761414 }
13771415 }
13781416
1379- private function registerValidatorMapping (ContainerBuilder $ container , array $ config , array &$ files )
1380- {
1381- $ fileRecorder = function ($ extension , $ path ) use (&$ files ) {
1382- $ files ['yaml ' === $ extension ? 'yml ' : $ extension ][] = $ path ;
1383- };
1384-
1385- if (interface_exists ('Symfony\Component\Form\FormInterface ' )) {
1386- $ reflClass = new \ReflectionClass ('Symfony\Component\Form\FormInterface ' );
1387- $ fileRecorder ('xml ' , dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' );
1388- }
1389-
1390- foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ bundle ) {
1391- $ dirname = $ bundle ['path ' ];
1392-
1393- if (
1394- $ container ->fileExists ($ file = $ dirname .'/Resources/config/validation.yaml ' , false ) ||
1395- $ container ->fileExists ($ file = $ dirname .'/Resources/config/validation.yml ' , false )
1396- ) {
1397- $ fileRecorder ('yml ' , $ file );
1398- }
1399-
1400- if ($ container ->fileExists ($ file = $ dirname .'/Resources/config/validation.xml ' , false )) {
1401- $ fileRecorder ('xml ' , $ file );
1402- }
1403-
1404- if ($ container ->fileExists ($ dir = $ dirname .'/Resources/config/validation ' , '/^$/ ' )) {
1405- $ this ->registerMappingFilesFromDir ($ dir , $ fileRecorder );
1406- }
1407- }
1408-
1409- $ this ->registerMappingFilesFromConfig ($ container , $ config , $ fileRecorder );
1410- }
1411-
14121417 private function registerMappingFilesFromDir ($ dir , callable $ fileRecorder )
14131418 {
14141419 foreach (Finder::create ()->followLinks ()->files ()->in ($ dir )->name ('/\.(xml|ya?ml)$/ ' ) as $ file ) {
@@ -1494,12 +1499,45 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
14941499 }
14951500 }
14961501
1497- private function registerPropertyAccessConfiguration (array $ config , ContainerBuilder $ container )
1502+ private function registerPropertyAccessConfiguration (array $ config , ContainerBuilder $ container, XmlFileLoader $ loader )
14981503 {
1504+ $ loader ->load ('property_access.xml ' );
1505+
1506+ $ chainLoader = $ container ->getDefinition ('property_access.mapping.chain_loader ' );
1507+
1508+ $ serializerLoaders = array ();
1509+ if (isset ($ config ['enable_annotations ' ]) && $ config ['enable_annotations ' ]) {
1510+ if (!$ this ->annotationsConfigEnabled ) {
1511+ throw new \LogicException ('"enable_annotations" on property access cannot be set as Annotations support is disabled. ' );
1512+ }
1513+
1514+ $ annotationLoader = new Definition (
1515+ 'Symfony\Component\PropertyAccess\Mapping\Loader\AnnotationLoader ' ,
1516+ array (new Reference ('annotation_reader ' ))
1517+ );
1518+ $ annotationLoader ->setPublic (false );
1519+
1520+ $ serializerLoaders [] = $ annotationLoader ;
1521+ }
1522+
1523+ $ fileRecorder = function ($ extension , $ path ) use (&$ serializerLoaders ) {
1524+ $ definition = new Definition (in_array ($ extension , array ('yaml ' , 'yml ' )) ? 'Symfony\Component\PropertyAccess\Mapping\Loader\YamlFileLoader ' : 'Symfony\Component\PropertyAccess\Mapping\Loader\XmlFileLoader ' , array ($ path ));
1525+ $ definition ->setPublic (false );
1526+ $ serializerLoaders [] = $ definition ;
1527+ };
1528+
1529+ $ this ->registerComponentMapping ($ container , $ config , 'property_accessor ' , $ fileRecorder );
1530+
1531+ $ chainLoader ->replaceArgument (0 , $ serializerLoaders );
1532+
1533+ $ metadataLoader = $ container ->getDefinition ('property_access.mapping.class_metadata_factory ' )
1534+ ->replaceArgument (0 , $ chainLoader );
1535+
14991536 $ container
15001537 ->getDefinition ('property_accessor ' )
15011538 ->replaceArgument (0 , $ config ['magic_call ' ])
15021539 ->replaceArgument (1 , $ config ['throw_exception_on_invalid_index ' ])
1540+ ->replaceArgument (3 , $ metadataLoader )
15031541 ;
15041542 }
15051543
0 commit comments