Middleware¶
1 2 3 4 5 6 7 | demo_middleware:
path: api/demo/middleware
controller: LMS\Demo\Controller\DemoApiController::test
options:
middleware:
- auth
- LMS\Routes\Middleware\Api\VerifyAdminBackendSession
|
Tip
Route will be triggered only if all defined middleware pass.
Required: No
Variants: LMSRoutesMiddlewareApiAuthenticate | LMSRoutesMiddlewareApiVerifyCsrfToken | VendorExtensionMiddlewareApiMyCustomMiddleware
Tip
auth is just a sugar that combines (Authenticate and VerifyCsrfToken)
Use a custom defined middleware¶
namespace Vendor\Extension\Middleware\Api;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
class MyCustomMiddleware
{
/**
* @param array $arguments
*/
public function process(array $arguments): void
{
$isOk = true; // Replace with your actual logic...
if ($isOk) {
return;
}
throw new MethodNotAllowedException([], 'Denied!');
}
}
1 2 3 4 5 6 | demo_middleware:
path: api/demo/middleware
controller: LMS\Demo\Controller\DemoApiController::test
options:
middleware:
- Vendor\Extension\Middleware\Api\MyCustomMiddleware
|