Download the PHP package karser/glorpen-propel-bundle without Composer
On this page you can find all versions of the php package karser/glorpen-propel-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download karser/glorpen-propel-bundle
More information about karser/glorpen-propel-bundle
Files in karser/glorpen-propel-bundle
Package glorpen-propel-bundle
Short Description Propel events and model extending for Symfony2.
License GPL-3.0
Informations about the package glorpen-propel-bundle
GlorpenPropelBundle
Additional Propel integration for Symfony2.
Official repositories
For forking and other funnies
BitBucket: https://bitbucket.org/glorpen/glorpenpropelbundle - main repo
GitHub: https://github.com/glorpen/GlorpenPropelBundle
How to install
- add requirements to composer.json:
- enable the plugin in your AppKernel class
app/AppKernel.php
- add behavior configuration to propel config
To enable all behaviors at once you can import to your configuration @GlorpenPropelBundle/Resources/config/config.yml and config_dev.yml accordingly.
Example for config.yml:
Propel Events
If you didn't import config.yml providen by this bundle, you have to add event behavior to your propel configuration and change PropelPDO class.
And in config_dev.yml:
Listening for propel hooks
- register listener
Available events
Event class: `ConnectionEvent`
- connection.create
- connection.commit.pre
- connection.commit.post
- connection.rollback.post
- connection.rollback.pre
Event class: `ModelEvent`
- model.insert.post
- model.update.post
- model.delete.post
- model.save.post
- model.insert.pre
- model.update.pre
- model.delete.pre
- model.save.pre
- model.construct
Event class: `QueryEvent`
- query.delete.pre
- query.delete.post
- query.select.pre
- query.update.pre
- query.update.post
- query.construct
Event class: `PeerEvent`
- construct
Will be called on model/query/peer construct/delete/update/etc
ContainerAwareInterface for model
You can implement ContainerAwareInterface on your model to get access to Container through built-in service. Container is injected in model.construct event.
If you find yourself with error like `Serialization of 'Closure' is not allowed` it is probably about some not serializable services injected in model (since propel occasionally serializes and unserializes data).
Transaction events
Just like with Doctrine @ORM\HasLifecycleCallbacks you can handle non db logic in model in db transaction.
Commit hooks will be run just before PDO transaction commit and rollback just before rolback and only on saved models (if exception was thrown in preCommit hook). Methods provided by EventBehavior are:
- preCommit
- preCommitSave
- preCommitUpdate
- preCommitInsert
- preCommitDelete
- preRollback
- preRollbackSave
- preRollbackUpdate
- preRollbackInsert
- preRollbackDelete
Be aware that when using transaction on big amount of model objects with on-demand formatter they still will be cached inside service so you can exhaust available php memory.
And example how you can use available hooks (code mostly borrowed from Symfony2 cookbook):
Custom events
You can trigger events with generic or custom Event class, in following example ValidationEvent.
- create ValidationEvent event
- register listener in services.xml
- and then use it within model class
Model Extending
If you didn't import config.yml providen by this bundle, you have to add extend behavior to your propel configuration.
With behavior enabled you can define custom model classes for use with Propel.
You can extend only Model classes this way (extending Peers/Queries shouldn't be needed).
Calls to Query::find(), Peer::populateObject() etc. will now return your extended class objects.
In short it fixes:
- extending Model classes used by other bundles (eg. FOSUserBundle)
- queries/peer's returning proper isntances
- creating proper Query instance when calling `SomeQuery::create()`
Mapping usage
In config.yml:
Dynamic/Services usage
You can create dynamic extends by using services.
Your service should implement Glorpen\Propel\PropelBundle\Provider\OMClassProvider interface.
In services.xml:
FOSUserBundle and AdminGenerator
With above config, you can generate backend with AdminGenerator for FOSUser edit/creation/etc. For now you have to create empty UserQuery and UserPeer classes and then whole backend for user model should work :)
Other goodies
PlainModelJoin
Allows to inject data into `ON` clause for eg. comparing field to date or field from other joined table.
Remember that provided values are added as-is, without parsing for aliases and escaping.
Usage: