Get support for KnpLabs/rad-doctrine-event
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
KnpLabs/rad-doctrine-event
DEPRECATED
Unfortunately we decided to not maintain this project anymore (see why). If you want to mark another package as a replacement for this one please send an email to hello@knplabs.com.
Rapid Application Development : Doctrine Events
Access to your doctrine events from the Symfony DIC.
Official maintainers:
Installation
composer require knplabs/rad-doctrine-event ~2.1
And with Symfony:
class AppKernel
{
function registerBundles()
{
$bundles = array(
//...
new Knp\Rad\DoctrineEvent\Bundle\DoctrineEventBundle(),
//...
);
//...
return $bundles;
}
}
Use
Context
Let's say you have the following entity:
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class User
{
//...
}
Before
In order to plug doctrine events for that entity, we usually do:
namespace App\EventListener;
use App\Entity\User;
use Doctrine\ORM\Event\LifecycleEventArgs;
class UserListener
{
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if (false === $entity instanceof User) {
return;
}
// Some stuff
}
}
#services.yml
services:
app.event_listener.user_listener:
class: App\EventListener\UserListener
tags:
- { name: doctrine.event_listener, event: pre_persist, method: prePersist }
After
But with the KnpRadDoctrineEvent you will need:
namespace App\EventListener;
use Knp\Rad\DoctrineEvent\Event\DoctrineEvent;
class UserListener
{
public function prePersist(DoctrineEvent $event)
{
$entity = $event->getEntity();
// Some stuff
}
}
#services.yml
services:
app.event_listener.user_listener:
class: App\EventListener\UserListener
tags:
- { name: kernel.event_listener, event: app.entity.user.pre_persist, method: prePersist }
Inheritance
Context
Let's say you have an entity extending another entity:
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"page" = "App\Entity\Customer"})
*/
class User
{
//...
}
namespace App\Entity;
use App\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class Customer extends User
{
//...
}
Events
The parent entity events are dispatched just before the children entities:
For | First event | Second Event |
---|---|---|
pre_persist | app.entity.user.pre_persist | app.entity.customer.pre_persist |
post_update | app.entity.user.pre_update | app.entity.customer.pre_update |
... |
Terminate
Each post
(post_persist
, post_update
, post_remove
, post_load
) event is also redispatched during the kernel.terminate
event.
Event | Terminate event |
---|---|
app.entity.user.post_persist | app.entity.user.post_persist_terminate |
app.entity.user.post_update | app.entity.user.post_update_terminate |
app.entity.user.post_remove | app.entity.user.post_remove_terminate |
app.entity.user.post_load | app.entity.user.post_load_terminate |
Configuration
You can restrict event re-dispatching to specific entities.
You just have to follow this configuration:
knp_rad_doctrine_event:
entities:
- MyBundle\Entity\User
Then events will be dispatched only for the entity MyBundle\Entity\User
.
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2