21
21
use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
22
22
use Symfony \Component \Config \Definition \ConfigurationInterface ;
23
23
use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
24
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
24
25
use Symfony \Component \DependencyInjection \Exception \LogicException ;
25
26
use Symfony \Component \Form \Form ;
26
27
use Symfony \Component \HttpClient \HttpClient ;
30
31
use Symfony \Component \Mailer \Mailer ;
31
32
use Symfony \Component \Messenger \MessageBusInterface ;
32
33
use Symfony \Component \Notifier \Notifier ;
34
+ use Symfony \Component \PropertyAccess \PropertyAccessor ;
33
35
use Symfony \Component \PropertyInfo \PropertyInfoExtractorInterface ;
34
36
use Symfony \Component \RateLimiter \Policy \TokenBucketLimiter ;
35
37
use Symfony \Component \Serializer \Serializer ;
@@ -108,8 +110,19 @@ public function getConfigTreeBuilder()
108
110
->end ()
109
111
;
110
112
113
+ $ willBeAvailable = static function (string $ package , string $ class , string $ parentPackage = null ) {
114
+ $ parentPackages = (array ) $ parentPackage ;
115
+ $ parentPackages [] = 'symfony/framework-bundle ' ;
116
+
117
+ return ContainerBuilder::willBeAvailable ($ package , $ class , $ parentPackages );
118
+ };
119
+
120
+ $ enableIfStandalone = static function (string $ package , string $ class ) use ($ willBeAvailable ) {
121
+ return !class_exists (FullStack::class) && $ willBeAvailable ($ package , $ class ) ? 'canBeDisabled ' : 'canBeEnabled ' ;
122
+ };
123
+
111
124
$ this ->addCsrfSection ($ rootNode );
112
- $ this ->addFormSection ($ rootNode );
125
+ $ this ->addFormSection ($ rootNode, $ enableIfStandalone );
113
126
$ this ->addHttpCacheSection ($ rootNode );
114
127
$ this ->addEsiSection ($ rootNode );
115
128
$ this ->addSsiSection ($ rootNode );
@@ -119,25 +132,25 @@ public function getConfigTreeBuilder()
119
132
$ this ->addRouterSection ($ rootNode );
120
133
$ this ->addSessionSection ($ rootNode );
121
134
$ this ->addRequestSection ($ rootNode );
122
- $ this ->addAssetsSection ($ rootNode );
123
- $ this ->addTranslatorSection ($ rootNode );
124
- $ this ->addValidationSection ($ rootNode );
125
- $ this ->addAnnotationsSection ($ rootNode );
126
- $ this ->addSerializerSection ($ rootNode );
127
- $ this ->addPropertyAccessSection ($ rootNode );
128
- $ this ->addPropertyInfoSection ($ rootNode );
129
- $ this ->addCacheSection ($ rootNode );
135
+ $ this ->addAssetsSection ($ rootNode, $ enableIfStandalone );
136
+ $ this ->addTranslatorSection ($ rootNode, $ enableIfStandalone );
137
+ $ this ->addValidationSection ($ rootNode, $ enableIfStandalone , $ willBeAvailable );
138
+ $ this ->addAnnotationsSection ($ rootNode, $ willBeAvailable );
139
+ $ this ->addSerializerSection ($ rootNode, $ enableIfStandalone , $ willBeAvailable );
140
+ $ this ->addPropertyAccessSection ($ rootNode, $ willBeAvailable );
141
+ $ this ->addPropertyInfoSection ($ rootNode, $ enableIfStandalone );
142
+ $ this ->addCacheSection ($ rootNode, $ willBeAvailable );
130
143
$ this ->addPhpErrorsSection ($ rootNode );
131
- $ this ->addWebLinkSection ($ rootNode );
132
- $ this ->addLockSection ($ rootNode );
133
- $ this ->addMessengerSection ($ rootNode );
144
+ $ this ->addWebLinkSection ($ rootNode, $ enableIfStandalone );
145
+ $ this ->addLockSection ($ rootNode, $ enableIfStandalone );
146
+ $ this ->addMessengerSection ($ rootNode, $ enableIfStandalone );
134
147
$ this ->addRobotsIndexSection ($ rootNode );
135
- $ this ->addHttpClientSection ($ rootNode );
136
- $ this ->addMailerSection ($ rootNode );
148
+ $ this ->addHttpClientSection ($ rootNode, $ enableIfStandalone );
149
+ $ this ->addMailerSection ($ rootNode, $ enableIfStandalone );
137
150
$ this ->addSecretsSection ($ rootNode );
138
- $ this ->addNotifierSection ($ rootNode );
139
- $ this ->addRateLimiterSection ($ rootNode );
140
- $ this ->addUidSection ($ rootNode );
151
+ $ this ->addNotifierSection ($ rootNode, $ enableIfStandalone );
152
+ $ this ->addRateLimiterSection ($ rootNode, $ enableIfStandalone );
153
+ $ this ->addUidSection ($ rootNode, $ enableIfStandalone );
141
154
142
155
return $ treeBuilder ;
143
156
}
@@ -176,13 +189,13 @@ private function addCsrfSection(ArrayNodeDefinition $rootNode)
176
189
;
177
190
}
178
191
179
- private function addFormSection (ArrayNodeDefinition $ rootNode )
192
+ private function addFormSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
180
193
{
181
194
$ rootNode
182
195
->children ()
183
196
->arrayNode ('form ' )
184
197
->info ('form configuration ' )
185
- ->{! class_exists (FullStack::class) && class_exists ( Form::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
198
+ ->{$ enableIfStandalone ( ' symfony/form ' , Form::class)}()
186
199
->children ()
187
200
->arrayNode ('csrf_protection ' )
188
201
->treatFalseLike (['enabled ' => false ])
@@ -675,13 +688,13 @@ private function addRequestSection(ArrayNodeDefinition $rootNode)
675
688
;
676
689
}
677
690
678
- private function addAssetsSection (ArrayNodeDefinition $ rootNode )
691
+ private function addAssetsSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
679
692
{
680
693
$ rootNode
681
694
->children ()
682
695
->arrayNode ('assets ' )
683
696
->info ('assets configuration ' )
684
- ->{! class_exists (FullStack::class) && class_exists ( Package::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
697
+ ->{$ enableIfStandalone ( ' symfony/asset ' , Package::class)}()
685
698
->fixXmlConfig ('base_url ' )
686
699
->children ()
687
700
->scalarNode ('version_strategy ' )->defaultNull ()->end ()
@@ -763,13 +776,13 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
763
776
;
764
777
}
765
778
766
- private function addTranslatorSection (ArrayNodeDefinition $ rootNode )
779
+ private function addTranslatorSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
767
780
{
768
781
$ rootNode
769
782
->children ()
770
783
->arrayNode ('translator ' )
771
784
->info ('translator configuration ' )
772
- ->{! class_exists (FullStack::class) && class_exists ( Translator::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
785
+ ->{$ enableIfStandalone ( ' symfony/translation ' , Translator::class)}()
773
786
->fixXmlConfig ('fallback ' )
774
787
->fixXmlConfig ('path ' )
775
788
->fixXmlConfig ('enabled_locale ' )
@@ -816,16 +829,16 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
816
829
;
817
830
}
818
831
819
- private function addValidationSection (ArrayNodeDefinition $ rootNode )
832
+ private function addValidationSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone , callable $ willBeAvailable )
820
833
{
821
834
$ rootNode
822
835
->children ()
823
836
->arrayNode ('validation ' )
824
837
->info ('validation configuration ' )
825
- ->{! class_exists (FullStack::class) && class_exists ( Validation::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
838
+ ->{$ enableIfStandalone ( ' symfony/validator ' , Validation::class)}()
826
839
->children ()
827
840
->scalarNode ('cache ' )->end ()
828
- ->booleanNode ('enable_annotations ' )->{!class_exists (FullStack::class) && class_exists ( Annotation::class) ? 'defaultTrue ' : 'defaultFalse ' }()->end ()
841
+ ->booleanNode ('enable_annotations ' )->{!class_exists (FullStack::class) && $ willBeAvailable ( ' doctrine/annotations ' , Annotation::class, ' symfony/validator ' ) ? 'defaultTrue ' : 'defaultFalse ' }()->end ()
829
842
->arrayNode ('static_method ' )
830
843
->defaultValue (['loadValidatorMetadata ' ])
831
844
->prototype ('scalar ' )->end ()
@@ -906,15 +919,15 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
906
919
;
907
920
}
908
921
909
- private function addAnnotationsSection (ArrayNodeDefinition $ rootNode )
922
+ private function addAnnotationsSection (ArrayNodeDefinition $ rootNode, callable $ willBeAvailable )
910
923
{
911
924
$ rootNode
912
925
->children ()
913
926
->arrayNode ('annotations ' )
914
927
->info ('annotation configuration ' )
915
- ->{class_exists ( Annotation::class) ? 'canBeDisabled ' : 'canBeEnabled ' }()
928
+ ->{$ willBeAvailable ( ' doctrine/annotations ' , Annotation::class) ? 'canBeDisabled ' : 'canBeEnabled ' }()
916
929
->children ()
917
- ->scalarNode ('cache ' )->defaultValue (interface_exists ( Cache::class) ? 'php_array ' : 'none ' )->end ()
930
+ ->scalarNode ('cache ' )->defaultValue ($ willBeAvailable ( ' doctrine/cache ' , Cache::class, ' doctrine/annotation ' ) ? 'php_array ' : 'none ' )->end ()
918
931
->scalarNode ('file_cache_dir ' )->defaultValue ('%kernel.cache_dir%/annotations ' )->end ()
919
932
->booleanNode ('debug ' )->defaultValue ($ this ->debug )->end ()
920
933
->end ()
@@ -923,15 +936,15 @@ private function addAnnotationsSection(ArrayNodeDefinition $rootNode)
923
936
;
924
937
}
925
938
926
- private function addSerializerSection (ArrayNodeDefinition $ rootNode )
939
+ private function addSerializerSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone , $ willBeAvailable )
927
940
{
928
941
$ rootNode
929
942
->children ()
930
943
->arrayNode ('serializer ' )
931
944
->info ('serializer configuration ' )
932
- ->{! class_exists (FullStack::class) && class_exists ( Serializer::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
945
+ ->{$ enableIfStandalone ( ' symfony/serializer ' , Serializer::class)}()
933
946
->children ()
934
- ->booleanNode ('enable_annotations ' )->{!class_exists (FullStack::class) && class_exists ( Annotation::class) ? 'defaultTrue ' : 'defaultFalse ' }()->end ()
947
+ ->booleanNode ('enable_annotations ' )->{!class_exists (FullStack::class) && $ willBeAvailable ( ' doctrine/annotations ' , Annotation::class, ' symfony/serializer ' ) ? 'defaultTrue ' : 'defaultFalse ' }()->end ()
935
948
->scalarNode ('name_converter ' )->end ()
936
949
->scalarNode ('circular_reference_handler ' )->end ()
937
950
->scalarNode ('max_depth_handler ' )->end ()
@@ -950,13 +963,14 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode)
950
963
;
951
964
}
952
965
953
- private function addPropertyAccessSection (ArrayNodeDefinition $ rootNode )
966
+ private function addPropertyAccessSection (ArrayNodeDefinition $ rootNode, callable $ willBeAvailable )
954
967
{
955
968
$ rootNode
956
969
->children ()
957
970
->arrayNode ('property_access ' )
958
971
->addDefaultsIfNotSet ()
959
972
->info ('Property access configuration ' )
973
+ ->{$ willBeAvailable ('symfony/property-access ' , PropertyAccessor::class) ? 'canBeDisabled ' : 'canBeEnabled ' }()
960
974
->children ()
961
975
->booleanNode ('magic_call ' )->defaultFalse ()->end ()
962
976
->booleanNode ('magic_get ' )->defaultTrue ()->end ()
@@ -969,19 +983,19 @@ private function addPropertyAccessSection(ArrayNodeDefinition $rootNode)
969
983
;
970
984
}
971
985
972
- private function addPropertyInfoSection (ArrayNodeDefinition $ rootNode )
986
+ private function addPropertyInfoSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
973
987
{
974
988
$ rootNode
975
989
->children ()
976
990
->arrayNode ('property_info ' )
977
991
->info ('Property info configuration ' )
978
- ->{! class_exists (FullStack::class) && interface_exists ( PropertyInfoExtractorInterface::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
992
+ ->{$ enableIfStandalone ( ' symfony/property-info ' , PropertyInfoExtractorInterface::class)}()
979
993
->end ()
980
994
->end ()
981
995
;
982
996
}
983
997
984
- private function addCacheSection (ArrayNodeDefinition $ rootNode )
998
+ private function addCacheSection (ArrayNodeDefinition $ rootNode, callable $ willBeAvailable )
985
999
{
986
1000
$ rootNode
987
1001
->children ()
@@ -1008,7 +1022,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
1008
1022
->scalarNode ('default_psr6_provider ' )->end ()
1009
1023
->scalarNode ('default_redis_provider ' )->defaultValue ('redis://localhost ' )->end ()
1010
1024
->scalarNode ('default_memcached_provider ' )->defaultValue ('memcached://localhost ' )->end ()
1011
- ->scalarNode ('default_pdo_provider ' )->defaultValue (class_exists ( Connection::class) ? 'database_connection ' : null )->end ()
1025
+ ->scalarNode ('default_pdo_provider ' )->defaultValue ($ willBeAvailable ( ' doctrine/dbal ' , Connection::class) ? 'database_connection ' : null )->end ()
1012
1026
->arrayNode ('pools ' )
1013
1027
->useAttributeAsKey ('name ' )
1014
1028
->prototype ('array ' )
@@ -1117,13 +1131,13 @@ private function addPhpErrorsSection(ArrayNodeDefinition $rootNode)
1117
1131
;
1118
1132
}
1119
1133
1120
- private function addLockSection (ArrayNodeDefinition $ rootNode )
1134
+ private function addLockSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
1121
1135
{
1122
1136
$ rootNode
1123
1137
->children ()
1124
1138
->arrayNode ('lock ' )
1125
1139
->info ('Lock configuration ' )
1126
- ->{! class_exists (FullStack::class) && class_exists ( Lock::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
1140
+ ->{$ enableIfStandalone ( ' symfony/lock ' , Lock::class)}()
1127
1141
->beforeNormalization ()
1128
1142
->ifString ()->then (function ($ v ) { return ['enabled ' => true , 'resources ' => $ v ]; })
1129
1143
->end ()
@@ -1179,25 +1193,25 @@ private function addLockSection(ArrayNodeDefinition $rootNode)
1179
1193
;
1180
1194
}
1181
1195
1182
- private function addWebLinkSection (ArrayNodeDefinition $ rootNode )
1196
+ private function addWebLinkSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
1183
1197
{
1184
1198
$ rootNode
1185
1199
->children ()
1186
1200
->arrayNode ('web_link ' )
1187
1201
->info ('web links configuration ' )
1188
- ->{! class_exists (FullStack::class) && class_exists ( HttpHeaderSerializer::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
1202
+ ->{$ enableIfStandalone ( ' symfony/weblink ' , HttpHeaderSerializer::class)}()
1189
1203
->end ()
1190
1204
->end ()
1191
1205
;
1192
1206
}
1193
1207
1194
- private function addMessengerSection (ArrayNodeDefinition $ rootNode )
1208
+ private function addMessengerSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
1195
1209
{
1196
1210
$ rootNode
1197
1211
->children ()
1198
1212
->arrayNode ('messenger ' )
1199
1213
->info ('Messenger configuration ' )
1200
- ->{! class_exists (FullStack::class) && interface_exists ( MessageBusInterface::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
1214
+ ->{$ enableIfStandalone ( ' symfony/messenger ' , MessageBusInterface::class)}()
1201
1215
->fixXmlConfig ('transport ' )
1202
1216
->fixXmlConfig ('bus ' , 'buses ' )
1203
1217
->validate ()
@@ -1392,13 +1406,13 @@ private function addRobotsIndexSection(ArrayNodeDefinition $rootNode)
1392
1406
;
1393
1407
}
1394
1408
1395
- private function addHttpClientSection (ArrayNodeDefinition $ rootNode )
1409
+ private function addHttpClientSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
1396
1410
{
1397
1411
$ rootNode
1398
1412
->children ()
1399
1413
->arrayNode ('http_client ' )
1400
1414
->info ('HTTP Client configuration ' )
1401
- ->{! class_exists (FullStack::class) && class_exists ( HttpClient::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
1415
+ ->{$ enableIfStandalone ( ' symfony/http-client ' , HttpClient::class)}()
1402
1416
->fixXmlConfig ('scoped_client ' )
1403
1417
->beforeNormalization ()
1404
1418
->always (function ($ config ) {
@@ -1728,13 +1742,13 @@ private function addHttpClientRetrySection()
1728
1742
;
1729
1743
}
1730
1744
1731
- private function addMailerSection (ArrayNodeDefinition $ rootNode )
1745
+ private function addMailerSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
1732
1746
{
1733
1747
$ rootNode
1734
1748
->children ()
1735
1749
->arrayNode ('mailer ' )
1736
1750
->info ('Mailer configuration ' )
1737
- ->{! class_exists (FullStack::class) && class_exists ( Mailer::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
1751
+ ->{$ enableIfStandalone ( ' symfony/mailer ' , Mailer::class)}()
1738
1752
->validate ()
1739
1753
->ifTrue (function ($ v ) { return isset ($ v ['dsn ' ]) && \count ($ v ['transports ' ]); })
1740
1754
->thenInvalid ('"dsn" and "transports" cannot be used together. ' )
@@ -1784,13 +1798,13 @@ private function addMailerSection(ArrayNodeDefinition $rootNode)
1784
1798
;
1785
1799
}
1786
1800
1787
- private function addNotifierSection (ArrayNodeDefinition $ rootNode )
1801
+ private function addNotifierSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
1788
1802
{
1789
1803
$ rootNode
1790
1804
->children ()
1791
1805
->arrayNode ('notifier ' )
1792
1806
->info ('Notifier configuration ' )
1793
- ->{! class_exists (FullStack::class) && class_exists ( Notifier::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
1807
+ ->{$ enableIfStandalone ( ' symfony/notifier ' , Notifier::class)}()
1794
1808
->fixXmlConfig ('chatter_transport ' )
1795
1809
->children ()
1796
1810
->arrayNode ('chatter_transports ' )
@@ -1833,13 +1847,13 @@ private function addNotifierSection(ArrayNodeDefinition $rootNode)
1833
1847
;
1834
1848
}
1835
1849
1836
- private function addRateLimiterSection (ArrayNodeDefinition $ rootNode )
1850
+ private function addRateLimiterSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
1837
1851
{
1838
1852
$ rootNode
1839
1853
->children ()
1840
1854
->arrayNode ('rate_limiter ' )
1841
1855
->info ('Rate limiter configuration ' )
1842
- ->{! class_exists (FullStack::class) && class_exists ( TokenBucketLimiter::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
1856
+ ->{$ enableIfStandalone ( ' symfony/rate-limiter ' , TokenBucketLimiter::class)}()
1843
1857
->fixXmlConfig ('limiter ' )
1844
1858
->beforeNormalization ()
1845
1859
->ifTrue (function ($ v ) { return \is_array ($ v ) && !isset ($ v ['limiters ' ]) && !isset ($ v ['limiter ' ]); })
@@ -1901,13 +1915,13 @@ private function addRateLimiterSection(ArrayNodeDefinition $rootNode)
1901
1915
;
1902
1916
}
1903
1917
1904
- private function addUidSection (ArrayNodeDefinition $ rootNode )
1918
+ private function addUidSection (ArrayNodeDefinition $ rootNode, callable $ enableIfStandalone )
1905
1919
{
1906
1920
$ rootNode
1907
1921
->children ()
1908
1922
->arrayNode ('uid ' )
1909
1923
->info ('Uid configuration ' )
1910
- ->{class_exists ( UuidFactory::class) ? ' canBeDisabled ' : ' canBeEnabled ' }()
1924
+ ->{$ enableIfStandalone ( ' symfony/uid ' , UuidFactory::class)}()
1911
1925
->addDefaultsIfNotSet ()
1912
1926
->children ()
1913
1927
->enumNode ('default_uuid_version ' )
0 commit comments