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

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' => 'user@example.com',
        'password' => 'plaintext_password',
        'roles' => ['ROLE_USER'],
    ]);
    

Implementation Patterns

Core Workflows

  1. User Creation & Management

    • Use UserManager service for CRUD operations:
      $user = $userManager->findUserByEmail('user@example.com');
      $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' => 'user@example.com'], 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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui