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

Darvin User Bundle Laravel Package

darvinstudio/darvin-user-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Add the bundle via Composer:

    composer require darvinstudio/darvin-user-bundle
    

    Enable the bundle in config/bundles.php:

    DarvinStudio\UserBundle\DarvinUserBundle::class => ['all' => true],
    
  2. Database Setup Run migrations (if provided) or manually create tables based on the bundle’s schema (e.g., users, roles, permissions). Example structure:

    CREATE TABLE users (
        id INT AUTO_INCREMENT PRIMARY KEY,
        email VARCHAR(255) UNIQUE NOT NULL,
        password VARCHAR(255) NOT NULL,
        is_active BOOLEAN DEFAULT true,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    
  3. Basic Usage Register a user via the bundle’s service or manually:

    use DarvinStudio\UserBundle\Entity\User;
    use DarvinStudio\UserBundle\Service\UserManager;
    
    $userManager = $this->container->get('darvin_user.user_manager');
    $user = new User();
    $user->setEmail('user@example.com');
    $user->setPassword('plaintext_password'); // Handled by encoder
    $userManager->createUser($user);
    
  4. Authentication Configure Symfony’s security.yaml to use the bundle’s user provider:

    security:
        providers:
            darvin_user_provider:
                id: darvin_user.user_provider
    

Implementation Patterns

Core Workflows

  1. User CRUD Use the UserManager service for all user operations:

    // Create
    $userManager->createUser($user);
    
    // Update
    $userManager->updateUser($user);
    
    // Delete (soft/hard)
    $userManager->deleteUser($user->getId());
    
  2. Role/Permission Management Attach roles to users:

    $user->addRole('ROLE_ADMIN');
    $userManager->updateUser($user);
    

    Check permissions in controllers:

    $this->denyAccessUnlessGranted('ROLE_EDITOR', $user);
    
  3. Event Listeners Subscribe to bundle events (e.g., UserCreatedEvent) for post-actions:

    # config/services.yaml
    services:
        App\EventListener\UserListener:
            tags:
                - { name: kernel.event_listener, event: darvin_user.user_created, method: onUserCreated }
    
  4. API Integration Expose endpoints via Symfony’s serializer:

    use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
    
    $normalizer = new ObjectNormalizer();
    $userData = $normalizer->normalize($user);
    

Integration Tips

  • Custom User Entity: Extend the bundle’s User entity to add fields:

    use DarvinStudio\UserBundle\Entity\User as BaseUser;
    
    class AppUser extends BaseUser {
        private $customField;
    }
    

    Update config/packages/darvin_user.yaml to point to your entity.

  • Password Reset: Use the bundle’s PasswordResetManager for token-based resets:

    $token = $passwordResetManager->generateResetToken($user);
    
  • Multi-Tenancy: Override the UserProvider to filter users by tenant ID.


Gotchas and Tips

Pitfalls

  1. Outdated Releases

    • Last release was 2021-08-05. Test thoroughly for edge cases (e.g., password hashing, role inheritance).
    • Mitigation: Fork the repo or patch critical issues locally.
  2. Missing Documentation

    • Some methods (e.g., UserManager internals) lack examples. Use php app/console debug:container DarvinUserBundle to inspect services.
  3. Hardcoded Table Names

    • The bundle assumes default table names. Override via configuration:
      # config/packages/darvin_user.yaml
      darvin_user:
          db_driver: doctrine
          user_table: app_users
      
  4. Security Gaps

    • No built-in rate-limiting for login attempts. Add Symfony’s firewall config:
      security:
          firewalls:
              main:
                  pattern: ^/
                  form_login:
                      check_path: /login_check
                      enable_csrf: true
                  logout: true
                  max_attempts: 5
      

Debugging Tips

  • Enable Logging:
    # config/packages/monolog.yaml
    handlers:
        darvin_user:
            type: stream
            path: "%kernel.logs_dir%/darvin_user.log"
            level: debug
    
  • Check Events: Dump dispatched events in a listener:
    public function onUserCreated(UserCreatedEvent $event) {
        dump($event->getUser());
    }
    

Extension Points

  1. Custom Validators Add constraints to the User entity:

    use Symfony\Component\Validator\Constraints as Assert;
    
    class AppUser extends BaseUser {
        /**
         * @Assert\Length(min=8)
         */
        private $password;
    }
    
  2. Override Templates The bundle uses Twig templates for emails/reset pages. Override them in templates/DarvinUserBundle/:

    {# templates/DarvinUserBundle/Reset/reset.html.twig #}
    <h1>Custom Reset Page</h1>
    
  3. API Resources Extend the bundle’s UserResource (if using API Platform):

    use DarvinStudio\UserBundle\ApiResource\UserResource as BaseUserResource;
    
    class AppUserResource extends BaseUserResource {
        public function getOperations(EntityManagerInterface $em) {
            $reflection = new \ReflectionClass($this);
            return [
                // Add custom operations
            ];
        }
    }
    
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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views