@@ -986,8 +986,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
986
986
$ container ->setParameter ('validator.translation_domain ' , $ config ['translation_domain ' ]);
987
987
988
988
$ files = array ('xml ' => array (), 'yml ' => array ());
989
- $ this ->getValidatorMappingFiles ($ container , $ files );
990
- $ this ->getValidatorMappingFilesFromConfig ($ container , $ config , $ files );
989
+ $ this ->registerValidatorMapping ($ container , $ config , $ files );
991
990
992
991
if (!empty ($ files ['xml ' ])) {
993
992
$ validatorBuilder ->addMethodCall ('addXmlMappings ' , array ($ files ['xml ' ]));
@@ -1028,51 +1027,54 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
1028
1027
}
1029
1028
}
1030
1029
1031
- private function getValidatorMappingFiles (ContainerBuilder $ container , array &$ files )
1030
+ private function registerValidatorMapping (ContainerBuilder $ container, array $ config , array &$ files )
1032
1031
{
1032
+ $ fileRecorder = function ($ extension , $ path ) use (&$ files ) {
1033
+ $ files ['yaml ' === $ extension ? 'yml ' : $ extension ][] = $ path ;
1034
+ };
1035
+
1033
1036
if (interface_exists ('Symfony\Component\Form\FormInterface ' )) {
1034
1037
$ 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 ' ) ;
1036
1039
}
1037
1040
1038
1041
foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ bundle ) {
1039
1042
$ dirname = $ bundle ['path ' ];
1040
1043
1041
1044
if ($ container ->fileExists ($ file = $ dirname .'/Resources/config/validation.yml ' , false )) {
1042
- $ files [ 'yml ' ][] = $ file ;
1045
+ $ fileRecorder ( 'yml ' , $ file) ;
1043
1046
}
1044
1047
1045
1048
if ($ container ->fileExists ($ file = $ dirname .'/Resources/config/validation.xml ' , false )) {
1046
- $ files [ 'xml ' ][] = $ file ;
1049
+ $ fileRecorder ( 'xml ' , $ file) ;
1047
1050
}
1048
1051
1049
1052
if ($ container ->fileExists ($ dir = $ dirname .'/Resources/config/validation ' , '/^$/ ' )) {
1050
- $ this ->getValidatorMappingFilesFromDir ($ dir , $ files );
1053
+ $ this ->registerMappingFilesFromDir ($ dir , $ fileRecorder );
1051
1054
}
1052
1055
}
1056
+
1057
+ $ this ->registerMappingFilesFromConfig ($ container , $ config , $ fileRecorder );
1053
1058
}
1054
1059
1055
- private function getValidatorMappingFilesFromDir ($ dir , array & $ files )
1060
+ private function registerMappingFilesFromDir ($ dir , callable $ fileRecorder )
1056
1061
{
1057
1062
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 ());
1060
1064
}
1061
1065
}
1062
1066
1063
- private function getValidatorMappingFilesFromConfig (ContainerBuilder $ container , array $ config , array & $ files )
1067
+ private function registerMappingFilesFromConfig (ContainerBuilder $ container , array $ config , callable $ fileRecorder )
1064
1068
{
1065
1069
foreach ($ config ['mapping ' ]['paths ' ] as $ path ) {
1066
1070
if (is_dir ($ path )) {
1067
- $ this ->getValidatorMappingFilesFromDir ($ path , $ files );
1071
+ $ this ->registerMappingFilesFromDir ($ path , $ fileRecorder );
1068
1072
$ container ->addResource (new DirectoryResource ($ path , '/^$/ ' ));
1069
1073
} 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 )) {
1074
1075
throw new \RuntimeException (sprintf ('Unsupported mapping type in "%s", supported types are XML & Yaml. ' , $ path ));
1075
1076
}
1077
+ $ fileRecorder ($ matches [1 ], $ path );
1076
1078
} else {
1077
1079
throw new \RuntimeException (sprintf ('Could not open file or directory "%s". ' , $ path ));
1078
1080
}
@@ -1230,39 +1232,30 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
1230
1232
$ serializerLoaders [] = $ annotationLoader ;
1231
1233
}
1232
1234
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
+
1233
1241
foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ bundle ) {
1234
1242
$ dirname = $ bundle ['path ' ];
1235
1243
1236
1244
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 );
1241
1246
}
1242
1247
1243
1248
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 );
1248
1250
}
1249
1251
1250
1252
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 );
1263
1254
}
1264
1255
}
1265
1256
1257
+ $ this ->registerMappingFilesFromConfig ($ container , $ config , $ fileRecorder );
1258
+
1266
1259
$ chainLoader ->replaceArgument (0 , $ serializerLoaders );
1267
1260
$ container ->getDefinition ('serializer.mapping.cache_warmer ' )->replaceArgument (0 , $ serializerLoaders );
1268
1261
0 commit comments