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

app-verk/user-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require app-verk/user-bundle
    

    Register the bundle in config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3):

    AppVerk\UserBundle\UserBundle::class => ['all' => true],
    
  2. Configuration Create config/packages/user.yaml:

    user:
        entities:
            user_class: App\Entity\User
        acl:
            enabled: false
            access_denied_path: app_denied_route
    
  3. Create User Entity Extend AppVerk\UserBundle\Entity\User in your bundle:

    // src/Entity/User.php
    namespace App\Entity;
    
    use AppVerk\UserBundle\Entity\User as BaseUser;
    use Doctrine\ORM\Mapping as ORM;
    
    #[ORM\Entity(repositoryClass: "App\Entity\UserRepository")]
    class User extends BaseUser {}
    
  4. Update Schema

    php bin/console doctrine:schema:update --force
    
  5. Create Admin User

    php bin/console user:create:admin admin admin@example.com password123
    

First Use Case: Basic Authentication

  • Use Symfony’s built-in security system with UserBundle’s User entity.
  • Example security.yaml:
    security:
        providers:
            app_user_provider:
                entity: { class: App\Entity\User, property: email }
        firewalls:
            main:
                form_login:
                    provider: app_user_provider
    

Implementation Patterns

Workflow: User Management

  1. Registration Extend UserBundle’s registration logic by overriding the UserManager service:

    # config/services.yaml
    App\Service\CustomUserManager:
        decorates: 'app_verk.user.manager.user'
        arguments: ['@app_verk.user.manager.user.decorated']
    
  2. Role Assignment Assign roles dynamically in a controller:

    $user->addRole('ROLE_EDITOR');
    $em->persist($user);
    $em->flush();
    
  3. ACL Integration Enable ACL in user.yaml and annotate controllers:

    use AppVerk\UserBundle\Annotation\AVSecurity;
    
    #[AVSecurity(allow: {"ROLE_ADMIN"}, name: "edit", group: "content")]
    public function editAction() { ... }
    

Integration Tips

  • Custom User Fields Add fields to the User entity and update the schema:

    #[ORM\Column(type: "string", length: 255, nullable: true)]
    private $phoneNumber;
    
  • Event Listeners Subscribe to UserEvents (e.g., UserCreatedEvent) for post-registration actions:

    #[Tags(['kernel.event_listener'])]
    class UserListener implements UserEvents
    {
        public function onUserCreated(UserCreatedEvent $event) {
            // Send welcome email
        }
    }
    
  • API Integration Use JMS Serializer for API responses:

    # config/packages/jms_serializer.yaml
    jms_serializer:
        metadata:
            directories:
                App:
                    namespace_prefix: "App\\Serializer"
                    path: "%kernel.project_dir%/config/serializer"
    

Gotchas and Tips

Pitfalls

  1. ACL Caching Clear Symfony’s cache after enabling/disabling ACL:

    php bin/console cache:clear
    
  2. Annotation Parsing Ensure sensio/framework-extra-bundle is installed and annotations are parsed:

    # config/packages/framework.yaml
    framework:
        validation: { enable_annotations: true }
    
  3. Doctrine Migrations Avoid --force in production. Use migrations instead:

    php bin/console make:migration
    php bin/console doctrine:migrations:migrate
    

Debugging

  • Access Denied Issues Check access_denied_path in user.yaml and verify route existence. Enable debug mode to see ACL errors:

    # config/packages/dev/debug.yaml
    framework:
        router:
            debug: "%kernel.debug%"
    
  • Custom Resolver Logic Test AccessResolverInterface methods in isolation:

    $resolver = new CustomAccessResolver();
    $result = $resolver->resolve($user, 'edit'); // Debug $result
    

Extension Points

  1. Custom User Manager Override UserManager to add validation or business logic:

    class CustomUserManager extends AbstractUserManager
    {
        public function createUser(array $data) {
            $user = parent::createUser($data);
            // Custom logic (e.g., set default role)
            $user->addRole('ROLE_USER');
            return $user;
        }
    }
    
  2. Dynamic ACL Rules Use AccessResolverInterface for context-aware access control:

    public function resolve(RoleableInterface $user, $action): bool {
        if ($action === 'publish' && $user->isEditor()) {
            return true;
        }
        return false;
    }
    
  3. Event-Driven Workflows Extend UserEvents for workflows like password resets or profile updates:

    #[OnKernelEvent('kernel.request', method: 'onKernelRequest')]
    public function onKernelRequest(GetResponseEvent $event) {
        if ($event->isMasterRequest()) {
            $this->userManager->checkSession();
        }
    }
    

Configuration Quirks

  • Doctrine Extensions Ensure stof/doctrine-extensions-bundle is installed for soft-deletes or timestamps:

    composer require stof/doctrine-extensions-bundle
    
  • Email Validation Configure egulias/email-validator for strict email checks:

    # config/packages/validator.yaml
    validator:
        email_validation_mode: strict
    
  • Symfony Flex Conflicts If using Symfony 4+, ensure config/bundles.php includes:

    AppVerk\UserBundle\UserBundle::class => ['all' => true],
    
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