Skip to content

Commit

Permalink
updated http-middleware interface to 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Nov 27, 2016
1 parent 56adb64 commit fa8bc96
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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/).

## 0.2.0 - 2016-11-27

### Changed

* Updated to `http-interop/http-middleware#0.3`

## 0.1.0 - 2016-10-09

First version
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# middlewares/cors

[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![Software License][ico-license]](LICENSE)
[![Build Status][ico-travis]][link-travis]
[![Quality Score][ico-scrutinizer]][link-scrutinizer]
[![Total Downloads][ico-downloads]][link-downloads]
Expand All @@ -13,7 +13,7 @@ Middleware to implement Cross-Origin Resource Sharing (CORS) using [neomerx/cors

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

## Installation

Expand All @@ -39,7 +39,7 @@ $dispatcher = new Dispatcher([
new Middlewares\Cors($settings)
]);

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

## Options
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
},
"require": {
"php": "^5.6 || ^7.0",
"http-interop/http-middleware": "^0.2",
"http-interop/http-middleware": "^0.3",
"neomerx/cors-psr7": "^1.0",
"middlewares/utils": "~0.3"
"middlewares/utils": "~0.5"
},
"require-dev": {
"phpunit/phpunit": "^5.5",
"zendframework/zend-diactoros": "^1.3",
"friendsofphp/php-cs-fixer": "^1.12",
"squizlabs/php_codesniffer": "^2.7",
"mindplay/middleman": "^2.0"
"squizlabs/php_codesniffer": "^2.7"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 6 additions & 6 deletions src/Cors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Middlewares;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Interop\Http\Middleware\MiddlewareInterface;
use Interop\Http\Middleware\ServerMiddlewareInterface;
use Interop\Http\Middleware\DelegateInterface;
use Neomerx\Cors\Analyzer;
use Neomerx\Cors\Contracts\AnalysisResultInterface;
use Neomerx\Cors\Contracts\Strategies\SettingsStrategyInterface;

class Cors implements MiddlewareInterface
class Cors implements ServerMiddlewareInterface
{
/**
* @var SettingsStrategyInterface
Expand All @@ -30,12 +30,12 @@ public function __construct(SettingsStrategyInterface $settings)
/**
* Process a request and return a response.
*
* @param RequestInterface $request
* @param DelegateInterface $delegate
* @param ServerRequestInterface $request
* @param DelegateInterface $delegate
*
* @return ResponseInterface
*/
public function process(RequestInterface $request, DelegateInterface $delegate)
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
$cors = Analyzer::instance($this->settings)->analyze($request);

Expand Down
11 changes: 6 additions & 5 deletions tests/CorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace Middlewares\Tests;

use Middlewares\Cors;
use Zend\Diactoros\Request;
use Middlewares\Utils\Dispatcher;
use Middlewares\Utils\CallableMiddleware;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Response;
use mindplay\middleman\Dispatcher;
use Neomerx\Cors\Strategies\Settings;
use Neomerx\Cors\Contracts\Constants\CorsResponseHeaders;

Expand Down Expand Up @@ -61,10 +62,10 @@ public function testCors($url, $statusCode)

$response = (new Dispatcher([
new Cors($settings),
function () {
new CallableMiddleware(function () {
return new Response();
},
]))->dispatch(new Request($url));
}),
]))->dispatch(new ServerRequest([], [], $url));

$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
$this->assertEquals($statusCode, $response->getStatusCode());
Expand Down

0 comments on commit fa8bc96

Please sign in to comment.