Installation:
composer require damien-carcel/user-bundle
Register the bundle in config/bundles.php:
return [
// ...
DamienCarcel\UserBundle\CarcelUserBundle::class => ['all' => true],
];
Database Migration: Run migrations to create the required tables:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
First Use Case: Create a user via CLI:
php bin/console fos:user:create --username=test --email=test@example.com --super-admin
Authenticate via Symfony’s security system (e.g., login form or API token).
User Registration:
Extend the default registration form by overriding the RegistrationFormType in your own bundle:
# config/packages/carcel_user.yaml
carcel_user:
registration_form:
type: App\Form\RegistrationFormType
Authentication:
Use Symfony’s security system with the bundle’s provided UserProvider:
// src/Security/UserProvider.php
use DamienCarcel\UserBundle\Security\UserProvider as CarcelUserProvider;
class CustomUserProvider extends CarcelUserProvider { ... }
Profile Management:
Customize the profile update logic by overriding the ProfileFormType:
// src/Form/ProfileFormType.php
use DamienCarcel\UserBundle\Form\ProfileFormType as BaseProfileFormType;
class ProfileFormType extends BaseProfileFormType {
public function buildForm(FormBuilderInterface $builder, array $options) {
parent::buildForm($builder, $options);
$builder->add('custom_field', TextType::class);
}
}
API Integration:
Use Symfony’s serializer with the bundle’s User entity:
// src/Serializer/UserNormalizer.php
use DamienCarcel\UserBundle\Entity\User;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class UserNormalizer implements NormalizerInterface {
public function normalize($object, $format = null, array $context = []) {
if (!$object instanceof User) {
return;
}
return [
'id' => $object->getId(),
'email' => $object->getEmail(),
// Add custom fields
];
}
}
Deprecated Bundle:
Configuration Overrides:
config/packages/carcel_user.yaml:
carcel_user:
db_driver: orm # or 'mongodb'
firewall_name: main # Ensure this matches your security.yaml
Doctrine Migrations:
User entity, drop and recreate the database or manually adjust migrations to avoid conflicts.Security Quirks:
php bin/console cache:clear
Enable Debug Mode:
# config/packages/dev/doctrine.yaml
doctrine:
dbal:
logging: true
profiling: true
Check Events:
The bundle dispatches events like user.registered or user.updated. Listen to them in your EventSubscriber:
use DamienCarcel\UserBundle\Event\UserEvents;
class CustomUserSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
UserEvents::REGISTERED => 'onUserRegistered',
];
}
}
Custom Fields:
Add fields to the User entity (extend DamienCarcel\UserBundle\Entity\User):
// src/Entity/User.php
use DamienCarcel\UserBundle\Entity\User as BaseUser;
class User extends BaseUser {
/**
* @ORM\Column(type="string", nullable=true)
*/
private $customField;
}
Validation:
Override validation constraints in your User entity or form types.
Templates: Override Twig templates by copying them from:
vendor/damien-carcel/user-bundle/Resources/views/
to:
templates/bundles/carceluser/
API Tokens:
If using API authentication, integrate with lexik/jwt-authentication-bundle and ensure the User entity implements Lexik\Bundle\JWTAuthenticationBundle\Security\User\JWTUserInterface.
```markdown
---
How can I help you explore Laravel packages today?