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 \Templating \PhpEngine ;
48
+ use Symfony \Component \Security \Csrf \CsrfToken ;
49
+ use Symfony \Component \Security \Core \Exception \AuthenticationException ;
50
+ use Symfony \Component \Form \Form ;
51
+ use Symfony \Component \Asset \Package ;
44
52
45
53
/**
46
54
* FrameworkExtension.
@@ -160,28 +168,33 @@ public function load(array $configs, ContainerBuilder $container)
160
168
$ this ->registerRequestConfiguration ($ config ['request ' ], $ container , $ loader );
161
169
}
162
170
171
+ $ container ->addResource (new ClassExistenceResource (Validation::class));
172
+ $ container ->addResource (new ClassExistenceResource (Form::class));
173
+
163
174
if ($ this ->isConfigEnabled ($ container , $ config ['form ' ])) {
164
175
$ this ->formConfigEnabled = true ;
165
176
$ this ->registerFormConfiguration ($ config , $ container , $ loader );
166
177
$ config ['validation ' ]['enabled ' ] = true ;
167
178
168
- if (!class_exists (' Symfony\Component\Validator\ Validation' )) {
179
+ if (!class_exists (Validation::class )) {
169
180
throw new LogicException ('The Validator component is required to use the Form component. ' );
170
181
}
171
182
}
172
183
173
184
$ this ->registerSecurityCsrfConfiguration ($ config ['csrf_protection ' ], $ container , $ loader );
174
185
175
186
if ($ this ->isConfigEnabled ($ container , $ config ['assets ' ])) {
176
- if (!class_exists ('Symfony\Component\Asset\Package ' )) {
187
+ $ container ->addResource (new ClassExistenceResource (Package::class));
188
+ if (!class_exists (Package::class)) {
177
189
throw new LogicException ('Asset support cannot be enabled as the Asset component is not installed. ' );
178
190
}
179
191
180
192
$ this ->registerAssetsConfiguration ($ config ['assets ' ], $ container , $ loader );
181
193
}
182
194
183
195
if ($ this ->isConfigEnabled ($ container , $ config ['templating ' ])) {
184
- if (!class_exists ('Symfony\Component\Templating\PhpEngine ' )) {
196
+ $ container ->addResource (new ClassExistenceResource (PhpEngine::class));
197
+ if (!class_exists (PhpEngine::class)) {
185
198
throw new LogicException ('Templating support cannot be enabled as the Templating component is not installed. ' );
186
199
}
187
200
@@ -527,6 +540,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
527
540
$ definition ->replaceArgument (4 , $ debug );
528
541
$ definition ->replaceArgument (6 , $ debug );
529
542
543
+ $ container ->addResource (new ClassExistenceResource (DebugProcessor::class));
530
544
if ($ debug && class_exists (DebugProcessor::class)) {
531
545
$ definition = new Definition (DebugProcessor::class);
532
546
$ definition ->setPublic (false );
@@ -862,40 +876,46 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
862
876
863
877
// Discover translation directories
864
878
$ dirs = array ();
865
- if (class_exists (' Symfony\Component\Validator\ Validation' )) {
866
- $ r = new \ReflectionClass (' Symfony\Component\Validator\ Validation' );
879
+ if (class_exists (Validation::class )) {
880
+ $ r = new \ReflectionClass (Validation::class );
867
881
868
882
$ dirs [] = dirname ($ r ->getFileName ()).'/Resources/translations ' ;
869
883
}
870
- if (class_exists (' Symfony\Component\ Form\Form ' )) {
871
- $ r = new \ReflectionClass (' Symfony\Component\ Form\Form ' );
884
+ if (class_exists (Form::class )) {
885
+ $ r = new \ReflectionClass (Form::class );
872
886
873
887
$ dirs [] = dirname ($ r ->getFileName ()).'/Resources/translations ' ;
874
888
}
875
- if (class_exists ('Symfony\Component\Security\Core\Exception\AuthenticationException ' )) {
876
- $ r = new \ReflectionClass ('Symfony\Component\Security\Core\Exception\AuthenticationException ' );
889
+
890
+ $ container ->addResource (new ClassExistenceResource (AuthenticationException::class));
891
+ if (class_exists (AuthenticationException::class)) {
892
+ $ r = new \ReflectionClass (AuthenticationException::class);
877
893
878
894
$ dirs [] = dirname (dirname ($ r ->getFileName ())).'/Resources/translations ' ;
879
895
}
880
896
$ rootDir = $ container ->getParameter ('kernel.root_dir ' );
881
897
foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ name => $ bundle ) {
882
- if (is_dir ($ dir = $ bundle ['path ' ].'/Resources/translations ' )) {
898
+ $ container ->addResource (new FileExistenceResource ($ dir = $ bundle ['path ' ].'/Resources/translations ' ));
899
+ if (is_dir ($ dir )) {
883
900
$ dirs [] = $ dir ;
884
901
}
885
- if (is_dir ($ dir = $ rootDir .sprintf ('/Resources/%s/translations ' , $ name ))) {
902
+ $ container ->addResource (new FileExistenceResource ($ dir = $ rootDir .sprintf ('/Resources/%s/translations ' , $ name )));
903
+ if (is_dir ($ dir )) {
886
904
$ dirs [] = $ dir ;
887
905
}
888
906
}
889
907
890
908
foreach ($ config ['paths ' ] as $ dir ) {
909
+ $ container ->addResource (new FileExistenceResource ($ dir ));
891
910
if (is_dir ($ dir )) {
892
911
$ dirs [] = $ dir ;
893
912
} else {
894
913
throw new \UnexpectedValueException (sprintf ('%s defined in translator.paths does not exist or is not a directory ' , $ dir ));
895
914
}
896
915
}
897
916
898
- if (is_dir ($ dir = $ rootDir .'/Resources/translations ' )) {
917
+ $ container ->addResource (new FileExistenceResource ($ dir = $ rootDir .'/Resources/translations ' ));
918
+ if (is_dir ($ dir )) {
899
919
$ dirs [] = $ dir ;
900
920
}
901
921
@@ -946,7 +966,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
946
966
return ;
947
967
}
948
968
949
- if (!class_exists (' Symfony\Component\Validator\ Validation' )) {
969
+ if (!class_exists (Validation::class )) {
950
970
throw new LogicException ('Validation support cannot be enabled as the Validator component is not installed. ' );
951
971
}
952
972
@@ -958,7 +978,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
958
978
959
979
$ files = array ('xml ' => array (), 'yml ' => array ());
960
980
$ this ->getValidatorMappingFiles ($ container , $ files );
961
- $ this ->getValidatorMappingFilesFromConfig ($ config , $ files );
981
+ $ this ->getValidatorMappingFilesFromConfig ($ container , $ config , $ files );
962
982
963
983
if (!empty ($ files ['xml ' ])) {
964
984
$ validatorBuilder ->addMethodCall ('addXmlMappings ' , array ($ files ['xml ' ]));
@@ -1001,26 +1021,27 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
1001
1021
1002
1022
private function getValidatorMappingFiles (ContainerBuilder $ container , array &$ files )
1003
1023
{
1004
- if (interface_exists ( ' Symfony\Component\ Form\FormInterface ' )) {
1005
- $ reflClass = new \ReflectionClass (' Symfony\Component\ Form\FormInterface ' );
1024
+ if (class_exists ( Form::class )) {
1025
+ $ reflClass = new \ReflectionClass (Form::class );
1006
1026
$ files ['xml ' ][] = $ file = dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' ;
1007
1027
$ container ->addResource (new FileResource ($ file ));
1008
1028
}
1009
1029
1010
1030
foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ bundle ) {
1011
1031
$ dirname = $ bundle ['path ' ];
1012
1032
1013
- if (is_file ($ file = $ dirname .'/Resources/config/validation.yml ' )) {
1033
+ $ container ->addResource (new FileExistenceResource ($ file = $ dirname .'/Resources/config/validation.yml ' ));
1034
+ if (is_file ($ file )) {
1014
1035
$ files ['yml ' ][] = $ file ;
1015
- $ container ->addResource (new FileResource ($ file ));
1016
1036
}
1017
1037
1018
- if (is_file ($ file = $ dirname .'/Resources/config/validation.xml ' )) {
1038
+ $ container ->addResource (new FileExistenceResource ($ file = $ dirname .'/Resources/config/validation.xml ' ));
1039
+ if (is_file ($ file )) {
1019
1040
$ files ['xml ' ][] = $ file ;
1020
- $ container ->addResource (new FileResource ($ file ));
1021
1041
}
1022
1042
1023
- if (is_dir ($ dir = $ dirname .'/Resources/config/validation ' )) {
1043
+ $ container ->addResource (new FileExistenceResource ($ dir = $ dirname .'/Resources/config/validation ' ));
1044
+ if (is_dir ($ dir )) {
1024
1045
$ this ->getValidatorMappingFilesFromDir ($ dir , $ files );
1025
1046
$ container ->addResource (new DirectoryResource ($ dir ));
1026
1047
}
@@ -1035,9 +1056,10 @@ private function getValidatorMappingFilesFromDir($dir, array &$files)
1035
1056
}
1036
1057
}
1037
1058
1038
- private function getValidatorMappingFilesFromConfig (array $ config , array &$ files )
1059
+ private function getValidatorMappingFilesFromConfig (ContainerBuilder $ container , array $ config , array &$ files )
1039
1060
{
1040
1061
foreach ($ config ['mapping ' ]['paths ' ] as $ path ) {
1062
+ $ container ->addResource (new FileExistenceResource ($ path ));
1041
1063
if (is_dir ($ path )) {
1042
1064
$ this ->getValidatorMappingFilesFromDir ($ path , $ files );
1043
1065
} elseif (is_file ($ path )) {
@@ -1059,7 +1081,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
1059
1081
return ;
1060
1082
}
1061
1083
1062
- if (!class_exists ('Doctrine\Common\Annotations\Annotation ' )) {
1084
+ $ container ->addResource (new ClassExistenceResource (Annotation::class));
1085
+ if (!class_exists (Annotation::class)) {
1063
1086
throw new LogicException ('Annotations cannot be enabled as the Doctrine Annotation library is not installed. ' );
1064
1087
}
1065
1088
@@ -1130,6 +1153,7 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
1130
1153
return ;
1131
1154
}
1132
1155
1156
+ $ container ->addResource (new ClassExistenceResource (CsrfToken::class));
1133
1157
if (!class_exists ('Symfony\Component\Security\Csrf\CsrfToken ' )) {
1134
1158
throw new LogicException ('CSRF support cannot be enabled as the Security CSRF component is not installed. ' );
1135
1159
}
@@ -1151,33 +1175,38 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
1151
1175
*/
1152
1176
private function registerSerializerConfiguration (array $ config , ContainerBuilder $ container , XmlFileLoader $ loader )
1153
1177
{
1154
- if (class_exists ('Symfony\Component\Serializer\Normalizer\DataUriNormalizer ' )) {
1178
+ $ container ->addResource (new ClassExistenceResource (DataUriNormalizer::class));
1179
+ if (class_exists (DataUriNormalizer::class)) {
1155
1180
// Run after serializer.normalizer.object
1156
1181
$ definition = $ container ->register ('serializer.normalizer.data_uri ' , DataUriNormalizer::class);
1157
1182
$ definition ->setPublic (false );
1158
1183
$ definition ->addTag ('serializer.normalizer ' , array ('priority ' => -920 ));
1159
1184
}
1160
1185
1161
- if (class_exists ('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer ' )) {
1186
+ $ container ->addResource (new ClassExistenceResource (DateTimeNormalizer::class));
1187
+ if (class_exists (DateTimeNormalizer::class)) {
1162
1188
// Run before serializer.normalizer.object
1163
1189
$ definition = $ container ->register ('serializer.normalizer.datetime ' , DateTimeNormalizer::class);
1164
1190
$ definition ->setPublic (false );
1165
1191
$ definition ->addTag ('serializer.normalizer ' , array ('priority ' => -910 ));
1166
1192
}
1167
1193
1168
- if (class_exists ('Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer ' )) {
1194
+ $ container ->addResource (new ClassExistenceResource (JsonSerializableNormalizer::class));
1195
+ if (class_exists (JsonSerializableNormalizer::class)) {
1169
1196
// Run before serializer.normalizer.object
1170
1197
$ definition = $ container ->register ('serializer.normalizer.json_serializable ' , JsonSerializableNormalizer::class);
1171
1198
$ definition ->setPublic (false );
1172
1199
$ definition ->addTag ('serializer.normalizer ' , array ('priority ' => -900 ));
1173
1200
}
1174
1201
1202
+ $ container ->addResource (new ClassExistenceResource (YamlEncoder::class));
1175
1203
if (class_exists (YamlEncoder::class) && defined ('Symfony\Component\Yaml\Yaml::DUMP_OBJECT ' )) {
1176
1204
$ definition = $ container ->register ('serializer.encoder.yaml ' , YamlEncoder::class);
1177
1205
$ definition ->setPublic (false );
1178
1206
$ definition ->addTag ('serializer.encoder ' );
1179
1207
}
1180
1208
1209
+ $ container ->addResource (new ClassExistenceResource (CsvEncoder::class));
1181
1210
if (class_exists (CsvEncoder::class)) {
1182
1211
$ definition = $ container ->register ('serializer.encoder.csv ' , CsvEncoder::class);
1183
1212
$ definition ->setPublic (false );
@@ -1213,15 +1242,16 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
1213
1242
$ container ->addResource (new FileResource ($ file ));
1214
1243
}
1215
1244
1216
- if (is_file ($ file = $ dirname .'/Resources/config/serialization.yml ' )) {
1245
+ $ container ->addResource (new FileExistenceResource ($ file = $ dirname .'/Resources/config/serialization.yml ' ));
1246
+ if (is_file ($ file )) {
1217
1247
$ definition = new Definition ('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader ' , array ($ file ));
1218
1248
$ definition ->setPublic (false );
1219
1249
1220
1250
$ serializerLoaders [] = $ definition ;
1221
- $ container ->addResource (new FileResource ($ file ));
1222
1251
}
1223
1252
1224
- if (is_dir ($ dir = $ dirname .'/Resources/config/serialization ' )) {
1253
+ $ container ->addResource (new FileExistenceResource ($ dir = $ dirname .'/Resources/config/serialization ' ));
1254
+ if (is_dir ($ dir )) {
1225
1255
foreach (Finder::create ()->followLinks ()->files ()->in ($ dir )->name ('*.xml ' ) as $ file ) {
1226
1256
$ definition = new Definition ('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader ' , array ($ file ->getPathname ()));
1227
1257
$ definition ->setPublic (false );
0 commit comments