diff --git a/CHANGELOG.md b/CHANGELOG.md index 19963b6..ea12cce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Versions prior to 1.0 were originally released as `phly/conduit`; please visit its [CHANGELOG](https://github.com/phly/conduit/blob/master/CHANGELOG.md) for details. -## 2.0.1 - TBD +## 2.0.1 - 2017-01-25 ### Added @@ -22,7 +22,10 @@ details. ### Fixed -- Nothing. +- [#98](https://github.com/zendframework/zend-stratigility/pull/98) fixes how + `Middleware::pipe()` handles `MiddlewarePipe` instances passed to it; + previously it was incorrectly wrapping them in `CallableMiddlewareWrapper` + instances; it now pipes them as-is. ## 2.0.0 - 2017-01-24 diff --git a/src/MiddlewarePipe.php b/src/MiddlewarePipe.php index f1d95e9..d5a5979 100644 --- a/src/MiddlewarePipe.php +++ b/src/MiddlewarePipe.php @@ -128,10 +128,9 @@ public function pipe($path, $middleware = null) $path = '/'; } - // Decorate callable middleware as http-interop middleware if we have - // a response prototype present. + // Decorate callable middleware as http-interop middleware if (is_callable($middleware) - && ! $this->isInteropMiddleware($middleware) + && ! $middleware instanceof ServerMiddlewareInterface ) { $middleware = $this->decorateCallableMiddleware($middleware); } @@ -266,18 +265,6 @@ private function getCallableMiddlewareDecorator() return $this->callableMiddlewareDecorator; } - /** - * Is the provided middleware argument http-interop middleware? - * - * @param mixed $middleware - * @return bool - */ - private function isInteropMiddleware($middleware) - { - return ! is_callable($middleware) - && $middleware instanceof ServerMiddlewareInterface; - } - /** * @param callable $middleware * @return \ReflectionFunctionAbstract diff --git a/test/MiddlewarePipeTest.php b/test/MiddlewarePipeTest.php index ab29c90..6e1dfe7 100644 --- a/test/MiddlewarePipeTest.php +++ b/test/MiddlewarePipeTest.php @@ -518,4 +518,19 @@ public function testWillDecorateCallableArrayMiddlewareWithoutErrors() $this->assertInstanceOf(CallableMiddlewareWrapper::class, $test); $this->assertAttributeSame($middleware, 'middleware', $test); } + + public function testPipeShouldNotWrapMiddlewarePipeInstancesAsCallableMiddleware() + { + $nested = new MiddlewarePipe(); + $pipeline = new MiddlewarePipe(); + + $pipeline->pipe($nested); + + $r = new ReflectionProperty($pipeline, 'pipeline'); + $r->setAccessible(true); + $queue = $r->getValue($pipeline); + + $route = $queue->dequeue(); + $this->assertSame($nested, $route->handler); + } }