浏览代码

Enable MiddlewareQueue to be constructed with middleware objects.

Mark Story 9 年之前
父节点
当前提交
180553633c
共有 2 个文件被更改,包括 19 次插入0 次删除
  1. 10 0
      src/Http/MiddlewareQueue.php
  2. 9 0
      tests/TestCase/Http/MiddlewareQueueTest.php

+ 10 - 0
src/Http/MiddlewareQueue.php

@@ -40,6 +40,16 @@ class MiddlewareQueue implements Countable
     protected $callables = [];
     protected $callables = [];
 
 
     /**
     /**
+     * Constructor
+     *
+     * @param array $middleware The list of middleware to append.
+     */
+    public function __construct(array $middleware = [])
+    {
+        $this->queue = $middleware;
+    }
+
+    /**
      * Get the middleware at the provided index.
      * Get the middleware at the provided index.
      *
      *
      * @param int $index The index to fetch.
      * @param int $index The index to fetch.

+ 9 - 0
tests/TestCase/Http/MiddlewareQueueTest.php

@@ -50,6 +50,15 @@ class MiddlewareQueueTest extends TestCase
         Configure::write('App.namespace', $this->appNamespace);
         Configure::write('App.namespace', $this->appNamespace);
     }
     }
 
 
+    public function testConstructorAddingMiddleware()
+    {
+        $cb = function () {
+        };
+        $queue = new MiddlewareQueue([$cb]);
+        $this->assertCount(1, $queue);
+        $this->assertSame($cb, $queue->get(0));
+    }
+
     /**
     /**
      * Test get()
      * Test get()
      *
      *