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],
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.)
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'],
]);
User Creation & Management
UserManager service for CRUD operations:
$user = $userManager->findUserByEmail('user@example.com');
$userManager->updateUser($user, ['roles' => ['ROLE_ADMIN']]);
$userManager->deleteUser($user);
Authentication Integration
security.yaml:
firewalls:
main:
provider: dyatlovk_user.user_provider
providers:
dyatlovk_user.user_provider:
entity: { class: Dyatlovk\UserBundle\Entity\User, property: email }
Event Listeners
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.
}
}
Custom Fields
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;
}
Configuration Overrides
config/packages/dyatlovk_user.yaml is merged correctly. Use dump(config('dyatlovk_user')) to debug.Entity Inheritance
User, regenerate migrations:
php artisan make:migration extend_users_table --table=users
Security Provider Mismatch
security.yaml points to the correct user_provider (e.g., dyatlovk_user.user_provider).Event Dispatching
EventDispatcher isn’t autowired. Explicitly bind it:
$dispatcher = $this->get('event_dispatcher');
$dispatcher->dispatch(new UserEvent($user), UserEvents::POST_REGISTER);
Debugging
Performance
UserManager for high-traffic apps:
$user = $userManager->findUserBy(['email' => 'user@example.com'], true); // Enable cache
Testing
UserFactory for test data:
$user = $this->get('dyatlovk_user.user_factory')->create();
Laravel-Specific
SymfonyBridgeServiceProvider:
$this->app->bind('dyatlovk_user.user_manager', function ($app) {
return new UserManager($app['doctrine.orm.entity_manager']);
});
How can I help you explore Laravel packages today?