1. Go to this page and download the library: Download georgeff/bus 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/ */
georgeff / bus example snippets
class SendEmail
{
public function __construct(
public readonly string $to,
public readonly string $subject,
public readonly string $body,
) {}
}
class SendEmailHandler
{
public function __invoke(SendEmail $command): void
{
// send the email
}
}
use Georgeff\Bus\Dispatcher;
$dispatcher = new Dispatcher($resolver);
$dispatcher->dispatch(new SendEmail(
to: '[email protected]',
subject: 'Welcome',
body: 'Hello!',
));
use Georgeff\Bus\Resolver\SimpleResolver;
$resolver = new SimpleResolver($locator);
use Georgeff\Bus\Resolver\PsrContainerResolver;
$resolver = new PsrContainerResolver($container, $locator);
use Georgeff\Bus\Locator\InMemoryLocator;
$locator = new InMemoryLocator([
SendEmail::class => SendEmailHandler::class,
]);
use Georgeff\Bus\Locator\ClassNameLocator;
$locator = new ClassNameLocator();
use Georgeff\Bus\Dispatcher;
use Georgeff\Bus\MiddlewareAwareDispatcher;
use Georgeff\Bus\Resolver\PsrContainerResolver;
use Georgeff\Bus\Locator\InMemoryLocator;
$locator = new InMemoryLocator([
SendEmail::class => SendEmailHandler::class,
]);
$resolver = new PsrContainerResolver($container, $locator);
$dispatcher = new MiddlewareAwareDispatcher(
new Dispatcher($resolver),
[$logging, $transaction],
);
$dispatcher->dispatch(new SendEmail(
to: '[email protected]',
subject: 'Welcome',
body: 'Hello!',
));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.