Download the PHP package beebmx/kirby-middleware without Composer

On this page you can find all versions of the php package beebmx/kirby-middleware. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package kirby-middleware

Build Status Total Downloads Latest Stable Version License

Kirby Middleware

Kirby Middleware provides a powerful mechanism for inspecting and filtering requests entering your Kirby site.


Overview

Installation

Download

Download and copy this repository to /site/plugins/kirby-middleware.

Composer

Usage

Out of the box, you don't need to do anything to start using (except for installation). When you install the Kirby Middleware package, it comes with two ways of management middlewares, global middlewares and groups of middlewares.

Global middlewares

This middleware will always be triggered in every Page by the Middleware handler. Out of the box comes with a TrimStrings middleware, which will remove spaces in the Request made.

[!NOTE] To access to this request, you should call the Beebmx\KirbyMiddleware\Request instance.

The Kirby\Http\Request instance will never be modified.

You can access to the Request instance transformed with:

You can add features to the global middleware in your config.php file:

[!NOTE] You can add as much middleware as requested.

They can be a class or a Closure.

TrimStrings

TrimStrings clean all the inputs in the request, but sometimes you need to ignore some inputs to be trimmed; you can skip it with:

And you can recover those inputs with the Request instance in your controllers, models or any place required with:

Or for your convinience you can use the facade:

Group middlewares

The group middlewares will depend on routes to be triggered. By default, the group middleware comes with the web, auth and guest middleware, it brings a ValidateCsrfToken middlewares.

You can set the routes by adding the routes values in your config.php file:

[!NOTE] You can add a pattern like any Kirby route

By default, the web group comes with the (:all) route.

The auth and guest middlewares are inactive by default, but you can customize the routes to enable them.

And of course, you can add more features to the web middleware in your config.php file:

If the web group is not what you need, you can add a new group of middleware. You can add it within the config.php file:

The Middleware Group should looks like:

[!IMPORTANT] All the group middleware classes should extend Beebmx\KirbyMiddleware\MiddlewareGroups\MiddlewareGroup class.

ValidateCsrfToken

When you use an HTML form with POST, PUT, PATCH, or DELETE in your template, you should include a hidden CSRF _token field in the form so that the CSRF protection middleware can validate the request.

[!NOTE] For convenience, you can also use csrf, csrf-token or _token.

Sometimes you need to ignore some routes from the CSRF validation; you can skip it with:

Security middlewares

Kirby Middleware comes with two (auth and guest) middlewares to improve your security flow based on user authentication.

Auth middleware

The auth middleware provides a starting point to validate if the user is authenticated and if the user is able to visit given routes. If not, it will redirect to some URL to perform a proper login.

Heres an example of it:

[!NOTE] If the user is not authenticated, the middleware will redirect to a guest page.

Guest middleware

The guest middleware provides a starting point to validate if the visitor is a guest and is unauthenticated. If the user is authenticated, it will redirect to some URL to be inside a secured welcome page or dashboard.

Heres an example of it:

[!NOTE] If the user is authenticated, the middleware will redirect to a auth page.

Middleware

When you create a middleware, you can use a class or a Closure; it will depend on your needs and complexity.

Middleware class

When you create your own middleware class, it should look like:

As you can see, handle requires two parameters: a Request called $request and a Closure called $next. The $request contains the current request made in Kirby by the hook route:before.

The second parameter $next, you should call it at the end of the process to proceed to the next middleware validation with the $request.

If you need, some validations can prevent to continue with any other validation; you can throw an error or make a response redirection:

Or with an exception:

Closure middleware

The easiest way to add a global, web, auth or guest middleware is with a Closure; when you add a closure, it should look like:

[!IMPORTANT] Remember to call the $next closure to proceed to the next validation with the $request.

Options

Option Default Type Description
beebmx.kirby-middleware.enabled true bool Enable/Disable all Kirby Middleware.
beebmx.kirby-middleware.exceptions [] array Set exceptions for trim and csrf middlewares.
beebmx.kirby-middleware.global [] array Add your own global middlewares.
beebmx.kirby-middleware.groups [] array Add your own groups middlewares.
beebmx.kirby-middleware.routes [] array Customize your group routes.
beebmx.kirby-middleware.web [] array Add your own web middlewares.
beebmx.kirby-middleware.auth [] array Add your own auth middlewares.
beebmx.kirby-middleware.guest [] array Add your own guest middlewares.
beebmx.kirby-middleware.redirections [] array Customize your redirections for auth and guest middlewares.

Disable middleware

You can completly disable all middleware validations updating the enable value in the config.php file:

Facades

There are some facades to simplify the use of this plugin:

Facade Class Instance of
Beebmx\KirbyMiddleware\Facades\Middleware Beebmx\KirbyMiddleware\Middleware Middleware::instance()
Beebmx\KirbyMiddleware\Facades\Pipeline Beebmx\Pipeline\Pipeline new Pipeline
Beebmx\KirbyMiddleware\Facades\Request Beebmx\KirbyMiddleware\Request Request::instance()

Plugins

If you are creating your own plugin, and it's required to use some type of request manipulation, Kirby Middleware is also for you.

Installation

First, you need to inform Kirby Middleware than you have some global middleware or group middleware to register.

The easyest way to do this, is with a hook

Global methods

You can add your own validations to the global middleware. To achieve this, you have several methods.

Append

The append method adds the middleware to the end of the global middleware.

Prepend

The prepend method adds the middleware to the beginning of the global middleware.

getGlobalMiddleware

The getGlobalMiddleware method returns an array of all the global middleware registered.

Group methods

You can add your own validations to the groups middleware. To achieve this, you have several methods.

Append

The appendToGroup method adds the middleware to the end of the groups middlewares.

prependToGroup

The prependToGroup method adds the middleware to the beginning of the groups middlewares.

removeFromGroup

The removeFromGroup method removes some middleware from a specific group middleware.

addClassToGroup

The addClassToGroup method adds a Middleware Group class to the groups middlewares.

getMiddlewareGroups

The getMiddlewareGroups method returns an array of all the groups middleware registered.

Authenticate middleware

You can customize the Authenticate middleware without using options, but hook system.loadPlugins:after.

redirectUsing

To set the route to redirect if the user is not authenticated.

setRoutes

If you want to set the routes for the AuthMiddlewareGroup.

RedirectIfAuthenticated middleware

You can customize the RedirectIfAuthenticated middleware without using options, but hook system.loadPlugins:after.

redirectUsing

To set the route to redirect if the user is authenticated.

setRoutes

If you want to set the routes for the GuestMiddlewareGroup.

[!IMPORTANT] Remember, all the group middleware classes should extend Beebmx\KirbyMiddleware\MiddlewareGroups\MiddlewareGroup class.

Roadmap

License

Licensed under the MIT.

Credits


All versions of kirby-middleware with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
getkirby/composer-installer Version ^1.2
beebmx/pipeline Version ^1.0
laravel/serializable-closure Version ^1.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package beebmx/kirby-middleware contains the following files

Loading the files please wait ....