Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit6bad82f

Browse files
committed
Do not cast request handlers implementing middleware toRequestHandlerMiddleware
Per#645, `MiddlewareContainer::get()` was incorrectly castingmiddleware that also implemented `RequestHandlerInterface` to`RequestHandlerMiddleware`. This particularly affected`Zend\Stratigility\MiddlewarePipe` instances, as they implement bothinterfaces; if the last middleware in a pipeline called on the handler,users would then encounter a "pipeline exhausted" error, because itwould be invoked as a handler, and thus have no reference to theapplication's pipeline.This change verifies that the request handler does not also implement`MiddlewareInterface` before casting.
1 parent4e551cd commit6bad82f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

‎src/MiddlewareContainer.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ public function get($service) : MiddlewareInterface
6363
?$this->container->get($service)
6464
:new$service();
6565

66-
$middleware =$middlewareinstanceof RequestHandlerInterface
67-
?newRequestHandlerMiddleware($middleware)
68-
:$middleware;
66+
if ($middlewareinstanceof RequestHandlerInterface
67+
&& !$middlewareinstanceof MiddlewareInterface
68+
) {
69+
$middleware =newRequestHandlerMiddleware($middleware);
70+
}
6971

7072
if (!$middlewareinstanceof MiddlewareInterface) {
7173
throwException\InvalidMiddlewareException::forMiddlewareService($service,$middleware);

‎test/MiddlewareContainerTest.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,20 @@ public function testGetWillDecorateARequestHandlerAsMiddleware()
101101
$this->assertInstanceOf(RequestHandlerMiddleware::class,$middleware);
102102
$this->assertAttributeSame($handler,'handler',$middleware);
103103
}
104+
105+
/**
106+
* @see https://github.com/zendframework/zend-expressive/issues/645
107+
*/
108+
publicfunctiontestGetDoesNotCastMiddlewareImplementingRequestHandlerToRequestHandlerMiddleware()
109+
{
110+
$pipeline =$this->prophesize(RequestHandlerInterface::class);
111+
$pipeline->willImplement(MiddlewareInterface::class);
112+
113+
$this->originContainer->has('pipeline')->willReturn(true);
114+
$this->originContainer->get('pipeline')->will([$pipeline,'reveal']);
115+
116+
$middleware =$this->container->get('pipeline');
117+
118+
$this->assertSame($middleware,$pipeline->reveal());
119+
}
104120
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp