communitales / status-bus
Communitales StatusBus Component
Installs: 4 319
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.3
- communitales/log: ^3.1
- symfony/http-foundation: ^7.0
- symfony/translation: ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.51
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-symfony: ^1.3
- phpunit/phpunit: ^10.5
- rector/rector: ^1.0
- vimeo/psalm: ^5.23
README
Send status messages to a central status bus.
The content of the status can be displayed in the UI or logged into a file. So any service class of the application is able to send messages to the UI.
Setup
composer require communitales/status-bus
Setup for Symfony in services.yaml
:
services:
_defaults:
bind:
iterable $statusBusHandlers: !tagged_iterator communitales.status_handler
_instanceof:
Communitales\Component\StatusBus\StatusBusAwareInterface:
calls:
- [setStatusBus, ['@Communitales\Component\StatusBus\StatusBus']]
Communitales\Component\StatusBus\Handler\SymfonySessionFlashBagHandler:
tags: ['communitales.status_handler']
Communitales\Component\StatusBus\StatusBus: ~
Usage
You can send messages to the StatusBus
use Communitales\Component\StatusBus\StatusBusAwareInterface;
use Communitales\Component\StatusBus\StatusBusAwareTrait;
use Symfony\Component\Translation\TranslatableMessage;
class MyClass implements StatusBusAwareInterface
{
use StatusBusAwareTrait;
public function doSomething() {
// ...
// You can use the status bus without i18n
$this->statusBus->addSuccess(new TranslatableMessage('The item "example" has been successfully created.'));
// And you can use the status bus with i18n
$this->statusBus->addSuccess(new TranslatableMessage('action_item.success', ['item_name' => 'example']));
}
}