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

User Bundle Laravel Package

carcel/user-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require damien-carcel/user-bundle
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        DamienCarcel\UserBundle\CarcelUserBundle::class => ['all' => true],
    ];
    
  2. Database Migration: Run migrations to create the required tables:

    php bin/console doctrine:migrations:diff
    php bin/console doctrine:migrations:migrate
    
  3. 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).


Implementation Patterns

Core Workflows

  1. 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
    
  2. 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 { ... }
    
  3. 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);
        }
    }
    
  4. 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
            ];
        }
    }
    

Gotchas and Tips

Common Pitfalls

  1. Deprecated Bundle:

  2. Configuration Overrides:

    • The bundle relies on Symfony’s parameter bag. Override configurations in config/packages/carcel_user.yaml:
      carcel_user:
          db_driver: orm       # or 'mongodb'
          firewall_name: main  # Ensure this matches your security.yaml
      
  3. Doctrine Migrations:

    • If you customize the User entity, drop and recreate the database or manually adjust migrations to avoid conflicts.
  4. Security Quirks:

    • The bundle uses FOSUserBundle’s security logic. If you modify roles or providers, clear the cache:
      php bin/console cache:clear
      

Debugging Tips

  1. Enable Debug Mode:

    # config/packages/dev/doctrine.yaml
    doctrine:
        dbal:
            logging: true
            profiling: true
    
  2. 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',
            ];
        }
    }
    

Extension Points

  1. 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;
    }
    
  2. Validation: Override validation constraints in your User entity or form types.

  3. Templates: Override Twig templates by copying them from:

    vendor/damien-carcel/user-bundle/Resources/views/
    

    to:

    templates/bundles/carceluser/
    
  4. 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
---
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware