Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

User Bundle Laravel Package

albegali/user-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require albegali/user-bundle
    

    Ensure your AppKernel.php includes:

    new Sonata\UserBundle\SonataUserBundle('FOSUserBundle') // Extends FOSUserBundle
    // OR
    new Sonata\UserBundle\SonataUserBundle() // Standalone (no FOSUserBundle)
    
  2. Database Migrations: Run the bundle’s migrations (check vendor/albegali/user-bundle/Resources/doc/install.md for specifics). Example:

    php bin/console doctrine:migrations:diff
    php bin/console doctrine:migrations:migrate
    
  3. First Use Case:

    • Admin Panel: Access /admin to manage users/groups via SonataAdmin.
    • User Registration: Extend Sonata\UserBundle\Form\Type\RegistrationFormType in your config.yml:
      sonata_user:
          class:
              user: AppBundle\Entity\User
              group: AppBundle\Entity\Group
      

Implementation Patterns

Core Workflows

  1. User Management:

    • Admin CRUD: Use SonataAdmin’s UI (/admin/user) to create/edit users/groups.
    • Programmatic Access:
      $user = $this->get('sonata.user.pool')->getUserManager()->findUserBy(['email' => 'user@example.com']);
      
  2. Authentication:

    • Integrate with Symfony’s security system. Example security.yml:
      providers:
          sonata_user_provider:
              entity: { class: AppBundle\Entity\User, property: username }
      firewalls:
          main:
              form_login:
                  provider: sonata_user_provider
      
  3. Google Authenticator:

    • Enable in config.yml:
      sonata_user:
          google_authenticator:
              enabled: true
      
    • Use in templates:
      {{ form_row(form.google_authenticator_code) }}
      
  4. EasyExtends:

    • Extend default models (e.g., User) via EasyExtendsBundle:
      sonata_easy_extends:
          user:
              class: AppBundle\Entity\User
              fields:
                  - { name: 'phone', type: 'string', length: 20 }
      

Integration Tips

  • Custom Fields: Add fields to User entity and update the form type:
    // src/AppBundle/Form/Type/AppRegistrationFormType.php
    class AppRegistrationFormType extends RegistrationFormType {
        public function buildForm(FormBuilderInterface $builder, array $options) {
            $builder->add('phone', TextType::class);
        }
    }
    
  • API Access: Use FOSRestBundle for REST endpoints (e.g., /api/users).

Gotchas and Tips

Pitfalls

  1. FOSUserBundle Dependency:

    • If extending FOSUserBundle, ensure it’s installed (composer require friendsofsymfony/user-bundle).
    • Standalone mode requires manual setup of FOSUserBundle’s services (e.g., fos_user.user_manager).
  2. Doctrine Migrations:

    • Bundle assumes sonata_project/doctrine-extensions for soft deletes. Conflicts may arise if using custom Doctrine behaviors.
  3. Admin Route Conflicts:

    • SonataAdmin routes may clash with other bundles. Override routes in routing.yml:
      sonata_user_admin:
          resource: '@SonataUserBundle/Resources/config/routing/admin.xml'
          prefix: /custom-admin
      

Debugging

  • Symfony Profiler: Enable for user-related events:
    // config/packages/dev/sonata_user.yaml
    sonata_user:
        debug: true
    
  • Logs: Check var/log/dev.log for sonata.user entries.

Extension Points

  1. Custom User Classes:

    • Override sonata_user.class.user in config to use a custom entity (must extend Sonata\UserBundle\Entity\BaseUser).
  2. Event Listeners:

    • Subscribe to sonata.user.register or sonata.user.login events:
      // src/EventListener/UserListener.php
      class UserListener {
          public function onUserRegister(GetResponseUserEvent $event) {
              // Custom logic
          }
      }
      
      Register in services.yaml:
      services:
          AppBundle\EventListener\UserListener:
              tags:
                  - { name: kernel.event_listener, event: sonata.user.register, method: onUserRegister }
      
  3. Templates:

    • Override default templates (e.g., registration.html.twig) in templates/SonataUserBundle/.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware