12
12
namespace Symfony \Bundle \FrameworkBundle \DependencyInjection ;
13
13
14
14
use Doctrine \Common \Annotations \Reader ;
15
+ use Doctrine \Common \Annotations \Annotation ;
15
16
use Symfony \Bridge \Monolog \Processor \DebugProcessor ;
16
17
use Symfony \Component \Cache \Adapter \AdapterInterface ;
17
18
use Symfony \Component \Config \Loader \LoaderInterface ;
29
30
use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
30
31
use Symfony \Component \Config \FileLocator ;
31
32
use Symfony \Component \Config \Resource \ClassExistenceResource ;
33
+ use Symfony \Component \Config \Resource \FileExistenceResource ;
32
34
use Symfony \Component \PropertyAccess \PropertyAccessor ;
33
35
use Symfony \Component \Serializer \Encoder \YamlEncoder ;
34
36
use Symfony \Component \Serializer \Encoder \CsvEncoder ;
41
43
use Symfony \Component \Yaml \Yaml ;
42
44
use Symfony \Component \Console \Application ;
43
45
use Symfony \Component \Translation \Translator ;
46
+ use Symfony \Component \Validator \Validation ;
47
+ use Symfony \Component \Security \Csrf \CsrfToken ;
48
+ use Symfony \Component \Security \Core \Exception \AuthenticationException ;
49
+ use Symfony \Component \Form \Form ;
44
50
45
51
/**
46
52
* FrameworkExtension.
@@ -106,7 +112,6 @@ public function load(array $configs, ContainerBuilder $container)
106
112
// default in the Form and Validator component). If disabled, an identity
107
113
// translator will be used and everything will still work as expected.
108
114
if ($ this ->isConfigEnabled ($ container , $ config ['translator ' ]) || $ this ->isConfigEnabled ($ container , $ config ['form ' ]) || $ this ->isConfigEnabled ($ container , $ config ['validation ' ])) {
109
- $ container ->addResource (new ClassExistenceResource (Translator::class));
110
115
if (!class_exists (Translator::class) && $ this ->isConfigEnabled ($ container , $ config ['translator ' ])) {
111
116
throw new LogicException ('Translation support cannot be enabled as the Translation component is not installed. ' );
112
117
}
@@ -160,12 +165,15 @@ public function load(array $configs, ContainerBuilder $container)
160
165
$ this ->registerRequestConfiguration ($ config ['request ' ], $ container , $ loader );
161
166
}
162
167
168
+ $ container ->addResource (new ClassExistenceResource (Validation::class));
169
+ $ container ->addResource (new ClassExistenceResource (Form::class));
170
+
163
171
if ($ this ->isConfigEnabled ($ container , $ config ['form ' ])) {
164
172
$ this ->formConfigEnabled = true ;
165
173
$ this ->registerFormConfiguration ($ config , $ container , $ loader );
166
174
$ config ['validation ' ]['enabled ' ] = true ;
167
175
168
- if (!class_exists (' Symfony\Component\Validator\ Validation' )) {
176
+ if (!class_exists (Validation::class )) {
169
177
throw new LogicException ('The Validator component is required to use the Form component. ' );
170
178
}
171
179
}
@@ -527,6 +535,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
527
535
$ definition ->replaceArgument (4 , $ debug );
528
536
$ definition ->replaceArgument (6 , $ debug );
529
537
538
+ $ container ->addResource (new ClassExistenceResource (DebugProcessor::class));
530
539
if ($ debug && class_exists (DebugProcessor::class)) {
531
540
$ definition = new Definition (DebugProcessor::class);
532
541
$ definition ->setPublic (false );
@@ -862,41 +871,51 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
862
871
863
872
// Discover translation directories
864
873
$ dirs = array ();
865
- if (class_exists (' Symfony\Component\Validator\ Validation' )) {
866
- $ r = new \ReflectionClass (' Symfony\Component\Validator\ Validation' );
874
+ if (class_exists (Validation::class )) {
875
+ $ r = new \ReflectionClass (Validation::class );
867
876
868
877
$ dirs [] = dirname ($ r ->getFileName ()).'/Resources/translations ' ;
869
878
}
870
- if (class_exists (' Symfony\Component\ Form\Form ' )) {
871
- $ r = new \ReflectionClass (' Symfony\Component\ Form\Form ' );
879
+ if (class_exists (Form::class )) {
880
+ $ r = new \ReflectionClass (Form::class );
872
881
873
882
$ dirs [] = dirname ($ r ->getFileName ()).'/Resources/translations ' ;
874
883
}
875
- if (class_exists ('Symfony\Component\Security\Core\Exception\AuthenticationException ' )) {
876
- $ r = new \ReflectionClass ('Symfony\Component\Security\Core\Exception\AuthenticationException ' );
884
+
885
+ $ container ->addResource (new ClassExistenceResource (AuthenticationException::class));
886
+ if (class_exists (AuthenticationException::class)) {
887
+ $ r = new \ReflectionClass (AuthenticationException::class);
877
888
878
889
$ dirs [] = dirname (dirname ($ r ->getFileName ())).'/Resources/translations ' ;
879
890
}
880
891
$ rootDir = $ container ->getParameter ('kernel.root_dir ' );
881
892
foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ name => $ bundle ) {
882
893
if (is_dir ($ dir = $ bundle ['path ' ].'/Resources/translations ' )) {
883
894
$ dirs [] = $ dir ;
895
+ } else {
896
+ $ container ->addResource (new FileExistenceResource ($ dir ));
884
897
}
885
898
if (is_dir ($ dir = $ rootDir .sprintf ('/Resources/%s/translations ' , $ name ))) {
886
899
$ dirs [] = $ dir ;
900
+ } else {
901
+ $ container ->addResource (new FileExistenceResource ($ dir ));
887
902
}
888
903
}
889
904
890
905
foreach ($ config ['paths ' ] as $ dir ) {
891
906
if (is_dir ($ dir )) {
892
907
$ dirs [] = $ dir ;
893
908
} else {
909
+ $ container ->addResource (new FileExistenceResource ($ dir ));
910
+
894
911
throw new \UnexpectedValueException (sprintf ('%s defined in translator.paths does not exist or is not a directory ' , $ dir ));
895
912
}
896
913
}
897
914
898
915
if (is_dir ($ dir = $ rootDir .'/Resources/translations ' )) {
899
916
$ dirs [] = $ dir ;
917
+ } else {
918
+ $ container ->addResource (new FileExistenceResource ($ dir ));
900
919
}
901
920
902
921
// Register translation resources
@@ -946,7 +965,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
946
965
return ;
947
966
}
948
967
949
- if (!class_exists (' Symfony\Component\Validator\ Validation' )) {
968
+ if (!class_exists (Validation::class )) {
950
969
throw new LogicException ('Validation support cannot be enabled as the Validator component is not installed. ' );
951
970
}
952
971
@@ -958,7 +977,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
958
977
959
978
$ files = array ('xml ' => array (), 'yml ' => array ());
960
979
$ this ->getValidatorMappingFiles ($ container , $ files );
961
- $ this ->getValidatorMappingFilesFromConfig ($ config , $ files );
980
+ $ this ->getValidatorMappingFilesFromConfig ($ container , $ config , $ files );
962
981
963
982
if (!empty ($ files ['xml ' ])) {
964
983
$ validatorBuilder ->addMethodCall ('addXmlMappings ' , array ($ files ['xml ' ]));
@@ -1001,26 +1020,27 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
1001
1020
1002
1021
private function getValidatorMappingFiles (ContainerBuilder $ container , array &$ files )
1003
1022
{
1004
- if (interface_exists ( ' Symfony\Component\ Form\FormInterface ' )) {
1005
- $ reflClass = new \ReflectionClass (' Symfony\Component\ Form\FormInterface ' );
1023
+ if (class_exists ( Form::class )) {
1024
+ $ reflClass = new \ReflectionClass (Form::class );
1006
1025
$ files ['xml ' ][] = $ file = dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' ;
1007
1026
$ container ->addResource (new FileResource ($ file ));
1008
1027
}
1009
1028
1010
1029
foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ bundle ) {
1011
1030
$ dirname = $ bundle ['path ' ];
1012
1031
1013
- if (is_file ($ file = $ dirname .'/Resources/config/validation.yml ' )) {
1032
+ $ container ->addResource (new FileExistenceResource ($ file = $ dirname .'/Resources/config/validation.yml ' ));
1033
+ if (is_file ($ file )) {
1014
1034
$ files ['yml ' ][] = $ file ;
1015
- $ container ->addResource (new FileResource ($ file ));
1016
1035
}
1017
1036
1018
- if (is_file ($ file = $ dirname .'/Resources/config/validation.xml ' )) {
1037
+ $ container ->addResource (new FileExistenceResource ($ file = $ dirname .'/Resources/config/validation.xml ' ));
1038
+ if (is_file ($ file )) {
1019
1039
$ files ['xml ' ][] = $ file ;
1020
- $ container ->addResource (new FileResource ($ file ));
1021
1040
}
1022
1041
1023
- if (is_dir ($ dir = $ dirname .'/Resources/config/validation ' )) {
1042
+ $ container ->addResource (new FileExistenceResource ($ dir = $ dirname .'/Resources/config/validation ' ));
1043
+ if (is_dir ($ dir )) {
1024
1044
$ this ->getValidatorMappingFilesFromDir ($ dir , $ files );
1025
1045
$ container ->addResource (new DirectoryResource ($ dir ));
1026
1046
}
@@ -1035,9 +1055,10 @@ private function getValidatorMappingFilesFromDir($dir, array &$files)
1035
1055
}
1036
1056
}
1037
1057
1038
- private function getValidatorMappingFilesFromConfig (array $ config , array &$ files )
1058
+ private function getValidatorMappingFilesFromConfig (ContainerBuilder $ container , array $ config , array &$ files )
1039
1059
{
1040
1060
foreach ($ config ['mapping ' ]['paths ' ] as $ path ) {
1061
+ $ container ->addResource (new FileExistenceResource ($ path ));
1041
1062
if (is_dir ($ path )) {
1042
1063
$ this ->getValidatorMappingFilesFromDir ($ path , $ files );
1043
1064
} elseif (is_file ($ path )) {
@@ -1059,7 +1080,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
1059
1080
return ;
1060
1081
}
1061
1082
1062
- if (!class_exists ('Doctrine\Common\Annotations\Annotation ' )) {
1083
+ $ container ->addResource (new ClassExistenceResource (Annotation::class));
1084
+ if (!class_exists (Annotation::class)) {
1063
1085
throw new LogicException ('Annotations cannot be enabled as the Doctrine Annotation library is not installed. ' );
1064
1086
}
1065
1087
@@ -1130,6 +1152,7 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
1130
1152
return ;
1131
1153
}
1132
1154
1155
+ $ container ->addResource (new ClassExistenceResource (CsrfToken::class));
1133
1156
if (!class_exists ('Symfony\Component\Security\Csrf\CsrfToken ' )) {
1134
1157
throw new LogicException ('CSRF support cannot be enabled as the Security CSRF component is not installed. ' );
1135
1158
}
@@ -1151,33 +1174,38 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
1151
1174
*/
1152
1175
private function registerSerializerConfiguration (array $ config , ContainerBuilder $ container , XmlFileLoader $ loader )
1153
1176
{
1154
- if (class_exists ('Symfony\Component\Serializer\Normalizer\DataUriNormalizer ' )) {
1177
+ $ container ->addResource (new ClassExistenceResource (DataUriNormalizer::class));
1178
+ if (class_exists (DataUriNormalizer::class)) {
1155
1179
// Run after serializer.normalizer.object
1156
1180
$ definition = $ container ->register ('serializer.normalizer.data_uri ' , DataUriNormalizer::class);
1157
1181
$ definition ->setPublic (false );
1158
1182
$ definition ->addTag ('serializer.normalizer ' , array ('priority ' => -920 ));
1159
1183
}
1160
1184
1161
- if (class_exists ('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer ' )) {
1185
+ $ container ->addResource (new ClassExistenceResource (DateTimeNormalizer::class));
1186
+ if (class_exists (DateTimeNormalizer::class)) {
1162
1187
// Run before serializer.normalizer.object
1163
1188
$ definition = $ container ->register ('serializer.normalizer.datetime ' , DateTimeNormalizer::class);
1164
1189
$ definition ->setPublic (false );
1165
1190
$ definition ->addTag ('serializer.normalizer ' , array ('priority ' => -910 ));
1166
1191
}
1167
1192
1168
- if (class_exists ('Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer ' )) {
1193
+ $ container ->addResource (new ClassExistenceResource (JsonSerializableNormalizer::class));
1194
+ if (class_exists (JsonSerializableNormalizer::class)) {
1169
1195
// Run before serializer.normalizer.object
1170
1196
$ definition = $ container ->register ('serializer.normalizer.json_serializable ' , JsonSerializableNormalizer::class);
1171
1197
$ definition ->setPublic (false );
1172
1198
$ definition ->addTag ('serializer.normalizer ' , array ('priority ' => -900 ));
1173
1199
}
1174
1200
1201
+ $ container ->addResource (new ClassExistenceResource (YamlEncoder::class));
1175
1202
if (class_exists (YamlEncoder::class) && defined ('Symfony\Component\Yaml\Yaml::DUMP_OBJECT ' )) {
1176
1203
$ definition = $ container ->register ('serializer.encoder.yaml ' , YamlEncoder::class);
1177
1204
$ definition ->setPublic (false );
1178
1205
$ definition ->addTag ('serializer.encoder ' );
1179
1206
}
1180
1207
1208
+ $ container ->addResource (new ClassExistenceResource (CsvEncoder::class));
1181
1209
if (class_exists (CsvEncoder::class)) {
1182
1210
$ definition = $ container ->register ('serializer.encoder.csv ' , CsvEncoder::class);
1183
1211
$ definition ->setPublic (false );
@@ -1213,12 +1241,12 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
1213
1241
$ container ->addResource (new FileResource ($ file ));
1214
1242
}
1215
1243
1216
- if (is_file ($ file = $ dirname .'/Resources/config/serialization.yml ' )) {
1244
+ $ container ->addResource (new FileExistenceResource ($ file = $ dirname .'/Resources/config/serialization.yml ' ));
1245
+ if (is_file ($ file )) {
1217
1246
$ definition = new Definition ('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader ' , array ($ file ));
1218
1247
$ definition ->setPublic (false );
1219
1248
1220
1249
$ serializerLoaders [] = $ definition ;
1221
- $ container ->addResource (new FileResource ($ file ));
1222
1250
}
1223
1251
1224
1252
if (is_dir ($ dir = $ dirname .'/Resources/config/serialization ' )) {
@@ -1236,6 +1264,8 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
1236
1264
}
1237
1265
1238
1266
$ container ->addResource (new DirectoryResource ($ dir ));
1267
+ } else {
1268
+ $ container ->addResource (new FileExistenceResource ($ dir ));
1239
1269
}
1240
1270
}
1241
1271
0 commit comments