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 ;
34
+ use Symfony \Component \Config \Resource \DirectoryExistenceResource ;
32
35
use Symfony \Component \PropertyAccess \PropertyAccessor ;
33
36
use Symfony \Component \Serializer \Encoder \YamlEncoder ;
34
37
use Symfony \Component \Serializer \Encoder \CsvEncoder ;
41
44
use Symfony \Component \Yaml \Yaml ;
42
45
use Symfony \Component \Console \Application ;
43
46
use Symfony \Component \Translation \Translator ;
47
+ use Symfony \Component \Validator \Validation ;
48
+ use Symfony \Component \Templating \PhpEngine ;
49
+ use Symfony \Component \Security \Csrf \CsrfToken ;
50
+ use Symfony \Component \Security \Core \Exception \AuthenticationException ;
51
+ use Symfony \Component \Form \Form ;
44
52
45
53
/**
46
54
* FrameworkExtension.
@@ -160,12 +168,14 @@ 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
+
163
173
if ($ this ->isConfigEnabled ($ container , $ config ['form ' ])) {
164
174
$ this ->formConfigEnabled = true ;
165
175
$ this ->registerFormConfiguration ($ config , $ container , $ loader );
166
176
$ config ['validation ' ]['enabled ' ] = true ;
167
177
168
- if (!class_exists (' Symfony\Component\Validator\ Validation' )) {
178
+ if (!class_exists (Validation::class )) {
169
179
throw new LogicException ('The Validator component is required to use the Form component. ' );
170
180
}
171
181
}
@@ -181,7 +191,8 @@ public function load(array $configs, ContainerBuilder $container)
181
191
}
182
192
183
193
if ($ this ->isConfigEnabled ($ container , $ config ['templating ' ])) {
184
- if (!class_exists ('Symfony\Component\Templating\PhpEngine ' )) {
194
+ $ container ->addResource (new ClassExistenceResource (PhpEngine::class));
195
+ if (!class_exists (PhpEngine::class)) {
185
196
throw new LogicException ('Templating support cannot be enabled as the Templating component is not installed. ' );
186
197
}
187
198
@@ -862,18 +873,20 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
862
873
863
874
// Discover translation directories
864
875
$ dirs = array ();
865
- if (class_exists (' Symfony\Component\Validator\ Validation' )) {
866
- $ r = new \ReflectionClass (' Symfony\Component\Validator\ Validation' );
876
+ if (class_exists (Validation::class )) {
877
+ $ r = new \ReflectionClass (Validation::class );
867
878
868
879
$ dirs [] = dirname ($ r ->getFileName ()).'/Resources/translations ' ;
869
880
}
870
- if (class_exists (' Symfony\Component\ Form\Form ' )) {
871
- $ r = new \ReflectionClass (' Symfony\Component\ Form\Form ' );
881
+ if (class_exists (Form::class )) {
882
+ $ r = new \ReflectionClass (Form::class );
872
883
873
884
$ dirs [] = dirname ($ r ->getFileName ()).'/Resources/translations ' ;
874
885
}
875
- if (class_exists ('Symfony\Component\Security\Core\Exception\AuthenticationException ' )) {
876
- $ r = new \ReflectionClass ('Symfony\Component\Security\Core\Exception\AuthenticationException ' );
886
+
887
+ $ container ->addResource (new ClassExistenceResource (AuthenticationException::class));
888
+ if (class_exists (AuthenticationException::class)) {
889
+ $ r = new \ReflectionClass (AuthenticationException::class);
877
890
878
891
$ dirs [] = dirname (dirname ($ r ->getFileName ())).'/Resources/translations ' ;
879
892
}
@@ -902,6 +915,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
902
915
// Register translation resources
903
916
if ($ dirs ) {
904
917
foreach ($ dirs as $ dir ) {
918
+ $ container ->addResource (new DirectoryExistenceResource ($ dir ));
905
919
$ container ->addResource (new DirectoryResource ($ dir ));
906
920
}
907
921
@@ -946,7 +960,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
946
960
return ;
947
961
}
948
962
949
- if (!class_exists (' Symfony\Component\Validator\ Validation' )) {
963
+ if (!class_exists (Validation::class )) {
950
964
throw new LogicException ('Validation support cannot be enabled as the Validator component is not installed. ' );
951
965
}
952
966
@@ -958,7 +972,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
958
972
959
973
$ files = array ('xml ' => array (), 'yml ' => array ());
960
974
$ this ->getValidatorMappingFiles ($ container , $ files );
961
- $ this ->getValidatorMappingFilesFromConfig ($ config , $ files );
975
+ $ this ->getValidatorMappingFilesFromConfig ($ container , $ config , $ files );
962
976
963
977
if (!empty ($ files ['xml ' ])) {
964
978
$ validatorBuilder ->addMethodCall ('addXmlMappings ' , array ($ files ['xml ' ]));
@@ -1001,26 +1015,30 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
1001
1015
1002
1016
private function getValidatorMappingFiles (ContainerBuilder $ container , array &$ files )
1003
1017
{
1004
- if (interface_exists ('Symfony\Component\Form\FormInterface ' )) {
1005
- $ reflClass = new \ReflectionClass ('Symfony\Component\Form\FormInterface ' );
1018
+ $ container ->addResource (new ClassExistenceResource (Form::class));
1019
+ if (class_exists (Form::class)) {
1020
+ $ reflClass = new \ReflectionClass (Form::class);
1006
1021
$ files ['xml ' ][] = $ file = dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' ;
1007
1022
$ container ->addResource (new FileResource ($ file ));
1008
1023
}
1009
1024
1010
1025
foreach ($ container ->getParameter ('kernel.bundles_metadata ' ) as $ bundle ) {
1011
1026
$ dirname = $ bundle ['path ' ];
1012
1027
1013
- if (is_file ($ file = $ dirname .'/Resources/config/validation.yml ' )) {
1028
+ $ container ->addResource (new FileExistenceResource ($ file = $ dirname .'/Resources/config/validation.yml ' ));
1029
+ if (is_file ($ file )) {
1014
1030
$ files ['yml ' ][] = $ file ;
1015
1031
$ container ->addResource (new FileResource ($ file ));
1016
1032
}
1017
1033
1018
- if (is_file ($ file = $ dirname .'/Resources/config/validation.xml ' )) {
1034
+ $ container ->addResource (new FileExistenceResource ($ file = $ dirname .'/Resources/config/validation.xml ' ));
1035
+ if (is_file ($ file )) {
1019
1036
$ files ['xml ' ][] = $ file ;
1020
1037
$ container ->addResource (new FileResource ($ file ));
1021
1038
}
1022
1039
1023
- if (is_dir ($ dir = $ dirname .'/Resources/config/validation ' )) {
1040
+ $ container ->addResource (new DirectoryExistenceResource ($ dir = $ dirname .'/Resources/config/validation ' ));
1041
+ if (is_dir ($ dir )) {
1024
1042
$ this ->getValidatorMappingFilesFromDir ($ dir , $ files );
1025
1043
$ container ->addResource (new DirectoryResource ($ dir ));
1026
1044
}
@@ -1035,12 +1053,14 @@ private function getValidatorMappingFilesFromDir($dir, array &$files)
1035
1053
}
1036
1054
}
1037
1055
1038
- private function getValidatorMappingFilesFromConfig (array $ config , array &$ files )
1056
+ private function getValidatorMappingFilesFromConfig (ContainerBuilder $ container , array $ config , array &$ files )
1039
1057
{
1040
1058
foreach ($ config ['mapping ' ]['paths ' ] as $ path ) {
1041
1059
if (is_dir ($ path )) {
1060
+ $ container ->addResource (new DirectoryExistenceResource ($ path ));
1042
1061
$ this ->getValidatorMappingFilesFromDir ($ path , $ files );
1043
1062
} elseif (is_file ($ path )) {
1063
+ $ container ->addResource (new FileExistenceResource ($ path ));
1044
1064
if (preg_match ('/\.(xml|ya?ml)$/ ' , $ path , $ matches )) {
1045
1065
$ extension = $ matches [1 ];
1046
1066
$ files ['yaml ' === $ extension ? 'yml ' : $ extension ][] = $ 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 );
@@ -1219,9 +1246,11 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
1219
1246
1220
1247
$ serializerLoaders [] = $ definition ;
1221
1248
$ container ->addResource (new FileResource ($ file ));
1249
+ $ container ->addResource (new FileExistenceResource ($ file ));
1222
1250
}
1223
1251
1224
- if (is_dir ($ dir = $ dirname .'/Resources/config/serialization ' )) {
1252
+ $ container ->addResource (new DirectoryExistenceResource ($ dir = $ dirname .'/Resources/config/serialization ' ));
1253
+ if (is_dir ($ dir )) {
1225
1254
foreach (Finder::create ()->followLinks ()->files ()->in ($ dir )->name ('*.xml ' ) as $ file ) {
1226
1255
$ definition = new Definition ('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader ' , array ($ file ->getPathname ()));
1227
1256
$ definition ->setPublic (false );
0 commit comments