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