PHP code example of desarrolla2 / async-event-dispatcher-bundle

1. Go to this page and download the library: Download desarrolla2/async-event-dispatcher-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/ */

    

desarrolla2 / async-event-dispatcher-bundle example snippets


// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Desarrolla2\AsyncEventDispatcherBundle\AsyncEventDispatcherBundle(),
        );

        // ...
    }

    // ...
}




namespace CoreBundle\Controller;

use CoreBundle\EventDispatcher\AsyncEvents;
use Desarrolla2\AsyncEventDispatcherBundle\Event\Event;

class MessageController extends AbstractController
{
    public function createAction()
    {
        $manager = $this->container->get('desarrolla2.async_event_dispatcher');
        $manager->dispatch(
            AsyncEvents::NAME_EVENT,
            new Event(['date' => (new \DateTime())->format('Ymd')])
        );
    }
}



namespace CoreBundle\EventSubscriber;

use CoreBundle\EventDispatcher\AsyncEvents;
use Desarrolla2\AsyncEventDispatcherBundle\Event\Event;

class ExampleSubscriber extends AbstractEventSubscriber
{
    public static function getSubscribedEvents()
    {
        return [
            AsyncEvents::NAME_EVENT => 'onUpdateRequested',
        ];
    }

    public function onUpdateRequested(Event $event)
    {
        /* CODE */
    }
}