Download the PHP package becklyn/static-roles-bundle without Composer
On this page you can find all versions of the php package becklyn/static-roles-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download becklyn/static-roles-bundle
More information about becklyn/static-roles-bundle
Files in becklyn/static-roles-bundle
Package static-roles-bundle
Short Description This bundle provides a simple way to define all available roles and their hierarchy in your configuration
License BSD-3-Clause
Homepage https://github.com/Becklyn/BecklynStaticRolesBundle
Informations about the package static-roles-bundle
BecklynStaticRolesBundle
As user roles are directly coupled to the application code and we would like to configure our roles using an existing VCS (instead of the DB) this bundle implements a simple role system.
You define your roles including the hierarchy in your security.yml and the system provides ways to validated that, list them and for you to select them.
Installation
You can install it via composer:
Afterwards, you need to activate the bundle in your app/AppKernel.php
:
Configuration
Open up app/config/security.yml
and first remove the section role_hierarchy
that is automatically provided by symfony.
Then add your own role configuration on top of the file:
Assigning roles to a user entity
The bundle provides a form type to be used in user forms:
You will receive an array of roles in the entity as values: ["ROLE_ADMIN", "ROLE_USER"]
.
The mapping of these values can be done using the simple_array
type of doctrine. You need to set it nullable to properly support a user without any roles.
Hidden roles
If you are using roles, that should be used internally, but shouldn't be presented in the form type, you can add hidden: true
to the role definition:
In this example, only ROLE_ADMIN
will be selectable by the user.
Tagging
You can tag roles. This is a way to filter the visible roles in the form type. All roles that have at least one of your defined tags will be included.
If you don't define any tags in your form, all roles will be included.
Twig helper functions
Returns the role title by key. Returns null if the role key is not found.
Note
If you are transforming sensitive data, please keep in mind that updating the roles of the user entity won't automatically update the roles of the authenticated user token. You need to refresh this token.
You can fix this issue by adding this configuration in your app/config/security.yml
:
All versions of static-roles-bundle with dependencies
symfony/config Version ^6.1 || ^5.0
symfony/dependency-injection Version ^6.1 || ^5.0
symfony/form Version ^6.1 || ^5.0
symfony/http-kernel Version ^6.1 || ^5.0
symfony/options-resolver Version ^6.1 || ^5.0
symfony/security-core Version ^6.1 || ^5.0
twig/twig Version ^2.10 || ^3.0