Skip to content
Permalink
Browse files

Rename MiddlewareStack to MiddlewareQueue.

  • Loading branch information...
ADmad committed Jul 25, 2016
1 parent c97e14c commit f492ddbce3b4c5a8e92da1dde1327ae53edec524
@@ -43,8 +43,8 @@ public function __construct($configDir)
}
/**
* @param \Cake\Http\MiddlewareStack $middleware The middleware queue to set in your App Class
* @return \Cake\Http\MiddlewareStack
* @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to set in your App Class
* @return \Cake\Http\MiddlewareQueue
*/
abstract public function middleware($middleware);
@@ -21,7 +21,7 @@
* Provides methods for creating and manipulating a "queue" of middleware callables.
* This queue is used to process a request and response via \Cake\Http\Runner.
*/
class MiddlewareStack implements Countable
class MiddlewareQueue implements Countable
{
/**
* The queue of middleware callables.
@@ -33,12 +33,12 @@ class Runner
/**
* The middleware queue being run.
*
* @var MiddlewareStack
* @var MiddlewareQueue
*/
protected $middleware;
/**
* @param \Cake\Http\MiddlewareStack $middleware The middleware queue
* @param \Cake\Http\MiddlewareQueue $middleware The middleware queue
* @param \Psr\Http\Message\ServerRequestInterface $request The Server Request
* @param \Psr\Http\Message\ResponseInterface $response The response
* @return \Psr\Http\Message\ResponseInterface A response object
@@ -73,8 +73,8 @@ public function run(ServerRequestInterface $request = null, ResponseInterface $r
$request = $request ?: ServerRequestFactory::fromGlobals();
$response = $response ?: new Response();
$middleware = $this->app->middleware(new MiddlewareStack());
if (!($middleware instanceof MiddlewareStack)) {
$middleware = $this->app->middleware(new MiddlewareQueue());
if (!($middleware instanceof MiddlewareQueue)) {
throw new RuntimeException('The application `middleware` method did not return a middleware queue.');
}
$this->dispatchEvent('Server.buildMiddleware', ['middleware' => $middleware]);
@@ -14,14 +14,14 @@
*/
namespace Cake\Test\TestCase\Http;
use Cake\Http\MiddlewareStack;
use Cake\Http\MiddlewareQueue;
use Cake\TestSuite\TestCase;
use TestApp\Middleware\SampleMiddleware;
/**
* Test case for the MiddlewareStack
* Test case for the MiddlewareQueue
*/
class MiddlewareStackTest extends TestCase
class MiddlewareQueueTest extends TestCase
{
/**
* Test get()
@@ -30,7 +30,7 @@ class MiddlewareStackTest extends TestCase
*/
public function testGet()
{
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$cb = function () {
};
$stack->add($cb);
@@ -46,7 +46,7 @@ public function testGet()
*/
public function testPushReturn()
{
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$cb = function () {
};
$this->assertSame($stack, $stack->add($cb));
@@ -64,7 +64,7 @@ public function testPushOrdering()
$two = function () {
};
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$this->assertCount(0, $stack);
$stack->add($one);
@@ -86,7 +86,7 @@ public function testPrependReturn()
{
$cb = function () {
};
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$this->assertSame($stack, $stack->prepend($cb));
}
@@ -102,7 +102,7 @@ public function testPrependOrdering()
$two = function () {
};
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$this->assertCount(0, $stack);
$stack->add($one);
@@ -129,13 +129,13 @@ public function testInsertAt()
$three = function () {
};
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$stack->add($one)->add($two)->insertAt(0, $three);
$this->assertSame($three, $stack->get(0));
$this->assertSame($one, $stack->get(1));
$this->assertSame($two, $stack->get(2));
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$stack->add($one)->add($two)->insertAt(1, $three);
$this->assertSame($one, $stack->get(0));
$this->assertSame($three, $stack->get(1));
@@ -154,7 +154,7 @@ public function testInsertAtOutOfBounds()
$two = function () {
};
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$stack->add($one)->insertAt(99, $two);
$this->assertCount(2, $stack);
@@ -174,7 +174,7 @@ public function testInsertAtNegative()
$two = function () {
};
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$stack->add($one)->insertAt(-1, $two);
$this->assertCount(2, $stack);
@@ -194,7 +194,7 @@ public function testInsertBefore()
$two = new SampleMiddleware();
$three = function () {
};
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$stack->add($one)->add($two)->insertBefore(SampleMiddleware::class, $three);
$this->assertCount(3, $stack);
@@ -217,7 +217,7 @@ public function testInsertBeforeInvalid()
$two = new SampleMiddleware();
$three = function () {
};
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$stack->add($one)->add($two)->insertBefore('InvalidClassName', $three);
}
@@ -233,7 +233,7 @@ public function testInsertAfter()
};
$three = function () {
};
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$stack->add($one)->add($two)->insertAfter(SampleMiddleware::class, $three);
$this->assertCount(3, $stack);
@@ -254,7 +254,7 @@ public function testInsertAfterInvalid()
};
$three = function () {
};
$stack = new MiddlewareStack();
$stack = new MiddlewareQueue();
$stack->add($one)->add($two)->insertAfter('InvalidClass', $three);
$this->assertCount(3, $stack);
@@ -14,7 +14,7 @@
*/
namespace Cake\Test\TestCase;
use Cake\Http\MiddlewareStack;
use Cake\Http\MiddlewareQueue;
use Cake\Http\Runner;
use Cake\TestSuite\TestCase;
use RuntimeException;
@@ -32,7 +32,7 @@ class RunnerTest extends TestCase
public function setUp()
{
parent::setUp();
$this->stack = new MiddlewareStack();
$this->stack = new MiddlewareQueue();
$this->ok = function ($req, $res, $next) {
return $next($req, $res);
@@ -184,7 +184,7 @@ public function testBuildMiddlewareEvent()
$this->called = false;
$server->eventManager()->on('Server.buildMiddleware', function ($event, $middleware) {
$this->assertInstanceOf('Cake\Http\MiddlewareStack', $middleware);
$this->assertInstanceOf('Cake\Http\MiddlewareQueue', $middleware);
$middleware->add(function ($req, $res, $next) {
$this->called = true;
@@ -8,8 +8,8 @@
class BadResponseApplication extends BaseApplication
{
/**
* @param \Cake\Http\MiddlewareStack $middleware The middleware stack to set in your App Class
* @return \Cake\Http\MiddlewareStack
* @param \Cake\Http\MiddlewareQueue $middleware The middleware stack to set in your App Class
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware($middleware)
{
@@ -6,7 +6,7 @@
class InvalidMiddlewareApplication extends BaseApplication
{
/**
* @param \Cake\Http\MiddlewareStack $middleware The middleware stack to set in your App Class
* @param \Cake\Http\MiddlewareQueue $middleware The middleware stack to set in your App Class
* @return null
*/
public function middleware($middleware)
@@ -8,8 +8,8 @@
class MiddlewareApplication extends BaseApplication
{
/**
* @param \Cake\Http\MiddlewareStack $middleware The middleware stack to set in your App Class
* @return \Cake\Http\MiddlewareStack
* @param \Cake\Http\MiddlewareQueue $middleware The middleware stack to set in your App Class
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware($middleware)
{

0 comments on commit f492ddb

Please sign in to comment.
You can’t perform that action at this time.