pechenin / broker-action
Installs: 16 002
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 6
Requires
- symfony/framework-bundle: ^4.0
- dev-master
- dev-dependabot/composer/symfony/http-kernel-4.4.39
- dev-dependabot/composer/symfony/framework-bundle-5.3.15
- dev-dependabot/composer/symfony/var-exporter-4.4.4
- dev-dependabot/composer/symfony/http-foundation-4.4.1
- dev-dependabot/composer/symfony/mime-4.4.1
- dev-dependabot/composer/symfony/cache-4.3.9
This package is auto-updated.
Last update: 2025-06-26 07:27:58 UTC
README
Installation
Add bundle to config/bundles.php
BrokerAction\BrokerActionBundle::class => ['all' => true]
Create broker_action.yaml in config/packages folder
Example of broker_action.yaml:
broker_action:
mapping:
- { path: 'some.path', action: 'App\Actions\SomeAction' }
- { path: 'some.path1', action: 'App\Actions\SomeAnotherAction' }
Action creation
Create class that implements BrokerAction\Framework\ActionInterface
.
Example:
use BrokerAction\DTO\ActionResponse;
use BrokerAction\DTO\Error;
use BrokerAction\Framework\ActionInterface;
class SomeAction implements ActionInterface
{
public function run($data): ActionResponse
{
$response = new ActionResponse();
try {
echo $data;
$response->setData($data);
} catch (\Exception $exception) {
$response->setError(new Error($exception->getMessage()));
}
return $response;
}
}
Find route and fire action
To fire action you should create TransactionMessageDTO
object and pass it to route
method of BrokerAction\Framework\Router
.
Example:
use BrokerAction\Framework\Router;
use BrokerAction\DTO\TransactionMessage\TransactionMessageDTO;
class FooClass {
private $router;
public function (Router $router) {
$this->router = $router;
}
public function bar() {
$json = '{
"path": "some.path",
"payload": {
"acc_id": 1
}
}';
$message = TransactionMessageDTO::fromJson($json);
$reponse =$this->router->route($message);
}
}