PHP code example of jshannon63 / laravel-psr15-middleware

1. Go to this page and download the library: Download jshannon63/laravel-psr15-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/ */

    

jshannon63 / laravel-psr15-middleware example snippets




return [
    'middleware' => [
        [\Jshannon63\Psr15Middleware\exampleMiddleware::class, 'append', 'before'],
        [
            function() {
                return new \Jshannon63\Psr15Middleware\exampleMiddleware('Lovin', 'Laravel');
            },
            'prepend',
            'after'
        ],
        [
            (new \Jshannon63\Psr15Middleware\exampleMiddleware('PSR-15','Rocks')),
            'append',
            'after'
        ]
    ],
    'groups' => [
       'web' => [

        ],
        'api' => [
  
        ],
        'custom' => [
  
        ],
    ],
    'aliases' => [
        'psr15' => [
            (new \Jshannon63\Psr15Middleware\exampleMiddleware('Aliased','Middleware')),
            'prepend',
            'after'
        ]
    ]
];



// your namespace here

use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class exampleMiddleware implements MiddlewareInterface
{
    // Your constructor will be treated as a variadic function
    // and parameters may be passed either as a middleware route
    // parameter or as defined in the /config/psr15middleware.php
    // config file. You can read more about middleware parameters
    // in the Laravel documentation.

    public function __construct()
    {
        // if needed
    }

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // process any request manipulations here before the handler.
        // remember that only "before" middlewares have access to
        // the request object before the application acts on it.
        // the handler will ensure the next middleware will see any
        // changes to the request object.

        $response = $handler->handle($request);

        // response actions go here after the handler provides
        // you with a response object. keep in mind that any
        // "before" middlewares will only have access to a mock
        // response object and any updates will be lost.

        // "terminable" middlewares are run after the response has
        // been sent back to the browser. they will receive the
        // request object passed into this method and will get
        // a copy of the response object from the handler.

        // return the reponse object here.

        return $response;
    }
}