PHP code example of patryknamyslak / patflow

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

    

patryknamyslak / patflow example snippets


namespace PatrykNamyslak\PatFlow\Demo;

use PatrykNamyslak\PatFlow\Blueprints\Event;

class TestEvent extends Event{
    // Add a custom property to capture extra data to then later use in the Listener::handle() method
    public function __construct(protected string $message){
        parent::__construct();
    }
}

namespace PatrykNamyslak\PatFlow\Demo;

use PatrykNamyslak\PatFlow\Blueprints\Event;
use PatrykNamyslak\PatFlow\Blueprints\Listener;

class TestListener extends Listener{
    public function handle(Event $event): void{
        echo "Event triggered! at: {$event->timestamp} and a message was left here it is: {$event->message}";
    }
}

namespace PatrykNamyslak\PatFlow\Demo;

use PatrykNamyslak\PatFlow\Blueprints\ServiceProvider;

class TestServiceProvider extends ServiceProvider{
    // Define your event => array of listeners that are triggered on event fire
    public array $listen = [
        TestEvent::class => [TestListener::class],
    ];
}

use PatrykNamyslak\PatFlow\Demo\TestEvent;
use PatrykNamyslak\PatFlow\Demo\TestServiceProvider;

$dispatcher = new Dispatcher();

$serviceProvider = new TestServiceProvider(dispatcher: $dispatcher);
$serviceProvider->register();
$dispatcher->dispatch(new TestEvent(message: "Greetings My friend"));