PHP code example of sebk / small-events-swoft

1. Go to this page and download the library: Download sebk/small-events-swoft 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/ */

    

sebk / small-events-swoft example snippets




namespace App\Consumer;

use Sebk\SmallEventsSwoft\Consumer\AbstractSmallConsumer;

class TestConsumer extends AbstractSmallConsumer
{

    public function __construct()
    {
        $this->queueName = 'test';

        parent::__construct();
    }

    public function consume($messageContent): bool
    {
        var_dump($messageContent);

        return true;
    }

}



namespace App\Event;

use Swoft\Event\Annotation\Mapping\Subscriber;
use Swoft\Event\EventInterface;
use Swoft\Event\EventSubscriberInterface;

/**
 * @Subscriber()
 */
class TestSubscriber implements EventSubscriberInterface
{

    public static function getSubscribedEvents(): array
    {
        return [
            'testEvent' => 'handleTest',
        ];
    }

    public function handleTest(EventInterface $event)
    {
        dump($event->getParams());
    }

}