bengor-file/simple-bus-bridge
Adapter bridge that integrates BenGorFile's File library with Matthias Noback's SimpleBus, enabling File commands/events to be dispatched through SimpleBus. Install via Composer and run tests with PHPSpec.
composer require bengor-file/simple-bus-bridge
config/bus.php (or equivalent) to integrate with SimpleBus:
'bridges' => [
'file' => \BenGorFile\SimpleBusBridge\FileBridge::class,
],
AppServiceProvider@boot():
$bus = new \SimpleBus\MessageBus(
new \BenGorFile\SimpleBusBridge\FileBridge(
new \File\FileSystem($storagePath)
)
);
Use the bridge to store dispatched commands in a file system (e.g., JSON files) for later replay or debugging:
$bus->dispatch(new ProcessOrderCommand($orderId));
// Later, replay commands from storage
$storedCommands = $fileSystem->read('commands/ProcessOrderCommand_123.json');
$bus->dispatch($storedCommands);
Command Persistence:
SendEmailCommand instances to a directory for later replay.$bus = new \SimpleBus\MessageBus(
new \BenGorFile\SimpleBusBridge\FileBridge($fileSystem)
);
$bus->dispatch(new SendEmailCommand($userId, $template));
Integration with Laravel Queues:
// Dispatch to SimpleBus (file-backed) and Laravel queue
$bus->dispatch($command);
Queue::push(new DispatchCommandJob($command));
Middleware Chaining:
$bus = new \SimpleBus\MessageBus(
new \SimpleBus\Middleware\Chain(
new \SimpleBus\Middleware\LogMessages(),
new \BenGorFile\SimpleBusBridge\FileBridge($fileSystem)
)
);
Storage facade for cross-environment paths:
$fileSystem = Storage::disk('local')->getDriver();
JsonSerializable or use serialize() for custom objects.storage/app/commands/ProcessOrderCommand_123.json).get_class() + timestamp. Override FileBridge::getFileName() if needed:$bridge->setFileNameGenerator(function ($command) {
return 'custom_' . md5($command->getId()) . '.json';
});
serialize() or exclude them.storage/app/commands/ for generated files. Use dd($fileSystem->listContents()) to debug.$bus = new \SimpleBus\MessageBus(
new \SimpleBus\Middleware\Chain(
new class implements \SimpleBus\Middleware\Middleware {
public function handle($message, callable $next) {
\Log::debug("Dispatching: " . get_class($message));
return $next($message);
}
},
$fileBridge
)
);
\File\FileSystem to add encryption or compression:
$fileSystem = new CustomFileSystem($storagePath);
FileCreated):
$fileSystem->addListener(new class implements \File\EventListener {
public function handle(FileEvent $event) {
if ($event->getType() === FileEvent::CREATED) {
event(new CommandStored($event->getFile()));
}
}
});
FileBridge::getAllCommands() to replay batches:
foreach ($fileBridge->getAllCommands() as $command) {
$bus->dispatch($command);
}
How can I help you explore Laravel packages today?