@@ -37,6 +37,7 @@ class FrameworkExtension extends Extension
3737 private $ formConfigEnabled = false ;
3838 private $ translationConfigEnabled = false ;
3939 private $ sessionConfigEnabled = false ;
40+ private $ propertyAccessConfigEnabled = false ;
4041
4142 /**
4243 * @var string|null
@@ -80,12 +81,17 @@ public function load(array $configs, ContainerBuilder $container)
8081 $ loader ->load ('test.xml ' );
8182 }
8283
83- if ($ config ['session ' ][ ' enabled ' ] ) {
84+ if ($ this -> isConfigEnabled ( $ container , $ config ['session ' ]) ) {
8485 $ this ->sessionConfigEnabled = true ;
8586 $ this ->registerSessionConfiguration ($ config ['session ' ], $ container , $ loader );
8687 }
8788
88- if ($ config ['request ' ]['enabled ' ]) {
89+ if ($ this ->isConfigEnabled ($ container , $ config ['property_access ' ])) {
90+ $ this ->propertyAccessConfigEnabled = true ;
91+ $ this ->registerPropertyAccessConfiguration ($ config ['property_access ' ], $ container , $ loader );
92+ }
93+
94+ if ($ this ->isConfigEnabled ($ container , $ config ['request ' ])) {
8995 $ this ->registerRequestConfiguration ($ config ['request ' ], $ container , $ loader );
9096 }
9197
@@ -99,38 +105,52 @@ public function load(array $configs, ContainerBuilder $container)
99105 }
100106 }
101107
102- $ this ->registerSecurityCsrfConfiguration ($ config ['csrf_protection ' ], $ container , $ loader );
108+ if ($ this ->isConfigEnabled ($ container , $ config ['csrf_protection ' ])) {
109+ $ this ->registerSecurityCsrfConfiguration ($ config ['csrf_protection ' ], $ container , $ loader );
110+ }
103111
104- if ($ config ['assets ' ][ ' enabled ' ] ) {
112+ if ($ this -> isConfigEnabled ( $ container , $ config ['assets ' ]) ) {
105113 $ this ->registerAssetsConfiguration ($ config ['assets ' ], $ container , $ loader );
106114 }
107115
108- if ($ config ['templating ' ][ ' enabled ' ] ) {
116+ if ($ this -> isConfigEnabled ( $ container , $ config ['templating ' ]) ) {
109117 $ this ->registerTemplatingConfiguration ($ config ['templating ' ], $ config ['ide ' ], $ container , $ loader );
110118 }
111119
112- $ this ->registerValidationConfiguration ($ config , $ container , $ loader );
113- $ this ->registerEsiConfiguration ($ config ['esi ' ], $ container , $ loader );
114- $ this ->registerSsiConfiguration ($ config ['ssi ' ], $ container , $ loader );
115- $ this ->registerFragmentsConfiguration ($ config ['fragments ' ], $ container , $ loader );
116- $ this ->registerTranslatorConfiguration ($ config ['translator ' ], $ container );
120+ if ($ this ->isConfigEnabled ($ container , $ config ['validation ' ])) {
121+ $ this ->registerValidationConfiguration ($ config ['validation ' ], $ container , $ loader );
122+ }
123+
124+ if ($ this ->isConfigEnabled ($ container , $ config ['esi ' ])) {
125+ $ loader ->load ('esi.xml ' );
126+ }
127+
128+ if ($ this ->isConfigEnabled ($ container , $ config ['ssi ' ])) {
129+ $ loader ->load ('ssi.xml ' );
130+ }
131+
132+ if ($ this ->isConfigEnabled ($ container , $ config ['fragments ' ])) {
133+ $ this ->registerFragmentsConfiguration ($ config ['fragments ' ], $ container , $ loader );
134+ }
135+
136+ if ($ this ->isConfigEnabled ($ container , $ config ['translator ' ])) {
137+ $ this ->translationConfigEnabled = true ;
138+ $ this ->registerTranslatorConfiguration ($ config ['translator ' ], $ container );
139+ }
140+
117141 $ this ->registerProfilerConfiguration ($ config ['profiler ' ], $ container , $ loader );
118142
119- if ($ config ['router ' ][ ' enabled ' ] ) {
143+ if ($ this -> isConfigEnabled ( $ container , $ config ['router ' ]) ) {
120144 $ this ->registerRouterConfiguration ($ config ['router ' ], $ container , $ loader );
121145 }
122146
123147 $ this ->registerAnnotationsConfiguration ($ config ['annotations ' ], $ container , $ loader );
124148
125- if ($ this ->isConfigEnabled ($ container , $ config ['property_access ' ])) {
126- $ this ->registerPropertyAccessConfiguration ($ config ['property_access ' ], $ container , $ loader );
127- }
128-
129- if (isset ($ config ['serializer ' ])) {
149+ if ($ this ->isConfigEnabled ($ container , $ config ['serializer ' ])) {
130150 $ this ->registerSerializerConfiguration ($ config , $ container , $ loader );
131151 }
132152
133- if (isset ( $ config ['property_info ' ])) {
153+ if ($ this -> isConfigEnabled ( $ container , $ config ['property_info ' ])) {
134154 $ this ->registerPropertyInfoConfiguration ($ config ['property_info ' ], $ container , $ loader );
135155 }
136156
@@ -204,7 +224,7 @@ public function getConfiguration(array $config, ContainerBuilder $container)
204224 */
205225 private function registerFormConfiguration ($ config , ContainerBuilder $ container , XmlFileLoader $ loader )
206226 {
207- if (!$ this ->isConfigEnabled ( $ container , $ config [ ' property_access ' ]) ) {
227+ if (!$ this ->propertyAccessConfigEnabled ) {
208228 throw new LogicException ('"framework.property_access" must be enabled when "framework.form" is enabled. ' );
209229 }
210230
@@ -223,22 +243,6 @@ private function registerFormConfiguration($config, ContainerBuilder $container,
223243 }
224244 }
225245
226- /**
227- * Loads the ESI configuration.
228- *
229- * @param array $config An ESI configuration array
230- * @param ContainerBuilder $container A ContainerBuilder instance
231- * @param XmlFileLoader $loader An XmlFileLoader instance
232- */
233- private function registerEsiConfiguration (array $ config , ContainerBuilder $ container , XmlFileLoader $ loader )
234- {
235- if (!$ this ->isConfigEnabled ($ container , $ config )) {
236- return ;
237- }
238-
239- $ loader ->load ('esi.xml ' );
240- }
241-
242246 /**
243247 * Loads the SSI configuration.
244248 *
@@ -650,11 +654,6 @@ private function createVersion(ContainerBuilder $container, $version, $format, $
650654 */
651655 private function registerTranslatorConfiguration (array $ config , ContainerBuilder $ container )
652656 {
653- if (!$ this ->isConfigEnabled ($ container , $ config )) {
654- return ;
655- }
656- $ this ->translationConfigEnabled = true ;
657-
658657 // Use the "real" translator instead of the identity default
659658 $ container ->setAlias ('translator ' , 'translator.default ' );
660659 $ translator = $ container ->findDefinition ('translator.default ' );
@@ -745,16 +744,14 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
745744 */
746745 private function registerValidationConfiguration (array $ config , ContainerBuilder $ container , XmlFileLoader $ loader )
747746 {
748- if (!$ this ->isConfigEnabled ($ container , $ config[ ' validation ' ] )) {
747+ if (!$ this ->isConfigEnabled ($ container , $ config )) {
749748 return ;
750749 }
751750
752- if (!$ this ->isConfigEnabled ( $ container , $ config [ ' property_access ' ]) ) {
751+ if (!$ this ->propertyAccessConfigEnabled ) {
753752 throw new LogicException ('"framework.property_access" must be enabled when "framework.validator" is enabled. ' );
754753 }
755754
756- $ config = $ config ['validation ' ];
757-
758755 $ loader ->load ('validator.xml ' );
759756
760757 $ validatorBuilder = $ container ->getDefinition ('validator.builder ' );
@@ -882,10 +879,6 @@ private function registerPropertyAccessConfiguration(array $config, ContainerBui
882879 */
883880 private function registerSecurityCsrfConfiguration (array $ config , ContainerBuilder $ container , XmlFileLoader $ loader )
884881 {
885- if (!$ this ->isConfigEnabled ($ container , $ config )) {
886- return ;
887- }
888-
889882 if (!$ this ->sessionConfigEnabled ) {
890883 throw new \LogicException ('CSRF protection needs sessions to be enabled. ' );
891884 }
@@ -903,11 +896,7 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
903896 */
904897 private function registerSerializerConfiguration (array $ config , ContainerBuilder $ container , XmlFileLoader $ loader )
905898 {
906- if (!$ config ['serializer ' ]['enabled ' ]) {
907- return ;
908- }
909-
910- if (!$ this ->isConfigEnabled ($ container , $ config ['property_access ' ])) {
899+ if (!$ this ->propertyAccessConfigEnabled ) {
911900 throw new LogicException ('"framework.property_access" must be enabled when "framework.serializer" is enabled. ' );
912901 }
913902
@@ -993,10 +982,6 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
993982 */
994983 private function registerPropertyInfoConfiguration (array $ config , ContainerBuilder $ container , XmlFileLoader $ loader )
995984 {
996- if (!$ config ['enabled ' ]) {
997- return ;
998- }
999-
1000985 $ loader ->load ('property_info.xml ' );
1001986
1002987 if (class_exists ('phpDocumentor\Reflection\ClassReflector ' )) {
0 commit comments