Skip to content
This repository has been archived by the owner on Jun 30, 2020. It is now read-only.

3.14.0

Compare
Choose a tag to compare
@oscarotero oscarotero released this 26 Feb 10:25
· 139 commits to master since this release

BasePath

Previous versions provide the basePath option in some middleware pieces (saveResponse, readResponse, languageNegotiator, etc). For simplicity and to avoid repeat code, this option was removed. Now you can use the basePath middleware that provides a path generator to create full paths:

use Psr7Middlewares\Middleware;
use Psr7Middlewares\Middleware\BasePath;

$middlewares = [
    Middleware::basePath('/my-site/public'),

    Middleware::trailinSlash(),

    function ($request, $response, $next) {
        $basePath = BasePath::getBasePath($request); // returns /my-site/public

        $builder = BasePath::getPathBuilder($request);
        $link = $builder('fancy/path'); // generates /my-site/public/fancy/path

        return $next($request, $response);
    }
];

The middleware pieces affected by this change (dropped the basepath option) are:

  • LanguageNegotiator
  • TrailinSlash
  • ReadResponse
  • SaveResponse
  • ImageTransformer

Storage

Added the ability to use the session data of PhpSession and AuraSession in other middlewares, creating and sharing a subarray in the request attributes. This change affects to Csrf that no longer need to pass $_SESSION array in the constructor.

Automatic injection

Some middleware pieces like Csrf, Honeypot, etc inject automatically the inputs in post forms. This feature is disabled by default, in order to improve the performance. Now you can get a callable in your router to generate automatically these inputs:

$middlewares = [
    Middleware::Honeypot(),
    function ($request, $response, $next) {
        $generator = Middleware\Honeypot::getGenerator($request);

        $inputs = $generator();

       $response->getBody()->write('<form action="/action.php" method="POST">'.$inputs.'<input type="submit"></form>');

        return $next($request, $response);
    }
];

This change affects to the following middlewares:

  • Csrf
  • Honeypot
  • FormTimestamp

You can enable the automatic injection again using the option ->autoInsert(true)

New additions and fixes

  • MethodOverride Added ->parameter() option #28
  • ReadResponse Added ->continueOnError() option.
  • Geolocate New option ->saveInSession() to reuse the same geolocation result in all requests.
  • ImageTransformer Added a generator callable to generate the images paths.
  • Allow to register new middleware namespaces using Psr7Middlewares\Middleware::registerNamespace($namespace)
  • Robots Do not execute the next middleware if the path is "/robots.txt"
  • Middleware::create() now accepts a base path as first argument

Internal changes (not should affects)

  • Moved some static methods of Psr7Middlewares\Middleware to traits (getAttribute, setAttribute, hasAttribute, createStream)
  • Changed some transformers to be more independent