All Projects → oscarotero → middleland

oscarotero / middleland

Licence: MIT License
Simple PSR-15 middleware dispatcher

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to middleland

Middleman
Dead simple PSR-15 / PSR-7 middleware dispatcher
Stars: ✭ 87 (+180.65%)
Mutual labels:  middleware, dispatcher
react-redux-api-tools
A set of tools to facilitate react-redux development and decouple logic from compontents
Stars: ✭ 37 (+19.35%)
Mutual labels:  middleware
use
Easily add plugin support to your node.js application.
Stars: ✭ 25 (-19.35%)
Mutual labels:  middleware
cute
An event-centric publisher/subscribe model for objects inspired by the Qt framework
Stars: ✭ 37 (+19.35%)
Mutual labels:  middleware
fjage
Framework for Java and Groovy Agents
Stars: ✭ 19 (-38.71%)
Mutual labels:  middleware
geggleto-acl
PSR-7 Zend ACL implementation - Permission Library [ slim, psr7, acl, permissions, zend ]
Stars: ✭ 33 (+6.45%)
Mutual labels:  middleware
request-context
Simple connect middleware for accessing data in a request context.
Stars: ✭ 55 (+77.42%)
Mutual labels:  middleware
ReSwiftMonitor
ReSwift+redeux dev tools
Stars: ✭ 13 (-58.06%)
Mutual labels:  middleware
think-trace
Error trace for ThinkJS 3.x
Stars: ✭ 12 (-61.29%)
Mutual labels:  middleware
ASPNETcoreAngularJWT
Angular in ASP.NET Core with JWT solution by systemjs
Stars: ✭ 48 (+54.84%)
Mutual labels:  middleware
node-uploadx
Node.js middleware for handling resumable uploads
Stars: ✭ 17 (-45.16%)
Mutual labels:  middleware
falcon-policy
Policy Middleware for Falcon APIs
Stars: ✭ 30 (-3.23%)
Mutual labels:  middleware
http-authentication
PSR-15 middleware to implement Basic and Digest Http authentication
Stars: ✭ 29 (-6.45%)
Mutual labels:  middleware
oak-middleware-jwt
Oak middleware for JWT
Stars: ✭ 24 (-22.58%)
Mutual labels:  middleware
DevOps
DevOps code to deploy eScience services
Stars: ✭ 19 (-38.71%)
Mutual labels:  middleware
dictator
Dictates what your users see. Plug-based authorization.
Stars: ✭ 77 (+148.39%)
Mutual labels:  middleware
koa-rest-router
Most powerful, flexible and composable router for building enterprise RESTful APIs easily!
Stars: ✭ 67 (+116.13%)
Mutual labels:  middleware
access-log
PSR-15 middleware to generate access logs
Stars: ✭ 21 (-32.26%)
Mutual labels:  middleware
polix
🚀 Node.js Web Framework
Stars: ✭ 32 (+3.23%)
Mutual labels:  middleware
redux-tools
Redux tools to speed up development.
Stars: ✭ 16 (-48.39%)
Mutual labels:  middleware

Middleland

Latest Version on Packagist Software License Testing Quality Score

Simple (but powerful) PSR-15 middleware dispatcher:

Requirements

Example

use Middleland\Dispatcher;

$middleware = [
    new Middleware1(),
    new Middleware2(),
    new Middleware3(),

    // A dispatcher can be used to group middlewares
    new Dispatcher([
        new Middleware4(),
        new Middleware5(),
    ]),

    // You can use closures
    function ($request, $next) {
        $response = $next->handle($request);
        return $response->withHeader('X-Foo', 'Bar');
    },

    // Or use a string to create the middleware on demand using a PSR-11 container
    'middleware6'

    // USE AN ARRAY TO ADD CONDITIONS:

    // This middleware is processed only in paths starting by "/admin"
    ['/admin', new MiddlewareAdmin()],

    // This is processed in DEV
    [ENV === 'DEV', new MiddlewareAdmin()],

    // Use callables to create other conditions
    [
        function ($request) {
            return $request->getUri()->getScheme() === 'https';
        },
        new MiddlewareHttps()
    ],

    // There are some matchers included in this library to create conditions
    [
        new Pattern('*.png'),
        new MiddlewareForPngFiles()
    ],

    //And use several for each middleware
    [
        ENV === 'DEV',
        new Pattern('*.png'),
        new MiddlewareForPngFilesInDev()
    ],
];

$dispatcher = new Dispatcher($middleware, new Container());

$response = $dispatcher->dispatch(new Request());

Matchers

As you can see in the example above, you can use an array of "matchers" to filter the requests that receive middlewares. You can use callables, instances of Middleland\Matchers\MatcherInterface or booleans, but for comodity, the string values are also used to create Middleland\Matchers\Path instances. The available matchers are:

Name Description Example
Path Filter requests by base path. Use exclamation mark for negative matches new Path('/admin'), new Path('!/not-admin')
Pattern Filter requests by path pattern. Use exclamation mark for negative matches new Pattern('*.png') new Pattern('!*.jpg')
Accept Filter requests by Accept header. Use exclamation mark for negative matches new Accept('text/html') new Accept('!image/png')

How to create matchers

Just use a callable or an instance of the Middleland\Matchers\MatcherInterface. Example:

use Middleland\Matchers\MatcherInterface;
use Psr\Http\Message\ServerRequestInterface;

class IsAjax implements MatcherInterface
{
    public function __invoke(ServerRequestInterface $request): bool
    {
    	return $request->getHeaderLine('X-Requested-With') === 'xmlhttprequest';
	}
}

Please see CHANGELOG for more information about recent changes.

The MIT License (MIT). Please see LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].