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

Commit

Permalink
Pipe should not decorate MiddlewarePipe instances
Browse files Browse the repository at this point in the history
In prepping Expressive to use Stratigility 2, I discovered that
`MiddlewarePipe` instances piped into another `MiddlewarePipe` instance
were being decorated as callable middleware; this should no longer
happen.

This patch adds a test to ensure it does not happen, and updates
`pipe()` to not decorate callable `ServerMiddlewareInterface` instances.

In doing so, the `isInteropMiddleware()` method is no longer relevant,
and I removed it; since it was marked `private`, this is a backwards
compatible change.
  • Loading branch information
weierophinney committed Jan 25, 2017
1 parent 8a23a51 commit 0d8fe1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
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 0d8fe1d

Please sign in to comment.