lack / subscription
Manage subscriptions accross microservices
v1.2.2
2024-04-25 14:14 UTC
Requires
- php: >=8.0
- phore/http-client: *
- phore/hydrator: *
Requires (Dev)
README
Library to manage subscriptions accross services
Installation
composer install lack/subscription
Adding to Brace App
01_di.php
$app->addModule( new SubscriptionClientModule( "file:///opt/conf/", CONF_SUBSCRIPTION_CLIENT_ID, CONF_SUBSCRIPTION_CLIENT_SECRET ) );
10_middleware.php
$app->setPipe([ ... // Below RouterEvalMiddleware // Search for {subscription_id} in the route and load the subscription object new SubscriptionMiddleware(), ... ]);
Usage
In Controller Classes
The RouterEvalMiddleware will register a service subscription
in the container. You can use this service to get the subscription object.
public function loadSubscription(T_Subscritpion $subscription) { return $subscription; }
In Routes (as Middleware)
AppLoader::extend(function (BraceApp $app) { $mount = CONF_API_MOUNT; $subscriptionAuthValidatorMw = new SubscriptionBasicAuthValidationMiddleware(); // Validate auth token from mailbox of subscription $app->router->registerClass($mount, DocFusionApiCtrl::class, [$subscriptionAuthValidatorMw]);