### Install Documentation Dependencies Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md Install Python dependencies required for rendering documentation using pip. Ensure your PATH environment variable is correctly set to include Python's local bin directory. ```bash pip install --requirement docs/requirements.txt --user ``` -------------------------------- ### Commit Message with Description Example Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md An example demonstrating a good commit message structure, including a clear subject line and a detailed description explaining the 'why' behind the changes and referencing related issues. ```git call foo::bar() instead of bar::baz() This fixes a bug that arises when doing this or that, because baz() needs a flux capacitor object that might not be defined. Fixes #42 ``` -------------------------------- ### Build and View Documentation Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md Build the project documentation using the make command and open the generated HTML files in your browser. This command assumes Sphinx is installed and configured. ```bash $YOUR_FAVORITE_BROWSER docs/_build/html/index.html ``` -------------------------------- ### Install SonataUserBundle via Composer Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Use Composer to add the SonataUserBundle to your project dependencies. ```bash composer require sonata-project/user-bundle ``` -------------------------------- ### Install and Run PHP Coding Standard Fixer Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md Install PHP Coding Standard Fixer and run it to fix coding style issues before committing modifications. This ensures adherence to PSR-1, PSR-2, and Symfony Coding Standards. ```bash php-cs-fixer fix --verbose ``` -------------------------------- ### PHP Docblock with Type Hinting and Annotations Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md Example of a PHP docblock demonstrating type hinting, standard annotations, and phpstan-specific annotations for template types and parameters. It also shows multiline signatures for lines exceeding 120 characters. ```php /** * @param Bar|Baz $foo * @param class-string $class * @param int $limit a crucial, fascinating comment * * @return object * * @phpstan-template T of object * @phpstan-param class-string $class * @phpstan-return T */ protected function bar($foo, string $class, int $limit): object { // ... } ``` -------------------------------- ### Good Commit Message Subject Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md An example of a concise and precise commit message subject that clearly states the action performed. This is preferred over vague descriptions. ```git Document how to install the project ``` -------------------------------- ### Bad Commit Message Subject Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md An example of a commit message subject that is too vague and uninformative. It should be more precise about the action taken. ```git Update README.md ``` -------------------------------- ### Enable SonataUserBundle in config/bundles.php Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Register the SonataUserBundle in your application's bundle configuration file. ```php // config/bundles.php return [ // ... Sonata\UserBundle\SonataUserBundle::class => ['all' => true], ]; ``` -------------------------------- ### Configure Admin Firewall for SonataUserBundle Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Set up the security firewall for the admin area, including login, logout, and remember-me functionality. ```yaml # config/packages/security.yaml security: enable_authenticator_manager: true firewalls: admin: lazy: true pattern: /admin(.*) provider: sonata_user_bundle context: user form_login: login_path: sonata_user_admin_security_login check_path: sonata_user_admin_security_check default_target_path: sonata_admin_dashboard logout: path: sonata_user_admin_security_logout target: sonata_user_admin_security_login remember_me: secret: '%env(APP_SECRET)%' lifetime: 2629746 path: /admin ``` -------------------------------- ### Enable Impersonation in Firewall Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/user_impersonation.md Configure your security firewall to enable the switch_user functionality. Ensure the impersonating user has the ROLE_ALLOWED_TO_SWITCH role. ```yaml security: role_hierarchy: ROLE_SUPER_ADMIN: [ROLE_SONATA_ADMIN, ROLE_ALLOWED_TO_SWITCH] firewalls: admin: switch_user: true ``` -------------------------------- ### Configure Role Hierarchy, Hasher, and Provider Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Define role hierarchy, password hasher, and user provider for SonataUserBundle integration. ```yaml # config/packages/security.yaml security: role_hierarchy: ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN] ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] password_hashers: Sonata\UserBundle\Model\UserInterface: auto providers: sonata_user_bundle: id: sonata.user.security.user_provider ``` -------------------------------- ### Configure SonataUserBundle Settings Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Define the user class and email settings for the SonataUserBundle in the configuration file. ```yaml # config/packages/sonata_user.yaml sonata_user: class: user: App\Entity\SonataUserUser resetting: email: address: sonata@localhost sender_name: Sonata Admin ``` -------------------------------- ### Sonata User Bundle Configuration Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/advanced_configuration.md This snippet shows the full configuration options for the Sonata User Bundle in `config/packages/sonata_user.yaml`. It covers security ACL, manager type, impersonating settings, entity and admin class mappings, profile defaults, mailer service, and resetting configurations. ```yaml sonata_user: security_acl: false manager_type: orm # can be orm or mongodb impersonating: route: page_slug parameters: { path: / } class: # Entity Classes user: Sonata\UserBundle\Entity\BaseUser admin: # Admin Classes user: class: Sonata\UserBundle\Admin\Entity\UserAdmin controller: '%sonata.admin.configuration.default_controller%' translation: SonataUserBundle profile: default_avatar: bundles/sonatauser/default_avatar.png # Default avatar displayed if the user doesn't have one mailer: sonata.user.mailer.default # Service used to send emails resetting: # Reset password configuration (must be configured) email: template: '@SonataUser/Admin/Security/Resetting/email.html.twig' address: ~ sender_name: ~ ``` -------------------------------- ### Configure Doctrine ORM Mapping for SonataUserBundle Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Set up Doctrine ORM to recognize the SonataUserBundle's mappings in the doctrine configuration. ```yaml # config/packages/doctrine.yaml doctrine: orm: entity_managers: default: mappings: SonataUserBundle: ~ ``` -------------------------------- ### Define SonataUserUser Document for MongoDB Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Create the SonataUserUser document class extending BaseUser for MongoDB persistence. ```php // src/Document/SonataUserUser.php use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Sonata\UserBundle\Document\BaseUser; #[ODM\Document] class SonataUserUser extends BaseUser { #[ODM\Id] protected $id; } ``` -------------------------------- ### Enable ACL Security Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Enable ACL security in `config/packages/sonata_user.yaml` to prevent normal users from modifying super-admin user settings. Configure the ACL connection in `config/packages/security.yaml`. ```yaml # config/packages/sonata_user.yaml sonata_user: security_acl: true ``` ```yaml # config/packages/security.yaml security: acl: connection: default ``` -------------------------------- ### Configure SonataUserBundle for MongoDB Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Specify 'mongodb' as the manager type and set the user document class in the SonataUserBundle configuration. ```yaml # config/packages/sonata_user.yaml sonata_user: manager_type: mongodb class: user: App\Document\SonataUserUser ``` -------------------------------- ### Good Commit Message with Description Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md A well-formed commit message that includes a descriptive subject and a detailed body explaining the context and rationale for the change, referencing related issues. ```git Change web UI background color to pink This is a consensus made on #4242 in addition to #1337. We agreed that blank color is boring and so deja vu. Pink is the new way to do. ``` -------------------------------- ### Add Sonata Admin Security Routing Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Include the security and resetting routing resources for Sonata Admin integration. ```yaml # config/routes.yaml sonata_user_admin_security: resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml' prefix: /admin sonata_user_admin_resetting: resource: '@SonataUserBundle/Resources/config/routing/admin_resetting.xml' prefix: /admin ``` -------------------------------- ### Configure Impersonation Redirect Route Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/user_impersonation.md Specify the route name to redirect to after a user has been impersonated within the SonataUserBundle configuration. ```yaml sonata_user: impersonating: route: sonata_admin_dashboard ``` -------------------------------- ### Marking Code for Future Major Version Removal Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md Use the `NEXT_MAJOR` comment to indicate code that should be removed or uncommented in a subsequent major release. This is typically used when introducing new methods or features that will eventually replace older ones. ```php ` tag. Include a 'NEXT_MAJOR' comment for removal. ```xml The "%service_id%" service is deprecated since sonata-project/bar-bundle 42.x and will be removed in 43.0. ``` -------------------------------- ### Update Doctrine Schema Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Apply schema changes to the database after defining the Doctrine ORM entity. ```bash bin/console doctrine:schema:update --force ``` -------------------------------- ### Configure Security Access Control Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/docs/reference/installation.md Define access control rules in `config/packages/security.yaml` to manage user access to different parts of the application. Note the differences for Symfony versions 4.4 regarding `password_hashers` and `PUBLIC_ACCESS`. ```yaml # config/packages/security.yaml security: access_control: # Admin login page needs to be accessed without credential - { path: ^/admin/login$, role: PUBLIC_ACCESS } - { path: ^/admin/logout$, role: PUBLIC_ACCESS } - { path: ^/admin/login_check$, role: PUBLIC_ACCESS } - { path: ^/admin/request$, role: PUBLIC_ACCESS } - { path: ^/admin/check-email$, role: PUBLIC_ACCESS } - { path: ^/admin/reset/.*$, role: PUBLIC_ACCESS } # Secured part of the site # This config requires being logged for the whole site and having the admin role for the admin part. # Change these rules to adapt them to your needs - { path: ^/admin/, role: ROLE_ADMIN } - { path: ^/.*, role: PUBLIC_ACCESS } ``` -------------------------------- ### Deprecate Method with @deprecated and @trigger_error Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md Deprecate methods using both the @deprecated tag and @trigger_error to signal deprecation. Include a 'NEXT_MAJOR' comment for removal. ```php /** * NEXT_MAJOR: Remove this method. * * @deprecated since sonata-project/foo-lib 42.x, to be removed in 43.0. */ public function iAmBatman() { @trigger_error(sprintf( 'Method %s() is deprecated since sonata-project/foo-lib 42.x and will be removed in version 43.0.', __METHOD__ ), \E_USER_DEPRECATED); echo "But this is not Gotham here."; } ``` -------------------------------- ### Trigger Deprecation for General Code Source: https://github.com/sonata-project/sonatauserbundle/blob/5.x/CONTRIBUTING.md For code not covered by the @deprecated tag, trigger a deprecation notice using @trigger_error. Add a 'NEXT_MAJOR' comment for removal. ```php