A simple middleware to rewrite Request path, query and fragment.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.scrutinizer.yml
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE
README.md
composer.json
composer.lock
phpcs.xml.dist
phpunit.xml.dist

README.md

linkeddatacenter/url-rewriter

Latest Version on Packagist Software License Build Status Quality Score

Simple Middleware to rewrite the path, the query and the fragment of the an http request uri. It requires an array of rules that are evaluated in sequence. A rule is a two position array: array[0] is the regexp pattern to search (internally translated in #^$pattern$# and array[1] is the replacement according the php function preg_replace.

Inspired from middlewares/base-path

Requirements

Installation

This package is installable and autoloadable via Composer as linkeddatacenter/url-rewriter.

composer require linkeddatacenter/url-rewriter

Example

$dispatcher = new Dispatcher([
	new Middlewares\BasePath([
	[
            '/(\w+)' => '/$1/pluto',
            '/(\w+)/(\w+)/(\w+).(csv|json|xml)(.*)' =>'/$1/docstore?db=$2&table=$3&format=$4$5',
	])
]);

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

Options

__construct(array $rules)

rules := array [ , ,.... ] rule := array [ , ]

Test with docker

docker run --rm -ti -v $PWD/.:/app composer bash
composer install
vendor/bin/phpunit

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

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