1212namespace Symfony \Bundle \FrameworkBundle \DependencyInjection ;
1313
1414use Doctrine \Common \Annotations \Reader ;
15+ use Doctrine \Common \Annotations \Annotation ;
1516use Symfony \Bridge \Monolog \Processor \DebugProcessor ;
1617use Symfony \Component \Cache \Adapter \AdapterInterface ;
1718use Symfony \Component \Config \Loader \LoaderInterface ;
2930use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
3031use Symfony \Component \Config \FileLocator ;
3132use Symfony \Component \Config \Resource \ClassExistenceResource ;
33+ use Symfony \Component \Config \Resource \FileExistenceResource ;
3234use Symfony \Component \PropertyAccess \PropertyAccessor ;
3335use Symfony \Component \Serializer \Encoder \YamlEncoder ;
3436use Symfony \Component \Serializer \Encoder \CsvEncoder ;
4143use Symfony \Component \Yaml \Yaml ;
4244use Symfony \Component \Console \Application ;
4345use 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 ;
4450
4551/**
4652 * FrameworkExtension.
@@ -106,7 +112,6 @@ public function load(array $configs, ContainerBuilder $container)
106112// default in the Form and Validator component). If disabled, an identity
107113// translator will be used and everything will still work as expected.
108114if ($ this ->isConfigEnabled ($ container ,$ config ['translator ' ]) ||$ this ->isConfigEnabled ($ container ,$ config ['form ' ]) ||$ this ->isConfigEnabled ($ container ,$ config ['validation ' ])) {
109- $ container ->addResource (new ClassExistenceResource (Translator::class));
110115if (!class_exists (Translator::class) &&$ this ->isConfigEnabled ($ container ,$ config ['translator ' ])) {
111116throw new LogicException ('Translation support cannot be enabled as the Translation component is not installed. ' );
112117 }
@@ -160,12 +165,15 @@ public function load(array $configs, ContainerBuilder $container)
160165$ this ->registerRequestConfiguration ($ config ['request ' ],$ container ,$ loader );
161166 }
162167
168+ $ container ->addResource (new ClassExistenceResource (Validation::class));
169+ $ container ->addResource (new ClassExistenceResource (Form::class));
170+
163171if ($ this ->isConfigEnabled ($ container ,$ config ['form ' ])) {
164172$ this ->formConfigEnabled =true ;
165173$ this ->registerFormConfiguration ($ config ,$ container ,$ loader );
166174$ config ['validation ' ]['enabled ' ] =true ;
167175
168- if (!class_exists (' Symfony\Component\Validator\ Validation' )) {
176+ if (!class_exists (Validation::class )) {
169177throw new LogicException ('The Validator component is required to use the Form component. ' );
170178 }
171179 }
@@ -527,6 +535,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
527535$ definition ->replaceArgument (4 ,$ debug );
528536$ definition ->replaceArgument (6 ,$ debug );
529537
538+ $ container ->addResource (new ClassExistenceResource (DebugProcessor::class));
530539if ($ debug &&class_exists (DebugProcessor::class)) {
531540$ definition =new Definition (DebugProcessor::class);
532541$ definition ->setPublic (false );
@@ -862,41 +871,51 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
862871
863872// Discover translation directories
864873$ 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 );
867876
868877$ dirs [] =dirname ($ r ->getFileName ()).'/Resources/translations ' ;
869878 }
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 );
872881
873882$ dirs [] =dirname ($ r ->getFileName ()).'/Resources/translations ' ;
874883 }
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);
877888
878889$ dirs [] =dirname (dirname ($ r ->getFileName ())).'/Resources/translations ' ;
879890 }
880891$ rootDir =$ container ->getParameter ('kernel.root_dir ' );
881892foreach ($ container ->getParameter ('kernel.bundles_metadata ' )as $ name =>$ bundle ) {
882893if (is_dir ($ dir =$ bundle ['path ' ].'/Resources/translations ' )) {
883894$ dirs [] =$ dir ;
895+ }else {
896+ $ container ->addResource (new FileExistenceResource ($ dir ));
884897 }
885898if (is_dir ($ dir =$ rootDir .sprintf ('/Resources/%s/translations ' ,$ name ))) {
886899$ dirs [] =$ dir ;
900+ }else {
901+ $ container ->addResource (new FileExistenceResource ($ dir ));
887902 }
888903 }
889904
890905foreach ($ config ['paths ' ]as $ dir ) {
891906if (is_dir ($ dir )) {
892907$ dirs [] =$ dir ;
893908 }else {
909+ $ container ->addResource (new FileExistenceResource ($ dir ));
910+
894911throw new \UnexpectedValueException (sprintf ('%s defined in translator.paths does not exist or is not a directory ' ,$ dir ));
895912 }
896913 }
897914
898915if (is_dir ($ dir =$ rootDir .'/Resources/translations ' )) {
899916$ dirs [] =$ dir ;
917+ }else {
918+ $ container ->addResource (new FileExistenceResource ($ dir ));
900919 }
901920
902921// Register translation resources
@@ -946,7 +965,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
946965return ;
947966 }
948967
949- if (!class_exists (' Symfony\Component\Validator\ Validation' )) {
968+ if (!class_exists (Validation::class )) {
950969throw new LogicException ('Validation support cannot be enabled as the Validator component is not installed. ' );
951970 }
952971
@@ -958,7 +977,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
958977
959978$ files =array ('xml ' =>array (),'yml ' =>array ());
960979$ this ->getValidatorMappingFiles ($ container ,$ files );
961- $ this ->getValidatorMappingFilesFromConfig ($ config ,$ files );
980+ $ this ->getValidatorMappingFilesFromConfig ($ container , $ config ,$ files );
962981
963982if (!empty ($ files ['xml ' ])) {
964983$ validatorBuilder ->addMethodCall ('addXmlMappings ' ,array ($ files ['xml ' ]));
@@ -1001,26 +1020,27 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
10011020
10021021private function getValidatorMappingFiles (ContainerBuilder $ container ,array &$ files )
10031022 {
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 );
10061025$ files ['xml ' ][] =$ file =dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' ;
10071026$ container ->addResource (new FileResource ($ file ));
10081027 }
10091028
10101029foreach ($ container ->getParameter ('kernel.bundles_metadata ' )as $ bundle ) {
10111030$ dirname =$ bundle ['path ' ];
10121031
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 )) {
10141034$ files ['yml ' ][] =$ file ;
1015- $ container ->addResource (new FileResource ($ file ));
10161035 }
10171036
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 )) {
10191039$ files ['xml ' ][] =$ file ;
1020- $ container ->addResource (new FileResource ($ file ));
10211040 }
10221041
1023- if (is_dir ($ dir =$ dirname .'/Resources/config/validation ' )) {
1042+ $ container ->addResource (new FileExistenceResource ($ dir =$ dirname .'/Resources/config/validation ' ));
1043+ if (is_dir ($ dir )) {
10241044$ this ->getValidatorMappingFilesFromDir ($ dir ,$ files );
10251045$ container ->addResource (new DirectoryResource ($ dir ));
10261046 }
@@ -1035,9 +1055,10 @@ private function getValidatorMappingFilesFromDir($dir, array &$files)
10351055 }
10361056 }
10371057
1038- private function getValidatorMappingFilesFromConfig (array $ config ,array &$ files )
1058+ private function getValidatorMappingFilesFromConfig (ContainerBuilder $ container , array $ config ,array &$ files )
10391059 {
10401060foreach ($ config ['mapping ' ]['paths ' ]as $ path ) {
1061+ $ container ->addResource (new FileExistenceResource ($ path ));
10411062if (is_dir ($ path )) {
10421063$ this ->getValidatorMappingFilesFromDir ($ path ,$ files );
10431064 }elseif (is_file ($ path )) {
@@ -1059,7 +1080,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
10591080return ;
10601081 }
10611082
1062- if (!class_exists ('Doctrine\Common\Annotations\Annotation ' )) {
1083+ $ container ->addResource (new ClassExistenceResource (Annotation::class));
1084+ if (!class_exists (Annotation::class)) {
10631085throw new LogicException ('Annotations cannot be enabled as the Doctrine Annotation library is not installed. ' );
10641086 }
10651087
@@ -1130,6 +1152,7 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
11301152return ;
11311153 }
11321154
1155+ $ container ->addResource (new ClassExistenceResource (CsrfToken::class));
11331156if (!class_exists ('Symfony\Component\Security\Csrf\CsrfToken ' )) {
11341157throw new LogicException ('CSRF support cannot be enabled as the Security CSRF component is not installed. ' );
11351158 }
@@ -1151,33 +1174,38 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
11511174 */
11521175private function registerSerializerConfiguration (array $ config ,ContainerBuilder $ container ,XmlFileLoader $ loader )
11531176 {
1154- if (class_exists ('Symfony\Component\Serializer\Normalizer\DataUriNormalizer ' )) {
1177+ $ container ->addResource (new ClassExistenceResource (DataUriNormalizer::class));
1178+ if (class_exists (DataUriNormalizer::class)) {
11551179// Run after serializer.normalizer.object
11561180$ definition =$ container ->register ('serializer.normalizer.data_uri ' , DataUriNormalizer::class);
11571181$ definition ->setPublic (false );
11581182$ definition ->addTag ('serializer.normalizer ' ,array ('priority ' => -920 ));
11591183 }
11601184
1161- if (class_exists ('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer ' )) {
1185+ $ container ->addResource (new ClassExistenceResource (DateTimeNormalizer::class));
1186+ if (class_exists (DateTimeNormalizer::class)) {
11621187// Run before serializer.normalizer.object
11631188$ definition =$ container ->register ('serializer.normalizer.datetime ' , DateTimeNormalizer::class);
11641189$ definition ->setPublic (false );
11651190$ definition ->addTag ('serializer.normalizer ' ,array ('priority ' => -910 ));
11661191 }
11671192
1168- if (class_exists ('Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer ' )) {
1193+ $ container ->addResource (new ClassExistenceResource (JsonSerializableNormalizer::class));
1194+ if (class_exists (JsonSerializableNormalizer::class)) {
11691195// Run before serializer.normalizer.object
11701196$ definition =$ container ->register ('serializer.normalizer.json_serializable ' , JsonSerializableNormalizer::class);
11711197$ definition ->setPublic (false );
11721198$ definition ->addTag ('serializer.normalizer ' ,array ('priority ' => -900 ));
11731199 }
11741200
1201+ $ container ->addResource (new ClassExistenceResource (YamlEncoder::class));
11751202if (class_exists (YamlEncoder::class) &&defined ('Symfony\Component\Yaml\Yaml::DUMP_OBJECT ' )) {
11761203$ definition =$ container ->register ('serializer.encoder.yaml ' , YamlEncoder::class);
11771204$ definition ->setPublic (false );
11781205$ definition ->addTag ('serializer.encoder ' );
11791206 }
11801207
1208+ $ container ->addResource (new ClassExistenceResource (CsvEncoder::class));
11811209if (class_exists (CsvEncoder::class)) {
11821210$ definition =$ container ->register ('serializer.encoder.csv ' , CsvEncoder::class);
11831211$ definition ->setPublic (false );
@@ -1213,12 +1241,12 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
12131241$ container ->addResource (new FileResource ($ file ));
12141242 }
12151243
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 )) {
12171246$ definition =new Definition ('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader ' ,array ($ file ));
12181247$ definition ->setPublic (false );
12191248
12201249$ serializerLoaders [] =$ definition ;
1221- $ container ->addResource (new FileResource ($ file ));
12221250 }
12231251
12241252if (is_dir ($ dir =$ dirname .'/Resources/config/serialization ' )) {
@@ -1236,6 +1264,8 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
12361264 }
12371265
12381266$ container ->addResource (new DirectoryResource ($ dir ));
1267+ }else {
1268+ $ container ->addResource (new FileExistenceResource ($ dir ));
12391269 }
12401270 }
12411271