Skip to content

Instantly share code, notes, and snippets.

@Raistlfiren
Last active January 28, 2016 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raistlfiren/3fcd114fddb1730014af to your computer and use it in GitHub Desktop.
Save Raistlfiren/3fcd114fddb1730014af to your computer and use it in GitHub Desktop.
Doctrine Entity Listener
services:
job_bundle.listener.job_listener:
class: JobBundle\Listener\JobListener
tags:
- { name: doctrine.orm.entity_listener }
orm:
default_entity_manager: ~
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
entity_managers:
default_repository_class:
entity_listeners:
JobBundle\Entity\Job:
listeners:
JobBundle\Listener\JobListener:
events:
type: preFlush
method: preFlush
<?php
/**
* Job Entity
*
* @ORM\HasLifecycleCallbacks
* @ORM\Table()
* @ORM\Entity(repositoryClass="JobBundle\Entity\JobRepository")
* @ORM\EntityListeners({"JobBundle\Listener\JobListener"})
*/
class Job {}
<?php
namespace JobBundle\Listener;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use JobBundle\Entity\Job;
class JobListener
{
public function preUpdateHandler(Job $job, PreUpdateEventArgs $event)
{
$company = $job;
$uow = $event->getEntityChangeSet();
echo 'test';
die();
}
public function prePersistHandler(Job $job, LifecycleEventArgs $event)
{
die();
}
public function postPersistHandler(Job $job, LifecycleEventArgs $event)
{
die();
}
public function postUpdateHandler(Job $job, LifecycleEventArgs $event)
{
die();
}
public function preFlushHandler(Job $job, PreFlushEventArgs $event)
{
die();
}
public function postLoadHandler(Job $job, LifecycleEventArgs $event)
{
die();
}
}
//Controller Line...
if ($editForm->isValid()) {
$em->flush();
}
@Raistlfiren
Copy link
Author

screen shot 2016-01-28 at 8 39 46 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment