• Stars
    star
    400
  • Rank 107,843 (Top 3 %)
  • Language
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Collection of PSR-15 middlewares

logo

psr15-middlewares

Collection of PSR-15 middlewares

Requirements

Usage example

use Zend\Diactoros\ServerRequestFactory;
use Middlewares\Utils\Dispatcher;
use Middlewares;

$dispatcher = new Dispatcher([

    //Handle errors
    (new Middlewares\ErrorHandler())
    	->catchExceptions(true),

    //Log the request
    new Middlewares\AccessLog($app->get('logger')),

    //Calculate the response time
    new Middlewares\ResponseTime(),

    //Removes the trailing slash
    new Middlewares\TrailingSlash(false),

    //Insert the UUID
    new Middlewares\Uuid(),

    //Disable the search engine robots
    new Middlewares\Robots(false),

    //Compress the response to gzip
    new Middlewares\GzipEncoder(),

    //Minify the html
    new Middlewares\HtmlMinifier(),

    //Override the method using X-Http-Method-Override header
    new Middlewares\MethodOverride(),

    //Parse the json payload
    new Middlewares\JsonPayload(),

    //Parse the urlencoded payload
    new Middlewares\UrlEncodePayload(),

    //Save the client ip in the '_ip' attribute
    (new Middlewares\ClientIp())
    	->attribute('_ip'),

    //Allow only some ips
    (new Middlewares\Firewall(['127.0.0.*']))
        ->ipAttribute('_ip'),

    //Add cache expiration headers
    new Middlewares\Expires(),

    //Add the php debugbar
    new Middlewares\Debugbar(),

    //Negotiate the content-type
    new Middlewares\ContentType(),

    //Negotiate the language
    new Middlewares\ContentLanguage(['gl', 'es', 'en']),

    //Handle the routes with fast-route
    new Middlewares\FastRoute($app->get('dispatcher')),

    //Create and save a session in '_session' attribute
    (new Middlewares\AuraSession())
        ->attribute('_session'),

    //Handle the route
    new Middlewares\RequestHandler(),
]);

$response = $dispatcher->dispatch(ServerRequestFactory::fromGlobals());

List of all available middlewares

Authentication

Client info

Develop utils

Optimization

Routers

Security

Session

Urls

Others

Contributing

Use the package repository of each component to notify any issue or pull request related with it, and use this repository for generical questions, new middlewares discussions, etc.

If you want to contribute with new middlewares, you can take a look to these ideas. There's also a skeleton that you can use for quick start.

See CONTRIBUTING for contributing details.

Logo

Download the logo from the art directory.


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

More Repositories

1

awesome-psr15-middlewares

A curated list of awesome PSR-15 HTTP Middleware resources
319
star
2

fast-route

PSR-15 middleware to use FastRoute
PHP
94
star
3

utils

Common utils used by PSR-15 middlewares
PHP
50
star
4

request-handler

PSR-15 middleware to execute request handlers
PHP
45
star
5

negotiation

PSR-15 middleware to implement content negotiation
PHP
44
star
6

http-authentication

PSR-15 middleware to implement Basic and Digest Http authentication
PHP
36
star
7

whoops

PSR-15 middleware to use Whoops as error handler
PHP
32
star
8

payload

PSR-15 middleware to parse the body of the request with support for json, csv and url-encode
PHP
31
star
9

trailing-slash

PSR-15 middleware to normalize the trailing slash of the uri path
PHP
26
star
10

proxy

PSR-15 middleware to forward requests and return responses
PHP
22
star
11

access-log

PSR-15 middleware to generate access logs
PHP
20
star
12

minifier

Middleware to minify Html, CSS and Javascript responses
PHP
18
star
13

client-ip

PSR-15 middleware to detect the client ip and save it as a request attribute.
PHP
16
star
14

cache

PSR-15 middleware with various cache utilities
PHP
15
star
15

debugbar

PSR-15 middleware to insert PHP DebugBar automatically in html responses
PHP
15
star
16

csp

PSR-15 middleware to add the Content-Security-Policy header to the response
PHP
15
star
17

response-time

PSR-15 middleware to save the response time into the X-Response-Time header
PHP
14
star
18

error-handler

PSR-15 middleware to handle http errors
PHP
14
star
19

https

PSR-15 middleware to redirect to https and adds the Strict-Transport-Security header
PHP
14
star
20

php-session

PSR-15 middleware to create a php session using the request data
PHP
13
star
21

honeypot

PSR-15 middleware to implement a honeypot spam prevention
PHP
13
star
22

firewall

Middleware to provide IP filtering
PHP
12
star
23

geolocation

PSR-15 middleware to geolocate the client using the ip address
PHP
12
star
24

referrer-spam

PSR-15 middleware to block referrer spammers
PHP
12
star
25

cors

PSR-15 middleware to implement Cross-Origin Resource Sharing (CORS)
PHP
12
star
26

image-manipulation

PSR-15 middleware to manipulate images on-demand
PHP
10
star
27

filesystem

PSR-15 middleware to write or read responses from files
PHP
9
star
28

aura-router

PSR-15 middleware to use Aura.Router
PHP
8
star
29

skeleton

A skeleton repository for PSR-15 middleware packages
PHP
7
star
30

encoder

PSR-15 middleware to encode the response body to gzip or deflate
PHP
6
star
31

csv-payload

PSR-15 middleware to parse the CSV body of the request
PHP
6
star
32

reporting-logger

PSR-15 middleware to log server-side reportings
PHP
6
star
33

recaptcha

PSR-15 middleware to use Google reCAPTCHA for spam prevention
PHP
6
star
34

redirect

Middleware to redirect old urls to new urls SEO friendly
PHP
6
star
35

method-override

PSR-15 middleware to override the request method using the X-Http-Method-Override header
PHP
6
star
36

error-response

Middleware to create responses with error status code (4xx-5xx)
PHP
6
star
37

aura-session

PSR-15 middleware to manage sessions using Aura.Session
PHP
6
star
38

uuid

PSR-15 middleware to generate an UUID and save it in the X-Uuid header
PHP
5
star
39

shutdown

PSR-15 middleware to display a 503 maintenance page
PHP
5
star
40

ideas

Need a Middleware or looking for ideas?
5
star
41

json-exception-handler

Middleware to catch exceptions and output them as JSON
PHP
5
star
42

robots

PSR-15 middleware to enable/disable the robots of the search engines
PHP
4
star
43

emitter

Middleware to send (or emit) a PSR-7 response object using header() and echo
PHP
4
star
44

www

PSR-15 middleware to add or remove the www subdomain
PHP
4
star
45

base-path

PSR-15 middleware to remove the prefix from the uri path of the request
PHP
4
star
46

base-path-router

PSR-15 middleware to assign request handlers based on path prefixes
PHP
4
star
47

content-length

PSR-15 middleware to inject the Content-Length header into the response
PHP
3
star
48

lowercase

PSR-15 middleware to convert the URI path to lowercase
PHP
2
star