Ich habe diese Teilnehmer sich in AppBundle\DoctrineListeners
Körper es ist dieseSymfony3.3, Doktrin2. EventSubscriber, auf Update nicht ausgeführt
namespace AppBundle\DoctrineListeners;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\OnFlushEventArgs;
use AppBundle\Entity\Bing\KeyWordReport;
use Doctrine\ORM\Events;
/**
* Listener used to on update fielt create history
*/
class KeywordSubscriber implements EventSubscriber
{
public function onFlush(OnFlushEventArgs $args)
{
throw new \Exception("Error Processing Request", 1); //for testing
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
foreach ($uow->getScheduledEntityUpdates() as $updated) {
if ($updated instanceof KeyWordReport) {
//do some work
}
}
$uow->computeChangeSets();
}
public function getSubscribedEvents()
{
return [Events::onFlush => ['onFlush', 10], Events::preUpdate];
}
}
i autoconfigure in symfony eingeführt bin mit 3,3
service.yml
services:
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
in Entität habe ich in Annotation diese * @ORM\EntityListeners({"AppBundle\DoctrineListeners\KeywordSubscriber"})
warum es nicht ausgeführt wird?
Lehre 'EventSubscribes' (http://symfony.com/doc/current/doctrine/event_listeners_subscribers.html) und' EntityListeners' (https: // symfony. com/doc/current/bundles/DoctrineBundle/entity-listeners.html) sind verschiedene Dinge. Und hier gibt es nichts mit Autowiring zu tun (Ihr Abonnent hat keine Abhängigkeit). Wenn Sie jedoch in Version 3.3 sind, können Sie die automatische Autoloading- und Autokonfigurationsfunktion verwenden, um diese Klasse automatisch als Dienst mit dem entsprechenden Tag zu registrieren. –