1. Go to this page and download the library: Download benycode/slim-middleware library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
benycode / slim-middleware example snippets
use BenyCode\Slim\Middleware\HealthCheckEndpointMiddleware;
return [
......
HealthCheckEndpointMiddleware::class => function (ContainerInterface $container) {
return new HealthCheckEndpointMiddleware(
[
'health_endpoint' => '/_health', // change if needed other endpoint
],
<<inject you PSR7 logger if needed>>,
);
},
......
];
use Slim\Exception\HttpNotFoundException;
use BenyCode\Slim\Middleware\HealthCheckEndpointMiddleware;
$app
->get(
'/{any:.*}',
function (Request $request, Response $response) {
throw new HttpNotFoundException($request);
}
)
....
->add(HealthCheckEndpointMiddleware::class)
->setName('any')
;
use BenyCode\Slim\Middleware\InfoEndpointMiddleware;
return [
......
InfoEndpointMiddleware::class => function (ContainerInterface $container) {
return new InfoEndpointMiddleware(
[
'info_endpoint' => '/_info', // change if needed other endpoint
],
'<<define api version here>>', // example: v0.0.0
);
},
......
];
use Slim\Exception\HttpNotFoundException;
use BenyCode\Slim\Middleware\InfoEndpointMiddleware;
$app
->get(
'/{any:.*}',
function (Request $request, Response $response) {
throw new HttpNotFoundException($request);
}
)
....
->add(InfoEndpointMiddleware::class)
->setName('any')
;
use BenyCode\Middleware\SettingsUpMiddleware;
return function (App $app) {
...
$app->add(SettingsUpMiddleware::class);
...
};