Hi there, I'm currently facing a problem while developing a bundle.
I'd like to provide to the end user a recipe who will be able to update some configuration files, by example the security layer config file.
Let's take the case of a UserBundle who generally need to a user to make some manual setup by updating the security.yaml file. The idea behind Symfony Flex was (and still is) to provide a tool to automates the most common tasks of Symfony applications. However in this particular case Flex cannot do it's job to configure a Bundle using a recipe because Flex is not able to put some values in a file like security.yaml without overriding the whole file.
This proposal, would be to Flex to be able to had some predefined keys to a YAML config file without overriding the whole file (and maybe losing some data from another bundle).
Let's take and example, here is the security.yaml file provided by the SecurityBundle recipe:
security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
in_memory: { memory: ~ }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
# activate different ways to authenticate
# http_basic: true
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
# form_login: true
# https://symfony.com/doc/current/security/form_login_setup.html
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
A bundle should be able to configure the security layer and add some data in this file. By example FOSUserBundle, require this values and a recipe should be able to add this values:
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
user_checker: fos_user.user_checker
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
This feature will be very helpful in cases like the example above.
I also encountered this problem when workin on the Docker configurator, here is the (not very good) solution I ended with: https://github.com/symfony/flex/pull/128/files#diff-fd4f36bd81db26a51f12e9150ef07761R21
I suggest you create a maker command in your bundle and ask the end user to run it, it's IMO a better solution because you may have more control over the updated file (merging, interaction, etc.)
yea, FYI, it's private right now inside of MakerBundle, but that library does have a class (YamlSourceManipulator) with the ability to update YAML files without killing current indentation, comments, etc. It's used, for example, to update security.yaml for several of the commands
Closing as maker bundle is a good reco.
Most helpful comment
yea, FYI, it's private right now inside of MakerBundle, but that library does have a class (
YamlSourceManipulator) with the ability to update YAML files without killing current indentation, comments, etc. It's used, for example, to updatesecurity.yamlfor several of the commands