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

Propel Di Behavior Bundle Laravel Package

c33s/propel-di-behavior-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Prerequisites: Install GlorpenPropelBundle first via Composer.
  2. Installation: Add the bundle to composer.json:
    composer require c33s/propel-di-behavior-bundle
    
  3. Configure Propel: Add the behavior to app/config/config.yml:
    propel:
        behaviors:
            c33s_di: vendor.c33s.propel-di-behavior-bundle.src.C33sPropelDependencyCollectorBehavior
    
  4. Register Bundle: Include the bundle in AppKernel.php:
    new C33s\PropelDIBehaviorBundle\C33sPropelDIBehaviorBundle(),
    
  5. First Use Case: Inject a Symfony service into a Propel model:
    // In your model's schema.xml or behavior definition
    <behavior name="c33s_di">
        <parameter name="service">logger</parameter>
        <parameter name="property">logger</parameter>
    </behavior>
    

Implementation Patterns

Dependency Injection Workflows

  1. Model-Level Injection:

    • Define dependencies in schema.xml for a specific model:
      <behavior name="c33s_di">
          <parameter name="service">twig</parameter>
          <parameter name="property">twigEngine</parameter>
      </behavior>
      
    • Access injected services via the model’s property (e.g., $model->twigEngine).
  2. Global Injection:

    • Use c33s_di_global for shared dependencies across all models:
      propel:
          behaviors:
              c33s_di_global: vendor.c33s.propel-di-behavior-bundle.src.C33sPropelDependencyCollectorBehavior
      
    • Override globally in specific models if needed.
  3. Query-Level Injection:

    • Inject services into Query classes via the same behavior:
      <behavior name="c33s_di" class="Query">
          <parameter name="service">security.token_storage</parameter>
          <parameter name="property">tokenStorage</parameter>
      </behavior>
      
  4. Parameter Injection:

    • Inject Symfony parameters (e.g., app.path.base) alongside services:
      <behavior name="c33s_di">
          <parameter name="parameter">app.path.base</parameter>
          <parameter name="property">basePath</parameter>
      </behavior>
      

Integration Tips

  • Lazy Loading: Services are injected lazily during model initialization (avoids circular dependencies).
  • Service Aliases: Use fully qualified service IDs (e.g., security.token_storage) or aliases defined in services.yml.
  • Testing: Mock dependencies in PHPUnit by overriding the container or using setService() in tests:
    $model->setService('logger', $mockLogger);
    

Gotchas and Tips

Pitfalls

  1. Missing GlorpenPropelBundle:

    • The bundle requires GlorpenPropelBundle. Forgetting this causes silent failures.
    • Fix: Install and configure GlorpenPropelBundle first.
  2. Case Sensitivity:

    • Service/parameter names in schema.xml must match exactly those in services.yml or parameters.yml.
    • Tip: Use YAML anchors (&service) for consistency.
  3. Circular Dependencies:

    • Injecting a model into itself (directly or indirectly) via DI causes runtime errors.
    • Workaround: Use setters or lazy initialization.
  4. Behavior Overrides:

    • Global (c33s_di_global) and model-specific behaviors merge. Unexpected behavior may occur if properties clash.
    • Tip: Prefix properties (e.g., globalLogger, modelLogger) to avoid conflicts.
  5. Propel Schema Updates:

    • Adding/removing behaviors requires re-building the Propel schema:
      php bin/console propel:build --no-confirm
      

Debugging

  • Verify Injection: Check if properties are populated by dumping the model:
    var_dump(get_object_vars($model)); // Look for your injected property.
    
  • Container Dumping: List available services to debug missing injections:
    php bin/console debug:container
    
  • Logs: Enable debug mode (app.debug=true) to catch initialization errors.

Extension Points

  1. Custom Behaviors: Extend C33sPropelDependencyCollectorBehavior to add validation or post-processing:
    class CustomDIBehavior extends C33sPropelDependencyCollectorBehavior {
        protected function postInject(Model $model) {
            // Custom logic after injection.
        }
    }
    
  2. Dynamic Properties: Use PHP magic methods (__get, __set) to dynamically inject services:
    public function __get($name) {
        if ($this->container->has($name)) {
            return $this->container->get($name);
        }
        return parent::__get($name);
    }
    
  3. Event Listeners: Hook into Propel events (e.g., postInsert) to conditionally inject dependencies:
    $model->addListener('postInsert', function ($model) {
        $model->setService('event_dispatcher', $this->container->get('event_dispatcher'));
    });
    
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