PHP code example of wyrihaximus / broadcast

1. Go to this page and download the library: Download wyrihaximus/broadcast 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/ */

    

wyrihaximus / broadcast example snippets


use WyriHaximus\Broadcast\ContainerListenerProvider;
use WyriHaximus\Broadcast\Dispatcher;
use WyriHaximus\Broadcast\Dummy\Event;

$event = new Event();

(new Dispatcher(new ContainerListenerProvider($container), $logger))->dispatch($event)



declare(strict_types=1);

namespace WyriHaximus\Apps\WyriHaximusNet\GitHub\Ingest;

use Mammatus\LifeCycleEvents\Initialize;
use Mammatus\LifeCycleEvents\Shutdown;
use Psr\Log\LoggerInterface;
use WyriHaximus\Broadcast\Contracts\DoNotHandle;
use WyriHaximus\Broadcast\Contracts\Listener;

final class Consumer implements Listener
{
    private LoggerInterface $logger;

    public function __construct(ConsumerContract $consumer, Producer $producer, LoggerInterface $logger)
    {
        $this->logger   = $logger;
    }

    public function start(Initialize $event): void
    {
        $this->logger->debug('Starting to consume ingested GitHub WebHook events');
    }

    public function handle(GenericEvent|StandardEvent $even): void
    {
        // This handler handles both the GenericEvent and StandardEvent events.
    }

    public function stop(Shutdown $event): void
    {
        $this->logger->debug('Stopping to consume ingested GitHub WebHook events');
    }

    #[DoNotHandle]
    public function doNotHandle(Event $event): void
    {
        // Even through this method accepts a single object we mark not to handle it with the DoNotHandle attribute.
    }
}