Weave 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

Usersbundle Laravel Package

dyatlovk/usersbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require dyatlovk/usersbundle
    

    Enable the bundle in config/bundles.php (Symfony) or config/app.php (Laravel via Symfony bridge):

    Dyatlovk\UserBundle\UserBundle::class => ['all' => true],
    
  2. Publish Configuration Run the publisher command to generate default config:

    php artisan vendor:publish --provider="Dyatlovk\UserBundle\UserBundle" --tag="config"
    

    (For Laravel, use php artisan config:publish if needed.)

  3. First Use Case Create a user via the bundle’s service:

    use Dyatlovk\UserBundle\Entity\User;
    use Dyatlovk\UserBundle\Service\UserManager;
    
    $userManager = $this->get('dyatlovk_user.user_manager');
    $user = $userManager->createUser([
        'email' => '[email protected]',
        'password' => 'plaintext_password',
        'roles' => ['ROLE_USER'],
    ]);
    

Implementation Patterns

Core Workflows

  1. User Creation & Management

    • Use UserManager service for CRUD operations:
      $user = $userManager->findUserByEmail('[email protected]');
      $userManager->updateUser($user, ['roles' => ['ROLE_ADMIN']]);
      $userManager->deleteUser($user);
      
  2. Authentication Integration

    • Extend Symfony’s security system by configuring security.yaml:
      firewalls:
          main:
              provider: dyatlovk_user.user_provider
      providers:
          dyatlovk_user.user_provider:
              entity: { class: Dyatlovk\UserBundle\Entity\User, property: email }
      
  3. Event Listeners

    • Subscribe to user lifecycle events (e.g., UserEvents::POST_REGISTER):
      use Dyatlovk\UserBundle\Event\UserEvents;
      use Symfony\Component\EventDispatcher\EventSubscriberInterface;
      
      class UserSubscriber implements EventSubscriberInterface
      {
          public static function getSubscribedEvents()
          {
              return [
                  UserEvents::POST_REGISTER => 'onUserRegistered',
              ];
          }
      
          public function onUserRegistered(UserEvent $event)
          {
              // Send welcome email, etc.
          }
      }
      
  4. Custom Fields

    • Extend the User entity by overriding the bundle’s base class:
      use Dyatlovk\UserBundle\Entity\User as BaseUser;
      
      class User extends BaseUser
      {
          /**
           * @ORM\Column(type="string", nullable=true)
           */
          private $customField;
      }
      

Gotchas and Tips

Pitfalls

  1. Configuration Overrides

    • Ensure config/packages/dyatlovk_user.yaml is merged correctly. Use dump(config('dyatlovk_user')) to debug.
  2. Entity Inheritance

    • If extending User, regenerate migrations:
      php artisan make:migration extend_users_table --table=users
      
  3. Security Provider Mismatch

    • Verify security.yaml points to the correct user_provider (e.g., dyatlovk_user.user_provider).
  4. Event Dispatching

    • Events may not fire if the EventDispatcher isn’t autowired. Explicitly bind it:
      $dispatcher = $this->get('event_dispatcher');
      $dispatcher->dispatch(new UserEvent($user), UserEvents::POST_REGISTER);
      

Tips

  1. Debugging

    • Enable Symfony’s profiler to inspect user events and security context.
  2. Performance

    • Cache user lookups in UserManager for high-traffic apps:
      $user = $userManager->findUserBy(['email' => '[email protected]'], true); // Enable cache
      
  3. Testing

    • Use the bundle’s UserFactory for test data:
      $user = $this->get('dyatlovk_user.user_factory')->create();
      
  4. Laravel-Specific

    • For Laravel, bridge Symfony services via SymfonyBridgeServiceProvider:
      $this->app->bind('dyatlovk_user.user_manager', function ($app) {
          return new UserManager($app['doctrine.orm.entity_manager']);
      });
      
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.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log