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

Ccdn User Profile Bundle Laravel Package

codeconsortium/ccdn-user-profile-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your composer.json:

    composer require codeconsortium/ccdn-user-profile-bundle
    

    Enable it in app/AppKernel.php under new CCDNUserProfileBundle().

  2. First Use Case The bundle provides a UserProfile entity and related services. Start by generating the entity and its CRUD operations:

    php app/console doctrine:generate:entity CCDNUserProfileBundle:UserProfile
    php app/console doctrine:generate:crud CCDNUserProfileBundle:UserProfile
    

    Access the generated CRUD routes (e.g., /user_profile/).

  3. Configuration Check app/config/config.yml for default settings. Override as needed:

    ccdn_user_profile:
        # Customize fields, validation, or services here
        default_profile_fields: ['first_name', 'last_name', 'email']
    

Implementation Patterns

Core Workflows

  1. Profile Management

    • Create/Update: Use the UserProfileManager service to handle profile logic:
      $manager = $this->get('ccdn_user_profile.manager');
      $profile = $manager->createProfile($userId, ['first_name' => 'John']);
      $manager->updateProfile($profile, ['last_name' => 'Doe']);
      
    • Validation: Leverage Symfony’s validator component (configured in validation.yml).
  2. Integration with Security

    • Extend the User entity to include a UserProfile relationship:
      // In User.php
      /**
       * @ORM\OneToOne(targetEntity="CCDNUserProfileBundle\Entity\UserProfile", mappedBy="user")
       */
      private $profile;
      
    • Use the UserProfileListener to auto-create profiles on user registration:
      # app/config/config.yml
      services:
          ccdn_user_profile.listener:
              class: CCDNUserProfileBundle\EventListener\UserProfileListener
              tags:
                  - { name: kernel.event_listener, event: security.user.provider.created, method: onUserCreated }
      
  3. Custom Fields

    • Add fields to the UserProfile entity:
      // src/CCDN/UserProfileBundle/Entity/UserProfile.php
      /**
       * @ORM\Column(type="string", nullable=true)
       */
      private $customField;
      
    • Update the bundle’s configuration to include the new field:
      ccdn_user_profile:
          default_profile_fields: ['first_name', 'last_name', 'custom_field']
      
  4. API Exposure

    • Use FOSRestBundle or similar to expose profile endpoints:
      # app/config/routing.yml
      ccdn_user_profile_rest:
          resource: "@CCDNUserProfileBundle/Resources/config/routing/rest.yml"
          prefix: /api
      

Gotchas and Tips

Common Pitfalls

  1. Doctrine Migrations

    • The bundle assumes a UserProfile table exists. Run migrations after installation:
      php app/console doctrine:schema:update --force
      
    • Tip: Use doctrine:migrations:diff to generate custom migrations if the bundle’s schema doesn’t fit your needs.
  2. Symfony 2.4 Legacy

    • The bundle targets Symfony 2.4 (old!). Test thoroughly with:
      • PHP 5.3.2+ (use php53 Docker images if needed).
      • Doctrine 2.1+ (avoid newer Doctrine features).
    • Workaround: Override deprecated services in app/config/services.yml:
      services:
          ccdn_user_profile.twig.extension:
              class: CCDNUserProfileBundle\Twig\ProfileExtension
              tags: ['twig.extension']
      
  3. Event Listeners

    • The UserProfileListener may conflict with other bundles (e.g., FOSUserBundle). Disable it if not needed:
      # app/config/config.yml
      ccdn_user_profile:
          auto_create_profiles: false
      
  4. Validation Overrides

    • Custom validation rules may not apply if the bundle’s constraints are hardcoded. Override the UserProfile entity’s validation:
      // src/CCDN/UserProfileBundle/Resources/config/validation.yml
      CCDN\UserProfileBundle\Entity\UserProfile:
          constraints:
              - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
                  fields: email
                  message: "Email already exists."
      

Debugging Tips

  1. Check Events

    • Enable debug mode to see if events (e.g., security.user.provider.created) are fired:
      // app/AppKernel.php
      $this->registerBundles([
          new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
          new CCDN\UserProfileBundle\CCDNUserProfileBundle(),
      ]);
      
    • Use bin/console debug:event-dispatcher to list available events.
  2. Database Schema

    • Dump the schema to verify tables/columns:
      php app/console doctrine:schema:dump-sql
      
  3. Service Availability

    • Verify the UserProfileManager is autowired:
      php app/console debug:container ccdn_user_profile.manager
      

Extension Points

  1. Custom Profile Types

    • Extend the UserProfile entity for multi-tenancy or roles:
      // src/AppBundle/Entity/CustomProfile.php
      class CustomProfile extends \CCDN\UserProfileBundle\Entity\UserProfile
      {
          /**
           * @ORM\Column(type="string")
           */
          private $role;
      }
      
    • Update the bundle’s UserProfileType form class (if needed).
  2. API Serialization

    • Override the UserProfile serializer normalization:
      # app/config/config.yml
      jms_serializer:
          metadata:
              directories:
                  CCDNUserProfileBundle:
                      namespace_prefix: "CCDN\\UserProfileBundle"
                      path: "%kernel.root_dir%/Resources/config/serializer"
      
      Create app/Resources/config/serializer/CCDN.UserProfileBundle.Entity.UserProfile.yml:
      CCDN\UserProfileBundle\Entity\UserProfile:
          exclusion_policy: ALL
          properties:
              id:
                  expose: true
              firstName:
                  expose: true
                  serialized_name: first_name
      
  3. Testing

    • Use functional tests to verify profile creation:
      // src/AppBundle/Tests/Functional/UserProfileTest.php
      public function testProfileCreation()
      {
          $client = static::createClient();
          $client->request('POST', '/user_profile', [
              'first_name' => 'Test',
              'last_name'  => 'User',
          ]);
          $this->assertEquals(201, $client->getResponse()->getStatusCode());
      }
      
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