1. Go to this page and download the library: Download beebmx/kirby-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/ */
beebmx / kirby-middleware example snippets
use Beebmx\KirbyMiddleware\Request;
$request = Request::instance();
use Beebmx\KirbyMiddleware\Request;
use Closure;
class ValidateSomeInformation
{
public function handle(Request $request, Closure $next)
{
// Perform action
return $next($request);
}
}
use Beebmx\KirbyMiddleware\Request;
use Closure;
use Kirby\Http\Response;
class UserShouldBeAuthenticated
{
public function handle(Request $request, Closure $next)
{
if(empty($request->user())) {
return Response::redirect('login')
}
return $next($request);
}
}
use Beebmx\KirbyMiddleware\Request;
use Closure;
use Kirby\Exception\ErrorPageException;
class UserShouldBeAuthenticated
{
public function handle(Request $request, Closure $next)
{
if(empty($request->user())) {
return throw new ErrorPageException([
'fallback' => 'Unauthorized',
'httpCode' => 401,
]);
}
return $next($request);
}
}
use Beebmx\KirbyMiddleware\Request;
use Closure;
'beebmx.kirby-middleware' => [
'web' => [
function (Request $request, Closure $next) {
// Perform action
return $next($request);
},
],
],