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

Customerbundle Laravel Package

edemy/customerbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require edemy/customerbundle
    

    Ensure eDemyFramework is installed and configured as a base dependency.

  2. Bundle Registration Add to config/bundles.php:

    return [
        // ...
        Edemy\CustomerBundle\EdemyCustomerBundle::class => ['all' => true],
    ];
    
  3. First Use Case Create a customer entity via CLI:

    php bin/console make:customer --name="John Doe" --email="john@example.com"
    

    Verify in the database (customers table) and via Tinker:

    $customer = \Edemy\CustomerBundle\Entity\Customer::find(1);
    
  4. Key Files to Review

    • src/Entity/Customer.php (Core model)
    • src/Resources/config/doctrine/Customer.orm.yml (Schema)
    • src/DependencyInjection/Configuration.php (Configurable options)

Implementation Patterns

Common Workflows

1. Customer Creation

Manual Entity Approach

use Edemy\CustomerBundle\Entity\Customer;
use Edemy\CustomerBundle\Factory\CustomerFactory;

$factory = new CustomerFactory();
$customer = $factory->createNamed('Jane Smith')
                    ->setEmail('jane@example.com')
                    ->setActive(true)
                    ->save();

return $customer->getId();

Form Integration

// src/Form/CustomerType.php
use Edemy\CustomerBundle\Form\CustomerType;

class RegistrationForm extends AbstractType {
    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder->add('customer', CustomerType::class);
    }
}

2. Data Access

Repository Usage

$repository = $this->getDoctrine()
    ->getRepository(\Edemy\CustomerBundle\Entity\Customer::class);

$activeCustomers = $repository->findBy(['active' => true]);
$customer = $repository->findOneByEmail('test@example.com');

QueryBuilder Extensions

// Custom query in a service
public function getCustomersByRole($role) {
    return $this->customerRepo->createQueryBuilder('c')
        ->where('c.role = :role')
        ->setParameter('role', $role)
        ->getQuery()
        ->getResult();
}

3. Events & Lifecycle

Subscribing to Events

// src/EventListener/CustomerListener.php
use Edemy\CustomerBundle\Event\CustomerEvents;

class CustomerListener {
    public static function getSubscribedEvents() {
        return [
            CustomerEvents::PRE_SAVE => 'onPreSave',
            CustomerEvents::POST_SAVE => 'onPostSave',
        ];
    }

    public function onPreSave(CustomerEvent $event) {
        $customer = $event->getCustomer();
        $customer->setUpdatedAt(new \DateTime());
    }
}

Triggering Events Manually

$event = new CustomerEvent($customer, 'custom_action');
$this->dispatcher->dispatch(CustomerEvents::CUSTOM_ACTION, $event);

4. API Integration

API Resource (API Platform Style)

# config/api/resources.yaml
resources:
    Edemy\CustomerBundle\Entity\Customer:
        collectionOperations:
            get:
                method: GET
                path: /customers
        itemOperations:
            get:
                method: GET
                path: /customers/{id}
            put:
                method: PUT

Custom Serialization

// src/Serializer/CustomerNormalizer.php
use Edemy\CustomerBundle\Entity\Customer;

class CustomerNormalizer implements NormalizerInterface {
    public function normalize($object, $format = null, array $context = []) {
        return [
            'id' => $object->getId(),
            'name' => $object->getFullName(),
            'email' => $object->getEmail(),
            'active' => $object->isActive(),
        ];
    }
}

Gotchas and Tips

Pitfalls

  1. Missing eDemy Framework Dependencies

    • The bundle assumes eDemyFramework is installed. If missing, expect:
      • ClassNotFoundException for core services (e.g., Dispatcher).
      • Fix: Install edemy/framework first or mock dependencies in tests.
  2. Doctrine Schema Conflicts

    • The bundle auto-generates a customers table. If your app already has a customers table:
      • Error: Column 'id' already exists.
      • Fix: Rename your table or extend the bundle’s Customer entity to avoid conflicts.
  3. Event Dispatcher Not Injected

    • If you forget to inject the EventDispatcherInterface:
      • Error: Call to a member function dispatch() on null.
      • Fix: Use dependency injection:
        public function __construct(private EventDispatcherInterface $dispatcher) {}
        
  4. Factory Overrides Not Applied

    • Custom factory methods may not persist if not called explicitly:
      // ❌ Won't save
      $customer = $factory->createNamed('Test');
      
      // ✅ Will save
      $customer = $factory->createNamed('Test')->save();
      

Debugging Tips

  1. Enable SQL Logging Add to .env:

    DOCTRINE_ORM_LOGGING=true
    DOCTRINE_ORM_LOGGING_PARAMS=true
    
  2. Check Event Dispatch Temporarily add a logger to events:

    public function onPreSave(CustomerEvent $event) {
        \Log::debug('Customer pre-save', ['customer' => $event->getCustomer()->toArray()]);
    }
    
  3. Validate Entity States Use the isValid() method on the Customer entity to check constraints:

    if (!$customer->isValid()) {
        foreach ($customer->getErrors() as $error) {
            \Log::error($error->getMessage());
        }
    }
    

Extension Points

  1. Custom Fields Extend the Customer entity:

    // src/Entity/ExtendedCustomer.php
    use Edemy\CustomerBundle\Entity\Customer;
    
    class ExtendedCustomer extends Customer {
        /**
         * @ORM\Column(type="string", nullable=true)
         */
        private $customField;
    
        // Getters/setters...
    }
    
  2. Override Factory Create a custom factory class:

    // src/Factory/CustomCustomerFactory.php
    use Edemy\CustomerBundle\Factory\CustomerFactory;
    
    class CustomCustomerFactory extends CustomerFactory {
        public function createWithDefaultRole($name) {
            return $this->createNamed($name)->setRole('default');
        }
    }
    
  3. Modify Serialization Override the normalizer:

    # config/services.yaml
    services:
        App\Serializer\CustomerNormalizer:
            tags: [serializer.normalizer]
            arguments: ['@app.customer.normalizer.inner']
    
  4. Add Custom Queries Extend the repository:

    // src/Repository/CustomerRepository.php
    use Edemy\CustomerBundle\Repository\CustomerRepository as BaseRepository;
    
    class CustomerRepository extends BaseRepository {
        public function findByRole($role) {
            return $this->createQueryBuilder('c')
                ->where('c.role = :role')
                ->setParameter('role', $role)
                ->getQuery()
                ->getResult();
        }
    }
    

Configuration Quirks

  1. Default Values The bundle sets active = false by default. Override in config/packages/edemy_customer.yaml:

    edemy_customer:
        default_active: true
    
  2. Entity Manager If using multiple Doctrine connections, specify the target entity manager:

    $customer = $this->getDoctrine()->getManager('custom_em')->find(Customer::class, 1);
    
  3. Validation Groups The bundle uses the Default validation group. Add custom groups in Customer.php:

    use Symfony\Component\Validator\Constraints as Assert;
    
    /**
     * @Assert\Email(groups={"registration"})
     */
    private $email;
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui