11
11
12
12
namespace Symfony \Bundle \FrameworkBundle \DependencyInjection ;
13
13
14
+ use Doctrine \Common \Annotations \Annotation ;
14
15
use Doctrine \Common \Annotations \Reader ;
16
+ use phpDocumentor \Reflection \DocBlockFactoryInterface ;
15
17
use Symfony \Bridge \Monolog \Processor \DebugProcessor ;
18
+ use Symfony \Component \Asset \Package ;
16
19
use Symfony \Component \Cache \Adapter \AdapterInterface ;
17
20
use Symfony \Component \Config \Loader \LoaderInterface ;
18
21
use Symfony \Component \DependencyInjection \Alias ;
26
29
use Symfony \Component \Config \Resource \FileResource ;
27
30
use Symfony \Component \Config \Resource \DirectoryResource ;
28
31
use Symfony \Component \Finder \Finder ;
32
+ use Symfony \Component \Form \Form ;
33
+ use Symfony \Component \Form \FormInterface ;
29
34
use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
30
35
use Symfony \Component \Config \FileLocator ;
31
- use Symfony \Component \Config \Resource \ClassExistenceResource ;
32
36
use Symfony \Component \PropertyAccess \PropertyAccessor ;
37
+ use Symfony \Component \Security \Core \Exception \AuthenticationException ;
33
38
use Symfony \Component \Serializer \Encoder \YamlEncoder ;
34
39
use Symfony \Component \Serializer \Encoder \CsvEncoder ;
35
40
use Symfony \Component \Serializer \Mapping \Factory \CacheClassMetadataFactory ;
36
41
use Symfony \Component \Serializer \Normalizer \DataUriNormalizer ;
37
42
use Symfony \Component \Serializer \Normalizer \DateTimeNormalizer ;
38
43
use Symfony \Component \Serializer \Normalizer \JsonSerializableNormalizer ;
44
+ use Symfony \Component \Templating \PhpEngine ;
45
+ use Symfony \Component \Translation \Translator ;
46
+ use Symfony \Component \Validator \Validation ;
39
47
use Symfony \Component \Workflow ;
40
48
use Symfony \Component \Workflow \SupportStrategy \ClassInstanceSupportStrategy ;
41
49
use Symfony \Component \Yaml \Yaml ;
@@ -85,8 +93,7 @@ public function load(array $configs, ContainerBuilder $container)
85
93
86
94
$ loader ->load ('fragment_renderer.xml ' );
87
95
88
- $ container ->addResource (new ClassExistenceResource (Application::class));
89
- if (class_exists (Application::class)) {
96
+ if ($ container ->classExists (Application::class)) {
90
97
$ loader ->load ('console.xml ' );
91
98
}
92
99
@@ -105,16 +112,18 @@ public function load(array $configs, ContainerBuilder $container)
105
112
// default in the Form and Validator component). If disabled, an identity
106
113
// translator will be used and everything will still work as expected.
107
114
if ($ this ->isConfigEnabled ($ container , $ config ['translator ' ]) || $ this ->isConfigEnabled ($ container , $ config ['form ' ]) || $ this ->isConfigEnabled ($ container , $ config ['validation ' ])) {
108
- if (!class_exists ('Symfony\Component\Transl
10000
ation\Translator ' ) && $ this ->isConfigEnabled ($ container , $ config ['translator ' ])) {
109
- throw new LogicException ('Translation support cannot be enabled as the Translation component is not installed. ' );
110
- }
115
+ if (!$ container ->classExists (Translator::class)) {
116
+ if ($ this ->isConfigEnabled ($ container , $ config ['translator ' ])) {
117
+ throw new LogicException ('Translation support cannot be enabled as the Translation component is not installed. ' );
118
+ }
111
119
112
- if (! class_exists ( ' Symfony\Component\Translation\Translator ' ) && $ this ->isConfigEnabled ($ container , $ config ['form ' ])) {
113
- throw new LogicException ('Form support cannot be enabled as the Translation component is not installed. ' );
114
- }
120
+ if ( $ this ->isConfigEnabled ($ container , $ config ['form ' ])) {
121
+ throw new LogicException ('Form support cannot be enabled as the Translation component is not installed. ' );
122
+ }
115
123
116
- if (!class_exists ('Symfony\Component\Translation\Translator ' ) && $ this ->isConfigEnabled ($ container , $ config ['validation ' ])) {
117
- throw new LogicException ('Validation support cannot be enabled as the Translation component is not installed. ' );
124
+ if ($ this ->isConfigEnabled ($ container , $ config ['validation ' ])) {
125
+ throw new LogicException ('Validation support cannot be enabled as the Translation component is not installed. ' );
126
+ }
118
127
}
119
128
120
129
$ loader ->load ('identity_translator.xml ' );
@@ -163,23 +172,23 @@ public function load(array $configs, ContainerBuilder $container)
163
172
$ this ->registerFormConfiguration ($ config , $ container , $ loader );
164
173
$ config ['validation ' ]['enabled ' ] = true ;
165
174
166
- if (!class_exists ( ' Symfony\Component\Validator\ Validation' )) {
175
+ if (!$ container -> classExists ( Validation::class )) {
167
176
throw new LogicException ('The Validator component is required to use the Form component. ' );
168
177
}
169
178
}
170
179
171
180
$ this ->registerSecurityCsrfConfiguration ($ config ['csrf_protection ' ], $ container , $ loader );
172
181
173
182
if ($ this ->isConfigEnabled ($ container , $ config ['assets ' ])) {
174
- if (!class_exists ( ' Symfony\Component\Asset\ Package' )) {
183
+ if (!$ container -> classExists ( Package::class )) {
175
184
throw new LogicException ('Asset support cannot be enabled as the Asset component is not installed. ' );
176
185
}
177
186
178
187
$ this ->registerAssetsConfiguration ($ config ['assets ' ], $ container , $ loader );
179
188
}
180
189
181
190
if ($ this ->isConfigEnabled ($ container , $ config ['templating ' ])) {
182
- if (!class_exists ( ' Symfony\Component\Templating\ PhpEngine' )) {
191
+ if (!$ container -> classExists ( PhpEngine::class )) {
183
192
throw new LogicException ('Templating support cannot be enabled as the Templating component is not installed. ' );
184
193
}
185
194
@@ -525,7 +534,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
525
534
$ definition ->replaceArgument (4 , $ debug );
526
535
$ definition ->replaceArgument (6 , $ debug );
527
536
528
- if ($ debug && class_exists (DebugProcessor::class)) {
537
+ if ($ debug && $ container -> classExists (DebugProcessor::class)) {
529
538
$ definition = new Definition (DebugProcessor::class);
530
539
$ definition ->setPublic (false );
531
540
$ container ->setDefinition ('debug.log_processor ' , $ definition );
@@ -860,18 +869,18 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
860
869
861
870
// Discover translation directories
862
871
$ dirs = array ();
863
- if (class_exists ( ' Symfony\Component\Validator\ Validation' )) {
864
- $ r = new \ReflectionClass (' Symfony\Component\Validator\ Validation' );
872
+ if ($ container -> classExists ( Validation::class )) {
873
+ $ r = new \ReflectionClass (Validation::class );
865
874
866
875
$ dirs [] = dirname ($ r ->getFileName ()).'/Resources/translations ' ;
867
876
}
868
- if (class_exists ( ' Symfony\Component\ Form\Form ' )) {
869
- $ r = new \ReflectionClass (' Symfony\Component\ Form\Form ' );
877
+ if ($ container -> classExists ( Form::class )) {
878
+ $ r = new \ReflectionClass (Form::class );
870
879
871
880
$ dirs [] = dirname ($ r ->getFileName ()).'/Resources/translations ' ;
872
881
}
873
- if (class_exists ( ' Symfony\Component\Security\Core\Exception\ AuthenticationException' )) {
874
- $ r = new \ReflectionClass (' Symfony\Component\Security\Core\Exception\ AuthenticationException' );
882
+ if ($ container -> classExists ( AuthenticationException::class )) {
883
+ $ r = new \ReflectionClass (AuthenticationException::class );
875
884
876
885
$ dirs [] = dirname (dirname ($ r ->getFileName ())).'/Resources/translations ' ;
877
886
}
@@ -944,7 +953,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
944
953
return ;
945
954
}
946
955
947
- if (!class_exists ( ' Symfony\Component\Validator\ Validation' )) {
956
+ if (!$ container -> classExists ( Validation::class )) {
948
957
throw new LogicException ('Validation support cannot be enabled as the Validator component is not installed. ' );
949
958
}
950
959
@@ -999,8 +1008,8 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
999
1008
1000
1009
private function getValidatorMappingFiles (ContainerBuilder $ container , array &$ files )
1001
1010
{
1002
- if (interface_exists ( ' Symfony\Component\Form\ FormInterface' )) {
1003
- $ reflClass = new \ReflectionClass (' Symfony\Component\Form\ FormInterface' );
1011
+ if ($ container -> classExists ( FormInterface::class )) {
1012
+ $ reflClass = new \ReflectionClass (FormInterface::class );
1004
1013
$ files ['xml ' ][] = $ file = dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' ;
1005
1014
$ container ->addResource (new FileResource ($ file ));
1006
1015
}
@@ -1057,7 +1066,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
1057
1066
return ;
1058
1067
}
1059
1068
1060
- if (!class_exists ( ' Doctrine\Common\Annotations\ Annotation' )) {
1069
+ if (!$ container -> classExists ( Annotation::class )) {
1061
1070
throw new LogicException ('Annotations cannot be enabled as the Doctrine Annotation library is not installed. ' );
1062
1071
}
1063
1072
@@ -1129,7 +1138,7 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
1129
1138
return ;
1130
1139
}
1131
1140
1132
- if (!class_exists ('Symfony\Component\Security\Csrf\CsrfToken ' )) {
1141
+ if (!$ container -> classExists ('Symfony\Component\Security\Csrf\CsrfToken ' )) {
1133
1142
throw new LogicException ('CSRF support cannot be enabled as the Security CSRF component is not installed. ' );
1134
1143
}
1135
1144
@@ -1150,34 +1159,34 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
1150
1159
*/
1151
1160
private function registerSerializerConfiguration (array $ config , ContainerBuilder $ container , XmlFileLoader $ loader )
1152
1161
{
1153
- if (class_exists ( ' Symfony\Component\Serializer\Normalizer\ DataUriNormalizer' )) {
1162
+ if ($ container -> classExists ( DataUriNormalizer::class )) {
1154
1163
// Run after serializer.normalizer.object
1155
1164
$ definition = $ container ->register ('serializer.normalizer.data_uri ' , DataUriNormalizer::class);
1156
1165
$ definition ->setPublic (false );
1157
1166
$ definition ->addTag ('serializer.normalizer ' , array ('priority ' => -920 ));
1158
1167
}
1159
1168
1160
- if (class_exists ( ' Symfony\Component\Serializer\Normalizer\ DateTimeNormalizer' )) {
1169
+ if ($ container -> classExists ( DateTimeNormalizer::class )) {
1161
1170
// Run before serializer.normalizer.object
1162
1171
$ definition = $ container ->register ('serializer.normalizer.datetime ' , DateTimeNormalizer::class);
1163
1172
$ definition ->setPublic (false );
1164
1173
$ definition ->addTag ('serializer.normalizer ' , array ('priority ' => -910 ));
1165
1174
}
1166
1175
1167
- if (class_exists ( ' Symfony\Component\Serializer\Normalizer\ JsonSerializableNormalizer' )) {
1176
+ if ($ container -> classExists ( JsonSerializableNormalizer::class )) {
1168
1177
// Run before serializer.normalizer.object
1169
1178
$ definition = $ container ->register ('serializer.normalizer.json_serializable ' , JsonSerializableNormalizer::class);
1170
1179
$ definition ->setPublic (false );
1171
1180
$ definition ->addTag ('serializer.normalizer ' , array ('priority ' => -900 ));
1172
1181
}
1173
1182
1174
- if (class_exists (YamlEncoder::class) && defined ('Symfony\Component\Yaml\Yaml::DUMP_OBJECT ' )) {
1183
+ if ($ container -> classExists (YamlEncoder::class) && defined ('Symfony\Component\Yaml\Yaml::DUMP_OBJECT ' )) {
1175
1184
$ definition = $ container ->register ('serializer.encoder.yaml ' , YamlEncoder::class);
1176
1185
$ definition ->setPublic (false );
1177
1186
$ definition ->addTag ('serializer.encoder ' );
1178
1187
}
1179
1188
1180
- if (class_exists (CsvEncoder::class)) {
1189
+ if ($ container -> classExists (CsvEncoder::class)) {
1181
1190
$ definition = $ container ->register ('serializer.encoder.csv ' , CsvEncoder::class);
1182
1191
$ definition ->setPublic (false );
1183
1192
$ definition ->addTag ('serializer.encoder ' );
@@ -1252,7 +1261,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
1252
1261
$ container ->getDefinition ('serializer.mapping.class_metadata_factory ' )->replaceArgument (
1253
1262
1 , new Reference ($ config ['cache ' ])
1254
1263
);
1255
- } elseif (!$ container ->getParameter ('kernel.debug ' ) && class_exists (CacheClassMetadataFactory::class)) {
1264
+ } elseif (!$ container ->getParameter ('kernel.debug ' ) && $ container -> classExists (CacheClassMetadataFactory::class)) {
1256
1265
$ cacheMetadataFactory = new Definition (
1257
1266
CacheClassMetadataFactory::class,
1258
1267
array (
@@ -1282,7 +1291,7 @@ private function registerPropertyInfoConfiguration(array $config, ContainerBuild
1282
1291
{
1283
1292
$ loader ->load ('property_info.xml ' );
1284
1293
1285
- if (interface_exists ( ' phpDocumentor\Reflection\ DocBlockFactoryInterface' )) {
1294
+ if ($ container -> classExists ( DocBlockFactoryInterface::class )) {
1286
1295
$ definition = $ container ->register ('property_info.php_doc_extractor ' , 'Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor ' );
1287
1296
$ definition ->addTag ('property_info.description_extractor ' , array ('priority ' =
10000
> -1000 ));
1288
1297
$ definition ->addTag ('property_info.type_extractor ' , array ('priority ' => -1001 ));
@@ -1324,7 +1333,7 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
1324
1333
$ container ->setDefinition ($ name , $ definition );
1325
1334
}
1326
1335
1327
- if (method_exists (PropertyAccessor::class, 'createCache ' )) {
1336
+ if ($ container -> classExists (PropertyAccessor::class) && method_exists (PropertyAccessor::class, 'createCache ' )) {
1328
1337
$ propertyAccessDefinition = $ container ->register ('cache.property_access ' , AdapterInterface::class);
1329
1338
$ propertyAccessDefinition ->setPublic (false );
1330
1339
$ propertyAccessDefinition ->setFactory (array (PropertyAccessor::class, 'createCache ' ));
0 commit comments