<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tracesoftwareinternational / elephant-guard example snippets
use TraceSoftware\Middleware\ElephantGuard\AuthenticatorInterface;
use TraceSoftware\Middleware\ElephantGuard
class RandomAuthenticator implements AuthenticatorInterface {
public function __invoke(array $arguments) {
return (bool)rand(0,1);
}
public function getLastError(): string
{
return "";
}
}
$app = new Slim\App;
$app->add(new ElephantGuard([
"path" => "/",
"authenticator" => new RandomAuthenticator
]);
use TraceSoftware\Middleware\ElephantGuard\AuthenticatorInterface;
use TraceSoftware\Middleware\ElephantGuard
$app = new Slim\App;
$app->add(new ElephantGuard([
"path" => "/",
"authenticator" => new class implements AuthenticatorInterface {
public function __invoke(\Psr\Http\Message\ServerRequestInterface $request): bool
{
return (bool) rand(0,1);
}
public function getLastError(): string
{
return "";
}
}
]);
$app = new Slim\App;
$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
"path" => "/admin",
"authenticator" => new \MyCustomAuthenticator()
"before" => function ($request, $arguments) {
return $request->withAttribute("user", $arguments["user"]);
}
]));
$app = new Slim\App;
$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
"path" => "/admin",
"authenticator" => new \MyCustomAuthenticator()
"after" => function ($request, $response, $arguments) {
return $response->withHeader("X-Brawndo", "plants crave");
}
]));