Download the PHP package c33s/propel-di-behavior-bundle without Composer
On this page you can find all versions of the php package c33s/propel-di-behavior-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download c33s/propel-di-behavior-bundle
More information about c33s/propel-di-behavior-bundle
Files in c33s/propel-di-behavior-bundle
Package propel-di-behavior-bundle
Short Description Clean Symfony2 dependency injection for your Propel models
License MIT
Homepage https://github.com/vworldat/C33sPropelDIBehaviorBundle
Informations about the package propel-di-behavior-bundle
C33sPropelDIBehaviorBundle
Clean Symfony2 dependency injection for your Propel models
Installation
This bundle depends on GlorpenPropelBundle
. Install that one first.
Require c33s/propel-di-behavior-bundle
in your composer.json
file:
Add propel behaviors to your propel config:
Register the bundle in app/AppKernel.php
:
Usage
Add behavior to your propel models - either globally (use the c33s_di_global
name for that) or to a specific model.
You may inject Symfony2 services or parameters into any Model
or Query
class. Each definition consists of the service
or parameter name to inject (enclose parameters in %-chars) followed by optional getter methods and type hints for this methods, separated
by colons:
logger:getLogger:\Psr\Log\LoggerInterface
injects the Symfony2 logger service, making it accessible by$model->getLogger()
(or$query->getLogger()
) and providing\Psr\Log\LoggerInterface
as a type hint for that getterlogger
injects the Symfony2 logger service without an explicit getter. Use$model->getInjectedDependency('logger')
to access it.%locale%:getLocale:string
injects thelocale
parameter, providing a getLocale() method for accessing it.
Example schema
How it works
C33sPropelDIBehaviorBundle
registers event listeners for model.create
and query.create
that are processed by GlorpenPropelBundle
. Upon each
model or query creation anonymous callbacks for each service will be injected into the classes, making sure that only the services that were specified
in the schema can be accessed. The callback furthermore ensures that no services will be instantiated without actually being used.
So far this is the cleanest way I have found to inject specific Symfony2 dependencies into Propel models without messing around with the full DI container.