@@ -986,8 +986,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
986986 $ container ->setParameter ('validator.translation_domain ' , $ config ['translation_domain ' ]);
987987
988988 $ files = array ('xml ' => array (), 'yml ' => array ());
989- $ this ->getValidatorMappingFiles ($ container , $ files );
990- $ this ->getValidatorMappingFilesFromConfig ($ container , $ config , $ files );
989+ $ this ->registerValidatorMapping ($ container , $ config , $ files );
991990
992991 if (!empty ($ files ['xml ' ])) {
993992 $ validatorBuilder ->addMethodCall ('addXmlMappings ' , array ($ files ['xml ' ]));
@@ -1028,51 +1027,54 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
10281027 }
10291028 }
10301029
1031- private function getValidatorMappingFiles (ContainerBuilder $ container , array &$ files )
1030+ private function registerValidatorMapping (ContainerBuilder $ container, array $ config , array &$ files )
10321031 {
1032+ $ fileRecorder = function ($ extension , $ path ) use (&$ files ) {
1033+ $ files ['yaml ' === $ extension ? 'yml ' : $ extension ][] = $ path ;
1034+ };
1035+
10331036 if (interface_exists ('Symfony\Component\Form\FormInterface ' )) {
10341037 $ reflClass = new \ReflectionClass ('Symfony\Component\Form\FormInterface ' );
1035- $ files [ 'xml ' ][] = dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' ;
1038+ $ fileRecorder ( 'xml ' , dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' ) ;
10361039 }
10371040
10381041 foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ bundle ) {
10391042 $ dirname = $ bundle ['path ' ];
10401043
10411044 if ($ container ->fileExists ($ file = $ dirname .'/Resources/config/validation.yml ' , false )) {
1042- $ files [ 'yml ' ][] = $ file ;
1045+ $ fileRecorder ( 'yml ' , $ file) ;
10431046 }
10441047
10451048 if ($ container ->fileExists ($ file = $ dirname .'/Resources/config/validation.xml ' , false )) {
1046- $ files [ 'xml ' ][] = $ file ;
1049+ $ fileRecorder ( 'xml ' , $ file) ;
10471050 }
10481051
10491052 if ($ container ->fileExists ($ dir = $ dirname .'/Resources/config/validation ' , '/^$/ ' )) {
1050- $ this ->getValidatorMappingFilesFromDir ($ dir , $ files );
1053+ $ this ->registerMappingFilesFromDir ($ dir , $ fileRecorder );
10511054 }
10521055 }
1056+
1057+ $ this ->registerMappingFilesFromConfig ($ container , $ config , $ fileRecorder );
10531058 }
10541059
1055- private function getValidatorMappingFilesFromDir ($ dir , array & $ files )
1060+ private function registerMappingFilesFromDir ($ dir , callable $ fileRecorder )
10561061 {
10571062 foreach (Finder::create ()->followLinks ()->files ()->in ($ dir )->name ('/\.(xml|ya?ml)$/ ' ) as $ file ) {
1058- $ extension = $ file ->getExtension ();
1059- $ files ['yaml ' === $ extension ? 'yml ' : $ extension ][] = $ file ->getRealpath ();
1063+ $ fileRecorder ($ file ->getExtension (), $ file ->getRealPath ());
10601064 }
10611065 }
10621066
1063- private function getValidatorMappingFilesFromConfig (ContainerBuilder $ container , array $ config , array & $ files )
1067+ private function registerMappingFilesFromConfig (ContainerBuilder $ container , array $ config , callable $ fileRecorder )
10641068 {
10651069 foreach ($ config ['mapping ' ]['paths ' ] as $ path ) {
10661070 if (is_dir ($ path )) {
1067- $ this ->getValidatorMappingFilesFromDir ($ path , $ files );
1071+ $ this ->registerMappingFilesFromDir ($ path , $ fileRecorder );
10681072 $ container ->addResource (new DirectoryResource ($ path , '/^$/ ' ));
10691073 } elseif ($ container ->fileExists ($ path , false )) {
1070- if (preg_match ('/\.(xml|ya?ml)$/ ' , $ path , $ matches )) {
1071- $ extension = $ matches [1 ];
1072- $ files ['yaml ' === $ extension ? 'yml ' : $ extension ][] = $ path ;
1073- } else {
1074+ if (!preg_match ('/\.(xml|ya?ml)$/ ' , $ path , $ matches )) {
10741075 throw new \RuntimeException (sprintf ('Unsupported mapping type in "%s", supported types are XML & Yaml. ' , $ path ));
10751076 }
1077+ $ fileRecorder ($ matches [1 ], $ path );
10761078 } else {
10771079 throw new \RuntimeException (sprintf ('Could not open file or directory "%s". ' , $ path ));
10781080 }
@@ -1230,39 +1232,30 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
12301232 $ serializerLoaders [] = $ annotationLoader ;
12311233 }
12321234
1235+ $ fileRecorder = function ($ extension , $ path ) use (&$ serializerLoaders ) {
1236+ $ definition = new Definition (in_array ($ extension , array ('yaml ' , 'yml ' )) ? 'Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader ' : 'Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader ' , array ($ path ));
1237+ $ definition ->setPublic (false );
1238+ $ serializerLoaders [] = $ definition ;
1239+ };
1240+
12331241 foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ bundle ) {
12341242 $ dirname = $ bundle ['path ' ];
12351243
12361244 if ($ container ->fileExists ($ file = $ dirname .'/Resources/config/serialization.xml ' , false )) {
1237- $ definition = new Definition ('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader ' , array ($ file ));
1238- $ definition ->setPublic (false );
1239-
1240- $ serializerLoaders [] = $ definition ;
1245+ $ fileRecorder ('xml ' , $ file );
12411246 }
12421247
12431248 if ($ container ->fileExists ($ file = $ dirname .'/Resources/config/serialization.yml ' , false )) {
1244- $ definition = new Definition ('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader ' , array ($ file ));
1245- $ definition ->setPublic (false );
1246-
1247- $ serializerLoaders [] = $ definition ;
1249+ $ fileRecorder ('yml ' , $ file );
12481250 }
12491251
12501252 if ($ container ->fileExists ($ dir = $ dirname .'/Resources/config/serialization ' )) {
1251- foreach (Finder::create ()->followLinks ()->files ()->in ($ dir )->name ('*.xml ' ) as $ file ) {
1252- $ definition = new Definition ('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader ' , array ($ file ->getPathname ()));
1253- $ definition ->setPublic (false );
1254-
1255- $ serializerLoaders [] = $ definition ;
1256- }
1257- foreach (Finder::create ()->followLinks ()->files ()->in ($ dir )->name ('*.yml ' ) as $ file ) {
1258- $ definition = new Definition ('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader ' , array ($ file ->getPathname ()));
1259- $ definition ->setPublic (false );
1260-
1261- $ serializerLoaders [] = $ definition ;
1262- }
1253+ $ this ->registerMappingFilesFromDir ($ dir , $ fileRecorder );
12631254 }
12641255 }
12651256
1257+ $ this ->registerMappingFilesFromConfig ($ container , $ config , $ fileRecorder );
1258+
12661259 $ chainLoader ->replaceArgument (0 , $ serializerLoaders );
12671260 $ container ->getDefinition ('serializer.mapping.cache_warmer ' )->replaceArgument (0 , $ serializerLoaders );
12681261
0 commit comments