PHP code example of lstrojny / procrastinator-bundle

1. Go to this page and download the library: Download lstrojny/procrastinator-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lstrojny / procrastinator-bundle example snippets



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();
    }
}