1. Go to this page and download the library: Download rennf93/psr15-guard 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/ */
rennf93 / psr15-guard example snippets
use Nyholm\Psr7\Factory\Psr17Factory;
use RenzoFranceschini\GuardCore\Config\SecurityConfig;
use RenzoFranceschini\GuardCore\Engine\GuardEngine;
use RenzoFranceschini\GuardCorePsr15\GuardMiddleware;
$config = new SecurityConfig(
enableRedis: false,
blacklist: ['192.0.2.0/24'],
rateLimit: 100,
rateLimitWindow: 60,
enableRateLimiting: true,
);
$factory = new Psr17Factory();
$engine = new GuardEngine($config);
$guard = new GuardMiddleware($engine, $factory, $factory);
$app->add($guard);
use RenzoFranceschini\GuardCore\Routing\RouteConfig;
use RenzoFranceschini\GuardCorePsr15\GuardMiddleware;
$middleware = new GuardMiddleware(
$engine,
$responseFactory,
$streamFactory,
routes: [
'/docs/' => new RouteConfig(enableSuspiciousDetection: false),
'/api/' => new RouteConfig(rateLimit: 5, rateLimitWindow: 10),
],
// optional: country resolver for RouteConfig geoRateLimits tiers
geoRateLimitResolver: $myResolver,
// optional: custom resolver receiving the PSR-7 server request
routeResolver: fn (ServerRequestInterface $r) => str_starts_with($r->getUri()->getPath(), '/admin') ? new RouteConfig(bypassedChecks: ['rate_limit']) : null,
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.