Installation
composer require baconmanager/user-bundle
Ensure baconmanager/acl-bundle is also installed (required dependency).
Enable the Bundle
Add to config/bundles.php:
BaconManager\UserBundle\BaconUserBundle::class => ['all' => true],
BaconManager\AclBundle\AclBundle::class => ['all' => true],
Database Migration
Run migrations (if provided) or manually create tables based on FOSUserBundle schema (this bundle extends it). Example:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
First Use Case Register a new user via the default FOSUserBundle registration form (extended by this bundle):
use BaconManager\UserBundle\Entity\User;
$user = new User();
$user->setUsername('testuser');
$user->setPlainPassword('secure123');
$user->setEmail('test@example.com');
$userManager = $this->get('fos_user.user_manager');
$userManager->updateUser($user);
User Management
Extend FOSUserBundle's UserManager to leverage ACL integration:
// In a service or controller
$userManager = $this->get('bacon_user.user_manager');
$user = $userManager->findUserBy(['email' => 'user@example.com']);
// Assign ACL roles (if ACL-Bundle is configured)
$aclProvider = $this->get('bacon_acl.acl_provider');
$aclProvider->assignRole('ROLE_ADMIN', $user);
Custom User Fields
Add fields to the User entity (extend BaconManager\UserBundle\Entity\User):
// src/Entity/CustomUser.php
namespace App\Entity;
use BaconManager\UserBundle\Entity\User as BaseUser;
class CustomUser extends BaseUser
{
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $customField;
// Getters/setters...
}
Update config/packages/bacon_user.yaml to point to your custom entity.
Authentication Integration
Override FOSUserBundle templates or use its events (e.g., security.authentication.success):
# config/packages/security.yaml
services:
App\EventListener\CustomAuthListener:
tags:
- { name: kernel.event_listener, event: security.authentication.success, method: onAuthenticationSuccess }
API Integration (Symfony API Platform) Enable serialization for the user entity:
# config/packages/api_platform.yaml
resources:
App\Entity\CustomUser:
collectionOperations:
get:
security: "is_granted('ROLE_USER')"
baconmanager/acl-bundle is configured before using role-based features.fos_user.registered or fos_user.created to trigger custom logic:
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class UserSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
FOSUserEvents::REGISTERED => 'onUserRegistered',
];
}
public function onUserRegistered(UserEvent $event)
{
// Extend user data or log registration
}
}
config/packages/fos_user.yaml:
registration:
form:
type: App\Form\RegistrationFormType
Missing ACL-Bundle Configuration
ServiceNotFoundException.baconmanager/acl-bundle is installed and configured in config/bundles.php.Entity Inheritance Issues
PropertyAccessException.User entity class is properly extended:
php bin/console cache:clear
Deprecated FOSUserBundle Methods
UserManager methods like createUser() may not work as expected.updateUser() or reloadUser() instead (check FOSUserBundle 2.x docs).Migration Conflicts
php bin/console doctrine:schema:drop --force
php bin/console doctrine:schema:update --force
config/packages/dev/doctrine.yaml:
dbal:
logging: true
profiling: true
public function onUserRegistered(UserEvent $event)
{
dump($event->getUser()); // Debug user data
}
php bin/console bacon:acl:debug
Custom User Providers
Override the default UserProvider in config/packages/security.yaml:
providers:
bacon_user_provider:
id: App\Security\User\CustomUserProvider
Template Overrides
Copy templates from vendor/baconmanager/user-bundle/Resources/views to templates/bacon_user/ and modify.
Event Dispatching
Extend existing events (e.g., fos_user.profile.edit) or create custom ones:
// Dispatch a custom event
$dispatcher->dispatch(new UserCustomEvent($user));
API Resource Customization
Use API Platform’s Denormalizer/Normalizer to control serialization:
// src/Serializer/UserNormalizer.php
use ApiPlatform\Core\Serializer\Normalizer\AbstractItemNormalizer;
class UserNormalizer extends AbstractItemNormalizer
{
public function normalize($object, $format = null, array $context = [])
{
$data = parent::normalize($object, $format, $context);
$data['custom_field'] = $object->getCustomField();
return $data;
}
}
How can I help you explore Laravel packages today?