Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/interop-middleware-detection'
Browse files Browse the repository at this point in the history
Close #98
  • Loading branch information
weierophinney committed Jan 25, 2017
2 parents 8a23a51 + cb75d91 commit 229e7d9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
17 changes: 2 additions & 15 deletions src/MiddlewarePipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/MiddlewarePipeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 229e7d9

Please sign in to comment.