PHPackages                             becklyn/static-roles-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. becklyn/static-roles-bundle

ActiveSymfony-bundle[Security](/categories/security)

becklyn/static-roles-bundle
===========================

This bundle provides a simple way to define all available roles and their hierarchy in your configuration

2.1.0(3y ago)43.0k↓50%2[1 issues](https://github.com/Becklyn/BecklynStaticRolesBundle/issues)BSD-3-ClausePHPPHP &gt;=8.1

Since Jul 9Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Becklyn/BecklynStaticRolesBundle)[ Packagist](https://packagist.org/packages/becklyn/static-roles-bundle)[ Docs](https://github.com/Becklyn/BecklynStaticRolesBundle)[ RSS](/packages/becklyn-static-roles-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (8)Versions (9)Used By (0)

BecklynStaticRolesBundle
========================

[](#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
------------

[](#installation)

You can install it via composer:

```
$ composer require becklyn/static-roles-bundle
```

Afterwards, you need to activate the bundle in your `app/AppKernel.php`:

```
public function registerBundles()
{
    $bundles = array(
        // ...
        new \Becklyn\StaticRolesBundle\BecklynStaticRolesBundle(),
        // ...
    );

    // ...
}
```

Configuration
-------------

[](#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:

```
becklyn_static_roles:
    roles:
        ROLE_ADMIN:
            title: "Admin"
            included_roles: [ROLE_USER]
        ROLE_USER:
            title: "User"
            description: "The default frontend user"
            tags: [tag1, tag2]
```

Assigning roles to a user entity
--------------------------------

[](#assigning-roles-to-a-user-entity)

The bundle provides a form type to be used in user forms:

```
$builder
    ->add("roles", "static_role", [
        "label" => "User roles",
        "multiple" => true,
        "expanded" => true,
    ]);
```

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`](http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#simple-array) type of doctrine. You need to set it nullable to properly support a user without any roles.

```
class User implements UserInterface
{
    // ...

    /**
     * @var string[]
     *
     * @ORM\Column(name="roles", type="simple_array", nullable=true)
     *
     */
    private $userRoles = null;

    // ...

    /**
     * @inheritdoc
     */
    public function getRoles ()
    {
        return $this->roles;
    }

    /**
     * @param string[]|null $roles
     */
    public function setRoles (array $roles = null)
    {
        $this->roles = $roles;
    }

    // ...
}
```

Hidden 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:

```
becklyn_static_roles:
    roles:
        ROLE_ADMIN:
            title: "Admin"
            included_roles: [ROLE_ALLOWED_TO_SWITCH]
        ROLE_ALLOWED_TO_SWITCH:
            title: "Internal: The user is allowed to switch roles"
            hidden: true
```

In this example, only `ROLE_ADMIN` will be selectable by the user.

Tagging
-------

[](#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.

```
$builder
    ->add("roles", "static_role", [
        "label" => "User roles",
        "multiple" => true,
        "expanded" => true,
        "roles_with_tags" => ["tag1", "tag2"], // only include roles with either "tag1" or "tag2"
    ]);
```

```
becklyn_static_roles:
    roles:
        ROLE_USER_1:
            title: "User 1"
            tags: [tag1, tag3] # will be included, as it has at least one of the defined roles
        ROLE_USER_2:
            title: "User 2"
            tags: [tag3, tag4] # will not be included, as it has none of the defined roles
```

If you don't define any tags in your form, all roles will be included.

```
$builder
    ->add("roles", "static_role", [
        "label" => "User roles",
        "multiple" => true,
        "expanded" => true,
        "roles_with_tags" => [], // includes all roles
    ]);

// This is also the default value, so you can omit it:
$builder
  ->add("roles", "static_role", [
      "label" => "User roles",
      "multiple" => true,
      "expanded" => true,
  ]);
```

Twig helper functions
---------------------

[](#twig-helper-functions)

```
staticRoleTitle(key)
```

Returns the role title by key. Returns null if the role key is not found.

Note
----

[](#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`:

```
security:
    always_authenticate_before_granting: true
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~452 days

Recently: every ~678 days

Total

7

Last Release

1254d ago

Major Versions

1.1.0 → 2.0.02022-12-12

PHP version history (3 changes)1.0.0-alpha.1PHP &gt;=5.5

1.1.0PHP ^7.0

2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1044355?v=4)[Becklyn Studios](/maintainers/becklyn)[@Becklyn](https://github.com/Becklyn)

---

Top Contributors

[![apfelbox](https://avatars.githubusercontent.com/u/1032411?v=4)](https://github.com/apfelbox "apfelbox (4 commits)")[![lukasbrodbeck](https://avatars.githubusercontent.com/u/12810590?v=4)](https://github.com/lukasbrodbeck "lukasbrodbeck (4 commits)")[![Thyrannoizer](https://avatars.githubusercontent.com/u/29758676?v=4)](https://github.com/Thyrannoizer "Thyrannoizer (2 commits)")

---

Tags

phprolessecuritysymfonysymfony-bundlesymfonysecurity

### Embed Badge

![Health badge](/badges/becklyn-static-roles-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/becklyn-static-roles-bundle/health.svg)](https://phpackages.com/packages/becklyn-static-roles-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[a2lix/translation-form-bundle

Translate your doctrine objects easily with some helpers

3376.9M38](/packages/a2lix-translation-form-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
