@@ -71,8 +71,8 @@ readable. These are the main advantages and disadvantages of each format:
7171 and validation for it. :doc: `Learn the YAML syntax </components/yaml/yaml_format >`;
7272* **XML **:autocompleted/validated by most IDEs and is parsed natively by PHP,
7373 but sometimes it generates configuration considered too verbose. `Learn the XML syntax `_;
74- * **PHP **: very powerful and it allows you to create dynamic configuration, but the
75- resulting configuration is less readable than the other formats .
74+ * **PHP **: very powerful and it allows you to create dynamic configuration with
75+ arrays or a :ref: ` ConfigBuilder < config-config-builder >` .
7676
7777Importing Configuration Files
7878~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -914,6 +914,41 @@ parameters at once by type-hinting any of its constructor arguments with the
914914 }
915915 }
916916
917+ .. _config-config-builder :
918+
919+ Using PHP ConfigBuilders
920+ ------------------------
921+
922+ Writing PHP config is sometimes difficult because you end up with large nested arrays
923+ and you have no help from your favorite IDE. A way to address this is to use "ConfigBuilders".
924+ They are objects that will help you build these arrays.
925+
926+ .. versionadded :: 5.3
927+
928+ The "ConfigBuilders" was added in Symfony 5.3 as an :doc: `experimental feature </contributing/code/experimental >`.
929+
930+ The ConfigBuilders are automatically generated in your ``kernel.build_dir `` for
931+ every bundle. By convention they all live in the namespace ``Symfony\Config ``.::
932+
933+ // config/packages/security.php
934+ use Symfony\Config\SecurityConfig;
935+
936+ return static function (SecurityConfig $security) {
937+ $security->firewall('main')
938+ ->pattern('^/*')
939+ ->lazy(true)
940+ ->anonymous();
941+
942+ $security
943+ ->roleHierarchy('ROLE_ADMIN', ['ROLE_USER'])
944+ ->roleHierarchy('ROLE_SUPER_ADMIN', ['ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'])
945+ ->accessControl()
946+ ->path('^/user')
947+ ->role('ROLE_USER');
948+
949+ $security->accessControl(['path' => '^/admin', 'roles' => 'ROLE_ADMIN']);
950+ };
951+
917952Keep Going!
918953-----------
919954
0 commit comments