middlewares/base-path

Name: base-path

Owner: Middlewares

Description: PSR-15 middleware to remove the prefix from the uri path of the request

Created: 2016-10-01 14:41:13.0

Updated: 2018-01-24 21:03:22.0

Pushed: 2018-01-24 21:04:26.0

Homepage:

Size: 24

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

middlewares/base-path

Latest Version on Packagist Software License Build Status Quality Score Total Downloads SensioLabs Insight

Middleware to remove the prefix from the uri path of the request. This is useful to combine with routers if the root of the website is in a subdirectory. For example, if the root of your website is /web/public, a request with the uri /web/public/post/34 will be converted to /post/34.

Requirements
Installation

This package is installable and autoloadable via Composer as middlewares/base-path.

oser require middlewares/base-path
Example
patcher = new Dispatcher([
new Middlewares\BasePath('/base/path')


ponse = $dispatcher->dispatch(new ServerRequest());
Options
__construct(string $basePath)

The prefix to remove.

fixLocation(true)

Used to add the prefix to the Location header. For example:

patcher = new Dispatcher([
(new Middlewares\BasePath('/base/path'))->fixLocation(),

function ($request, $next) {
    return new RedirectResponse('/post/1');
}


ponse = $dispatcher->dispatch($request);
 $response->getHeader('Location'); // Returns /base/path/post/1

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

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


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.