Skip to content

Commit e06b440

Browse files
committed
Merge branch 'feature/8-http-interop'
Close #8
2 parents b97e804 + e83e820 commit e06b440

File tree

5 files changed

+92
-23
lines changed

5 files changed

+92
-23
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 0.2.0 - 2017-10-09
6+
7+
### Added
8+
9+
- [#8](https://github.com/zendframework/zend-expressive-authorization/pull/8) adds
10+
support for http-interop/http-middleware 0.5.0 via a polyfill provided by the
11+
package webimpress/http-middleware-compatibility. Essentially, this means you
12+
can drop this package into an application targeting either the 0.4.1 or 0.5.0
13+
versions of http-middleware, and it will "just work".
14+
15+
### Changed
16+
17+
- Nothing.
18+
19+
### Deprecated
20+
21+
- Nothing.
22+
23+
### Removed
24+
25+
- Nothing.
26+
27+
### Fixed
28+
29+
- Nothing.
30+
531
## 0.1.0 - 2017-09-28
632

733
Initial release.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
"forum": "https://discourse.zendframework.com/c/questions/expressive"
2222
},
2323
"require": {
24-
"http-interop/http-middleware": "^0.4.1",
2524
"php": "^7.1",
2625
"psr/container": "^1.0",
2726
"psr/http-message": "^1.0.1",
28-
"zendframework/zend-expressive-router": "^2.1.0"
27+
"webimpress/http-middleware-compatibility": "^0.1.1",
28+
"zendframework/zend-expressive-router": "^2.2"
2929
},
3030
"require-dev": {
3131
"phpunit/phpunit": "^6.0.8",

composer.lock

Lines changed: 52 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AuthorizationMiddleware.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
namespace Zend\Expressive\Authorization;
99

10-
use Interop\Http\ServerMiddleware\DelegateInterface;
11-
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
1210
use Psr\Http\Message\ResponseInterface;
1311
use Psr\Http\Message\ServerRequestInterface;
12+
use Webimpress\HttpMiddlewareCompatibility\HandlerInterface;
13+
use Webimpress\HttpMiddlewareCompatibility\MiddlewareInterface;
1414

15-
class AuthorizationMiddleware implements ServerMiddlewareInterface
15+
use const Webimpress\HttpMiddlewareCompatibility\HANDLER_METHOD;
16+
17+
class AuthorizationMiddleware implements MiddlewareInterface
1618
{
1719
/**
1820
* @var AuthorizationInterface
@@ -34,7 +36,7 @@ public function __construct(AuthorizationInterface $authorization, ResponseInter
3436
* {@inheritDoc}
3537
* @todo Use role/identity interface from zend-expressive-authentication once published.
3638
*/
37-
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
39+
public function process(ServerRequestInterface $request, HandlerInterface $handler)
3840
{
3941
$role = $request->getAttribute(AuthorizationInterface::class, false);
4042

@@ -43,7 +45,7 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
4345
}
4446

4547
return $this->authorization->isGranted($role, $request)
46-
? $delegate->process($request)
48+
? $handler->{HANDLER_METHOD}($request)
4749
: $this->responsePrototype->withStatus(403);
4850
}
4951
}

test/AuthorizationMiddlewareTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@
77

88
namespace ZendTest\Expressive\Authorization;
99

10-
use Interop\Http\ServerMiddleware\DelegateInterface;
1110
use PHPUnit\Framework\TestCase;
1211
use Prophecy\Argument;
1312
use Psr\Http\Message\ResponseInterface;
1413
use Psr\Http\Message\ServerRequestInterface;
14+
use Webimpress\HttpMiddlewareCompatibility\HandlerInterface;
1515
use Zend\Expressive\Authorization\AuthorizationInterface;
1616
use Zend\Expressive\Authorization\AuthorizationMiddleware;
17-
use Zend\Expressive\Router\RouteResult;
17+
18+
use const Webimpress\HttpMiddlewareCompatibility\HANDLER_METHOD;
1819

1920
class AuthorizationMiddlewareTest extends TestCase
2021
{
2122
protected function setUp()
2223
{
2324
$this->authorization = $this->prophesize(AuthorizationInterface::class);
2425
$this->request = $this->prophesize(ServerRequestInterface::class);
25-
$this->delegate = $this->prophesize(DelegateInterface::class);
26+
$this->delegate = $this->prophesize(HandlerInterface::class);
2627
$this->response = $this->prophesize(ResponseInterface::class);
2728
}
2829

@@ -69,7 +70,7 @@ public function testProcessRoleGranted()
6970
$this->authorization->isGranted('foo', $this->request->reveal())->willReturn(true);
7071

7172
$middleware = new AuthorizationMiddleware($this->authorization->reveal(), $this->response->reveal());
72-
$this->delegate->process(Argument::any())->willReturn($this->response->reveal());
73+
$this->delegate->{HANDLER_METHOD}(Argument::any())->willReturn($this->response->reveal());
7374

7475
$response = $middleware->process(
7576
$this->request->reveal(),

0 commit comments

Comments
 (0)