1. Go to this page and download the library: Download icanboogie/message-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/ */
icanboogie / message-bus example snippets
namespace ICanBoogie\MessageBus;
/* @var Dispatcher $dispatcher */
/* @var object $message */
// The message is dispatched to its handler, the result is returned.
$result = $dispatcher->dispatch($message);
// …
final class DeleteMenu
{
public function __construct(
public /*readonly*/ int $id
) {
}
}
use ICanBoogie\MessageBus\Safe;
// …
final class ShowMenu implements Safe
{
public function __construct(
public /*readonly*/ int $id
) {
}
}
final class ShowMenuHandler
{
public function __invoke(ShowMenu $message): Menu
{
// …
}
}
use ICanBoogie\MessageBus\PSR\HandlerProviderWithContainer;
use Psr\Container\ContainerInterface;
/* @var $container ContainerInterface */
$handlerProvider = new HandlerProviderWithContainer($container, [
Acme\MenuService\Application\MessageBus\CreateMenu::class => Acme\MenuService\Application\MessageBus\CreateMenuHandler::class,
Acme\MenuService\Application\MessageBus\DeleteMenu::class => Acme\MenuService\Application\MessageBus\DeleteMenuHandler::class,
]);
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
use ICanBoogie\MessageBus\Symfony\MessageBusPass;
/* @var string $config */
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__));
$loader->load($config);
$container->addCompilerPass(new MessageBusPass());
$container->compile();
namespace Acme\MenuService\Application\MessageBus;
use ICanBoogie\MessageBus\Attribute\Handler;
use ICanBoogie\MessageBus\Attribute\Permission;
#[Permission('is_admin')]
#[Permission('can_write_menu')]
final class CreateMenu
{
// ...
}
#[Handler]
final class CreateMenuHandler
{
// ...
}
namespace Acme\MenuService\Presentation\Security\Voters;
use ICanBoogie\MessageBus\Attribute\Vote;
#[Vote('can_write_menu')]
final class CanWriteMenu
{
// ...
}
// ...
use ICanBoogie\MessageBus\RestrictedDispatcher;
final class MenuController
{
public function __construct(
private RestrictedDispatcher $dispatcher
) {}
}
// ...
use ICanBoogie\MessageBus\Context;
final class MenuController
{
// ...
public function delete(Request $request): Response
{
// ...
$this->dispatch(
new MenuDelete($id),
new Context([ $token ])
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.