Skip to content

Commit

Permalink
psr-17
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Aug 3, 2018
1 parent 69fa9ff commit 02b979e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor
composer.lock
.php_cs.cache
coverage
.phpunit.result.cache
1 change: 0 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ return PhpCsFixer\Config::create()
'pre_increment' => true,
'protected_to_private' => true,
'return_type_declaration' => true,
'self_accessor' => true,
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'single_blank_line_at_eof' => true,
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.1.0] - UNRELEASED

### Added

- PSR-17 support
- New option `responseFactory`

## [1.0.0] - 2018-01-24

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Middleware to normalize the trailing slash of the uri path. By default removes t
## Requirements

* PHP >= 7.0
* A [PSR-7](https://packagist.org/providers/psr/http-message-implementation) http message implementation ([Diactoros](https://github.com/zendframework/zend-diactoros), [Guzzle](https://github.com/guzzle/psr7), [Slim](https://github.com/slimphp/Slim), etc...)
* A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
* A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)

## Installation
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
},
"require": {
"php": "^7.0",
"middlewares/utils": "^1.0",
"middlewares/utils": "^2.1",
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"phpunit/phpunit": "^6.0|^7.0",
"zendframework/zend-diactoros": "^1.3",
"friendsofphp/php-cs-fixer": "^2.0",
"squizlabs/php_codesniffer": "^3.0"
Expand Down
5 changes: 4 additions & 1 deletion src/TrailingSlash.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

namespace Middlewares;

use Middlewares\Utils\Traits\HasResponseFactory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class TrailingSlash implements MiddlewareInterface
{
use HasResponseFactory;

/**
* @var bool Add or remove the slash
*/
Expand Down Expand Up @@ -47,7 +50,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$path = $this->normalize($uri->getPath());

if ($this->redirect && ($uri->getPath() !== $path)) {
return Utils\Factory::createResponse(301)
return $this->createResponse(301)
->withHeader('Location', (string) $uri->withPath($path));
}

Expand Down
6 changes: 3 additions & 3 deletions tests/TrailingSlashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function removeProvider(): array
*/
public function testRemove(string $uri, string $result)
{
$request = Factory::createServerRequest([], 'GET', $uri);
$request = Factory::createServerRequest('GET', $uri);

$response = Dispatcher::run([
new TrailingSlash(),
Expand Down Expand Up @@ -55,7 +55,7 @@ public function addProvider(): array
*/
public function testAdd(string $uri, string $result)
{
$request = Factory::createServerRequest([], 'GET', $uri);
$request = Factory::createServerRequest('GET', $uri);

$response = Dispatcher::run([
new TrailingSlash(true),
Expand All @@ -70,7 +70,7 @@ function ($request, $next) {

public function testRedirect()
{
$request = Factory::createServerRequest([], 'GET', '/foo/bar/');
$request = Factory::createServerRequest('GET', '/foo/bar/');

$response = Dispatcher::run([
(new TrailingSlash())->redirect(),
Expand Down

0 comments on commit 02b979e

Please sign in to comment.