lstrojny/procrastinator-bundle

Procrastinator (lstrojny/procrastinator) 的 Symfony2 集成

2.4.1 2014-01-19 22:49 UTC

This package is auto-updated.

Last update: 2024-09-16 05:57:34 UTC


README

Symfony2 集成 Procrastinator

控制器中的示例用法:仅在 Doctrine 的 postFlush 事件发生时执行事件

<?php
use Procrastinator\Deferred\DoctrineEventConditionalDeferred as Deferred;
use Doctrine\ORM\Events as OrmEvents;

class MyController ...
{
    public function sendMailAction()
    {
        $entry = new Entity();
        $entry->setText('hello world');

        $message = Message::newInstance()
                    ->setSubject('hello')
                    ->setBody('new entry');
        $mailer = $this->get('mailer');


        $procrastinator->register(
            $procrastinator
                ->newDeferred()
                ->ifDoctrineEvent(OrmEvents::postFlush)
                ->name('sendMail')
                ->call(function() use ($mailer, $message) { $mailer->send($message); })
                ->build()
        );


        $em = $this->get('doctrine.orm.default_entity_manager');
        $em->persist($entry);
        $em->flush();
    }
}