Skip to content
This repository
Browse code

Initial middelware implementation

  • Loading branch information...
commit d17a471451570757115e24aea30572f9f0c35add 1 parent f677bfe
José Lorenzo Rodríguez authored April 15, 2012
109  lib/Cake/Routing/Dispatcher.php
@@ -27,6 +27,9 @@
27 27
 App::uses('Scaffold', 'Controller');
28 28
 App::uses('View', 'View');
29 29
 App::uses('Debugger', 'Utility');
  30
+App::uses('CakeEvent', 'Event');
  31
+App::uses('CakeEventManager', 'Event');
  32
+App::uses('CakeEventListener', 'Event');
30 33
 
31 34
 /**
32 35
  * Dispatcher converts Requests into controller actions.  It uses the dispatched Request
@@ -35,7 +38,9 @@
35 38
  *
36 39
  * @package       Cake.Routing
37 40
  */
38  
-class Dispatcher {
  41
+class Dispatcher implements CakeEventListener {
  42
+
  43
+	protected $_eventManager;
39 44
 
40 45
 /**
41 46
  * Constructor.
@@ -48,6 +53,25 @@ public function __construct($base = false) {
48 53
 		}
49 54
 	}
50 55
 
  56
+	public function getEventManager() {
  57
+		if (!$this->_eventManager) {
  58
+			$this->_eventManager = new CakeEventManager();
  59
+			$this->_eventManager->attach($this);
  60
+		}
  61
+		return $this->_eventManager;
  62
+	}
  63
+
  64
+
  65
+	public function implementedEvents() {
  66
+		return array(
  67
+			'Dispatcher.before' => array(
  68
+				array('callable' => array($this, 'asset')),
  69
+				array('callable' => array($this, 'cached')),
  70
+				array('callable' => array($this, 'parseParams')),
  71
+			)
  72
+		);
  73
+	}
  74
+
51 75
 /**
52 76
  * Dispatches and invokes given Request, handing over control to the involved controller. If the controller is set
53 77
  * to autoRender, via Controller::$autoRender, then Dispatcher will render the view.
@@ -67,12 +91,16 @@ public function __construct($base = false) {
67 91
  * @throws MissingControllerException When the controller is missing.
68 92
  */
69 93
 	public function dispatch(CakeRequest $request, CakeResponse $response, $additionalParams = array()) {
70  
-		if ($this->asset($request->url, $response) || $this->cached($request->here())) {
  94
+		$beforeEvent = new CakeEvent('Dispatcher.before', $this, compact('request', 'response', 'additionalParams'));
  95
+		$this->getEventManager()->dispatch($beforeEvent);
  96
+
  97
+		$request = $beforeEvent->data['request'];
  98
+		if ($beforeEvent->result instanceof CakeResponse) {
  99
+			$beforeEvent->result->send();
71 100
 			return;
72 101
 		}
73 102
 
74 103
 		Router::setRequestInfo($request);
75  
-		$request = $this->parseParams($request, $additionalParams);
76 104
 		$controller = $this->_getController($request, $response);
77 105
 
78 106
 		if (!($controller instanceof Controller)) {
@@ -82,7 +110,14 @@ public function dispatch(CakeRequest $request, CakeResponse $response, $addition
82 110
 			));
83 111
 		}
84 112
 
85  
-		return $this->_invoke($controller, $request, $response);
  113
+		$response = $this->_invoke($controller, $request, $response);
  114
+		if (isset($request->params['return'])) {
  115
+			return $response->body();
  116
+		}
  117
+
  118
+		$afterEvent = new CakeEvent('Dispatcher.after', $this, compact('request', 'response'));
  119
+		$this->getEventManager()->dispatch($afterEvent);
  120
+		$afterEvent->data['response']->send();
86 121
 	}
87 122
 
88 123
 /**
@@ -93,7 +128,7 @@ public function dispatch(CakeRequest $request, CakeResponse $response, $addition
93 128
  * @param Controller $controller Controller to invoke
94 129
  * @param CakeRequest $request The request object to invoke the controller for.
95 130
  * @param CakeResponse $response The response object to receive the output
96  
- * @return void
  131
+ * @return CakeResponse te resulting response object
97 132
  */
98 133
 	protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) {
99 134
 		$controller->constructClasses();
@@ -113,22 +148,18 @@ protected function _invoke(Controller $controller, CakeRequest $request, CakeRes
113 148
 		}
114 149
 		$controller->shutdownProcess();
115 150
 
116  
-		if (isset($request->params['return'])) {
117  
-			return $response->body();
118  
-		}
119  
-		$response->send();
  151
+		return $response;
120 152
 	}
121 153
 
122 154
 /**
123 155
  * Applies Routing and additionalParameters to the request to be dispatched.
124 156
  * If Routes have not been loaded they will be loaded, and app/Config/routes.php will be run.
125 157
  *
126  
- * @param CakeRequest $request CakeRequest object to mine for parameter information.
127  
- * @param array $additionalParams An array of additional parameters to set to the request.
128  
- *   Useful when Object::requestAction() is involved
129  
- * @return CakeRequest The request object with routing params set.
  158
+ * @param CakeEvent $event containing the request, response and additional params
  159
+ * @return void
130 160
  */
131  
-	public function parseParams(CakeRequest $request, $additionalParams = array()) {
  161
+	public function parseParams($event) {
  162
+		$request = $event->data['request'];
132 163
 		if (count(Router::$routes) == 0) {
133 164
 			$namedExpressions = Router::getNamedExpressions();
134 165
 			extract($namedExpressions);
@@ -138,10 +169,9 @@ public function parseParams(CakeRequest $request, $additionalParams = array()) {
138 169
 		$params = Router::parse($request->url);
139 170
 		$request->addParams($params);
140 171
 
141  
-		if (!empty($additionalParams)) {
142  
-			$request->addParams($additionalParams);
  172
+		if (!empty($event->data['additionalParams'])) {
  173
+			$request->addParams($event->data['additionalParams']);
143 174
 		}
144  
-		return $request;
145 175
 	}
146 176
 
147 177
 /**
@@ -200,12 +230,13 @@ protected function _loadRoutes() {
200 230
 	}
201 231
 
202 232
 /**
203  
- * Outputs cached dispatch view cache
  233
+ * Checks whether the response was cached and set the body accordingly.
204 234
  *
205  
- * @param string $path Requested URL path with any query string parameters
206  
- * @return string|boolean False if is not cached or output
  235
+ * @param CakeEvent $event containing the request and response object
  236
+ * @return CakeResponse with cached content if found, null otherwise
207 237
  */
208  
-	public function cached($path) {
  238
+	public function cached($event) {
  239
+		$path = $event->data['request']->here();
209 240
 		if (Configure::read('Cache.check') === true) {
210 241
 			if ($path == '/') {
211 242
 				$path = 'home';
@@ -220,23 +251,29 @@ public function cached($path) {
220 251
 			if (file_exists($filename)) {
221 252
 				$controller = null;
222 253
 				$view = new View($controller);
223  
-				return $view->renderCache($filename, microtime(true));
  254
+				$result = $view->renderCache($filename, microtime(true));
  255
+				if ($result !== false) {
  256
+					$event->data['response']->body($result);
  257
+					return $event->data['response'];
  258
+				}
224 259
 			}
225 260
 		}
226  
-		return false;
227 261
 	}
228 262
 
229 263
 /**
230 264
  * Checks if a requested asset exists and sends it to the browser
231 265
  *
232  
- * @param string $url Requested URL
233  
- * @param CakeResponse $response The response object to put the file contents in.
234  
- * @return boolean True on success if the asset file was found and sent
  266
+ * @param CakeEvent $event containing the request and response object
  267
+ * @return CakeResponse if the client is requesting a recognized asset, null otherwise
235 268
  */
236  
-	public function asset($url, CakeResponse $response) {
  269
+	public function asset($event) {
  270
+		$url = $event->data['request']->url;
  271
+		$response = $event->data['response'];
  272
+
237 273
 		if (strpos($url, '..') !== false || strpos($url, '.') === false) {
238  
-			return false;
  274
+			return;
239 275
 		}
  276
+
240 277
 		$filters = Configure::read('Asset.filter');
241 278
 		$isCss = (
242 279
 			strpos($url, 'ccss/') === 0 ||
@@ -246,17 +283,21 @@ public function asset($url, CakeResponse $response) {
246 283
 			strpos($url, 'cjs/') === 0 ||
247 284
 			preg_match('#^/((theme/[^/]+)/cjs/)|(([^/]+)(?<!js)/cjs)/#i', $url)
248 285
 		);
  286
+
249 287
 		if (($isCss && empty($filters['css'])) || ($isJs && empty($filters['js']))) {
250 288
 			$response->statusCode(404);
251  
-			$response->send();
252  
-			return true;
  289
+			$event->stopPropagation();
  290
+			return $response;
253 291
 		} elseif ($isCss) {
254 292
 			include WWW_ROOT . DS . $filters['css'];
255  
-			return true;
  293
+			$event->stopPropagation();
  294
+			return $response;
256 295
 		} elseif ($isJs) {
257 296
 			include WWW_ROOT . DS . $filters['js'];
258  
-			return true;
  297
+			$event->stopPropagation();
  298
+			return $response;
259 299
 		}
  300
+
260 301
 		$pathSegments = explode('.', $url);
261 302
 		$ext = array_pop($pathSegments);
262 303
 		$parts = explode('/', $url);
@@ -283,10 +324,10 @@ public function asset($url, CakeResponse $response) {
283 324
 		}
284 325
 
285 326
 		if ($assetFile !== null) {
  327
+			$event->stopPropagation();
286 328
 			$this->_deliverAsset($response, $assetFile, $ext);
287  
-			return true;
  329
+			return $response;
288 330
 		}
289  
-		return false;
290 331
 	}
291 332
 
292 333
 /**
367  lib/Cake/Test/Case/Routing/DispatcherTest.php
@@ -45,6 +45,13 @@ protected function _sendHeader($name, $value = null) {
45 45
 class TestDispatcher extends Dispatcher {
46 46
 
47 47
 /**
  48
+ * Controller instance, made publicly available for testing
  49
+ *
  50
+ * @var Controller
  51
+ **/
  52
+	public $controller;
  53
+
  54
+/**
48 55
  * invoke method
49 56
  *
50 57
  * @param mixed $controller
@@ -52,8 +59,8 @@ class TestDispatcher extends Dispatcher {
52 59
  * @return void
53 60
  */
54 61
 	protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) {
55  
-		$result = parent::_invoke($controller, $request, $response);
56  
-		return $controller;
  62
+		$this->controller = $controller;
  63
+		return parent::_invoke($controller, $request, $response);
57 64
 	}
58 65
 
59 66
 }
@@ -565,14 +572,15 @@ public function tearDown() {
565 572
  */
566 573
 	public function testParseParamsWithoutZerosAndEmptyPost() {
567 574
 		$Dispatcher = new Dispatcher();
568  
-
569  
-		$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/params1/params2/params3"));
570  
-		$this->assertSame($test['controller'], 'testcontroller');
571  
-		$this->assertSame($test['action'], 'testaction');
572  
-		$this->assertSame($test['pass'][0], 'params1');
573  
-		$this->assertSame($test['pass'][1], 'params2');
574  
-		$this->assertSame($test['pass'][2], 'params3');
575  
-		$this->assertFalse(!empty($test['form']));
  575
+		$request = new CakeRequest("/testcontroller/testaction/params1/params2/params3");
  576
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $request));
  577
+		$Dispatcher->parseParams($event);
  578
+		$this->assertSame($request['controller'], 'testcontroller');
  579
+		$this->assertSame($request['action'], 'testaction');
  580
+		$this->assertSame($request['pass'][0], 'params1');
  581
+		$this->assertSame($request['pass'][1], 'params2');
  582
+		$this->assertSame($request['pass'][2], 'params3');
  583
+		$this->assertFalse(!empty($request['form']));
576 584
 	}
577 585
 
578 586
 /**
@@ -583,9 +591,11 @@ public function testParseParamsWithoutZerosAndEmptyPost() {
583 591
 	public function testParseParamsReturnsPostedData() {
584 592
 		$_POST['testdata'] = "My Posted Content";
585 593
 		$Dispatcher = new Dispatcher();
586  
-
587  
-		$test = $Dispatcher->parseParams(new CakeRequest("/"));
588  
-		$this->assertEquals("My Posted Content", $test['data']['testdata']);
  594
+		$request = new CakeRequest("/");
  595
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $request));
  596
+		$Dispatcher->parseParams($event);
  597
+		$test = $Dispatcher->parseParams($event);
  598
+		$this->assertEquals("My Posted Content", $request['data']['testdata']);
589 599
 	}
590 600
 
591 601
 /**
@@ -595,7 +605,10 @@ public function testParseParamsReturnsPostedData() {
595 605
  */
596 606
 	public function testParseParamsWithSingleZero() {
597 607
 		$Dispatcher = new Dispatcher();
598  
-		$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/1/0/23"));
  608
+		$test = new CakeRequest("/testcontroller/testaction/1/0/23");
  609
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $test));
  610
+		$Dispatcher->parseParams($event);
  611
+
599 612
 		$this->assertSame($test['controller'], 'testcontroller');
600 613
 		$this->assertSame($test['action'], 'testaction');
601 614
 		$this->assertSame($test['pass'][0], '1');
@@ -610,7 +623,10 @@ public function testParseParamsWithSingleZero() {
610 623
  */
611 624
 	public function testParseParamsWithManySingleZeros() {
612 625
 		$Dispatcher = new Dispatcher();
613  
-		$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/0/0/0/0/0/0"));
  626
+		$test = new CakeRequest("/testcontroller/testaction/0/0/0/0/0/0");
  627
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $test));
  628
+		$Dispatcher->parseParams($event);
  629
+
614 630
 		$this->assertRegExp('/\\A(?:0)\\z/', $test['pass'][0]);
615 631
 		$this->assertRegExp('/\\A(?:0)\\z/', $test['pass'][1]);
616 632
 		$this->assertRegExp('/\\A(?:0)\\z/', $test['pass'][2]);
@@ -626,8 +642,10 @@ public function testParseParamsWithManySingleZeros() {
626 642
  */
627 643
 	public function testParseParamsWithManyZerosInEachSectionOfUrl() {
628 644
 		$Dispatcher = new Dispatcher();
629  
-		$request = new CakeRequest("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
630  
-		$test = $Dispatcher->parseParams($request);
  645
+		$test = new CakeRequest("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
  646
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $test));
  647
+		$Dispatcher->parseParams($event);
  648
+
631 649
 		$this->assertRegExp('/\\A(?:000)\\z/', $test['pass'][0]);
632 650
 		$this->assertRegExp('/\\A(?:0000)\\z/', $test['pass'][1]);
633 651
 		$this->assertRegExp('/\\A(?:00000)\\z/', $test['pass'][2]);
@@ -643,9 +661,10 @@ public function testParseParamsWithManyZerosInEachSectionOfUrl() {
643 661
  */
644 662
 	public function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
645 663
 		$Dispatcher = new Dispatcher();
  664
+		$test = new CakeRequest("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
  665
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $test));
  666
+		$Dispatcher->parseParams($event);
646 667
 
647  
-		$request = new CakeRequest("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
648  
-		$test = $Dispatcher->parseParams($request);
649 668
 		$this->assertRegExp('/\\A(?:01)\\z/', $test['pass'][0]);
650 669
 		$this->assertRegExp('/\\A(?:0403)\\z/', $test['pass'][1]);
651 670
 		$this->assertRegExp('/\\A(?:04010)\\z/', $test['pass'][2]);
@@ -667,22 +686,25 @@ public function testQueryStringOnRoot() {
667 686
 
668 687
 		$_GET = array('coffee' => 'life', 'sleep' => 'sissies');
669 688
 		$Dispatcher = new Dispatcher();
670  
-		$uri = new CakeRequest('posts/home/?coffee=life&sleep=sissies');
671  
-		$result = $Dispatcher->parseParams($uri);
672  
-		$this->assertRegExp('/posts/', $result['controller']);
673  
-		$this->assertRegExp('/home/', $result['action']);
674  
-		$this->assertTrue(isset($result['url']['sleep']));
675  
-		$this->assertTrue(isset($result['url']['coffee']));
  689
+		$request = new CakeRequest('posts/home/?coffee=life&sleep=sissies');
  690
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $request));
  691
+		$Dispatcher->parseParams($event);
  692
+
  693
+		$this->assertRegExp('/posts/', $request['controller']);
  694
+		$this->assertRegExp('/home/', $request['action']);
  695
+		$this->assertTrue(isset($request['url']['sleep']));
  696
+		$this->assertTrue(isset($request['url']['coffee']));
676 697
 
677 698
 		$Dispatcher = new Dispatcher();
678  
-		$uri = new CakeRequest('/?coffee=life&sleep=sissy');
679  
-
680  
-		$result = $Dispatcher->parseParams($uri);
681  
-		$this->assertRegExp('/pages/', $result['controller']);
682  
-		$this->assertRegExp('/display/', $result['action']);
683  
-		$this->assertTrue(isset($result['url']['sleep']));
684  
-		$this->assertTrue(isset($result['url']['coffee']));
685  
-		$this->assertEquals('life', $result['url']['coffee']);
  699
+		$request = new CakeRequest('/?coffee=life&sleep=sissy');
  700
+
  701
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $request));
  702
+		$Dispatcher->parseParams($event);
  703
+		$this->assertRegExp('/pages/', $request['controller']);
  704
+		$this->assertRegExp('/display/', $request['action']);
  705
+		$this->assertTrue(isset($request['url']['sleep']));
  706
+		$this->assertTrue(isset($request['url']['coffee']));
  707
+		$this->assertEquals('life', $request['url']['coffee']);
686 708
 	}
687 709
 
688 710
 /**
@@ -700,7 +722,7 @@ public function testMissingController() {
700 722
 		$url = new CakeRequest('some_controller/home/param:value/param2:value2');
701 723
 		$response = $this->getMock('CakeResponse');
702 724
 
703  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  725
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
704 726
 	}
705 727
 
706 728
 /**
@@ -718,7 +740,7 @@ public function testMissingControllerInterface() {
718 740
 		$url = new CakeRequest('dispatcher_test_interface/index');
719 741
 		$response = $this->getMock('CakeResponse');
720 742
 
721  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  743
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
722 744
 	}
723 745
 
724 746
 /**
@@ -736,7 +758,7 @@ public function testMissingControllerAbstract() {
736 758
 		$url = new CakeRequest('dispatcher_test_abstract/index');
737 759
 		$response = $this->getMock('CakeResponse');
738 760
 
739  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  761
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
740 762
 	}
741 763
 
742 764
 /**
@@ -753,27 +775,27 @@ public function testDispatchBasic() {
753 775
 		$url = new CakeRequest('pages/home/param:value/param2:value2');
754 776
 		$response = $this->getMock('CakeResponse');
755 777
 
756  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  778
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
757 779
 		$expected = 'Pages';
758  
-		$this->assertEquals($expected, $controller->name);
  780
+		$this->assertEquals($expected, $Dispatcher->controller->name);
759 781
 
760 782
 		$expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
761  
-		$this->assertSame($expected, $controller->passedArgs);
  783
+		$this->assertSame($expected, $Dispatcher->controller->passedArgs);
762 784
 
763  
-		Configure::write('App.baseUrl','/pages/index.php');
  785
+		Configure::write('App.baseUrl', '/pages/index.php');
764 786
 
765 787
 		$url = new CakeRequest('pages/home');
766  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  788
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
767 789
 
768 790
 		$expected = 'Pages';
769  
-		$this->assertEquals($expected, $controller->name);
  791
+		$this->assertEquals($expected, $Dispatcher->controller->name);
770 792
 
771 793
 		$url = new CakeRequest('pages/home/');
772  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
773  
-		$this->assertNull($controller->plugin);
  794
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
  795
+		$this->assertNull($Dispatcher->controller->plugin);
774 796
 
775 797
 		$expected = 'Pages';
776  
-		$this->assertEquals($expected, $controller->name);
  798
+		$this->assertEquals($expected, $Dispatcher->controller->name);
777 799
 
778 800
 		unset($Dispatcher);
779 801
 
@@ -782,24 +804,24 @@ public function testDispatchBasic() {
782 804
 		Configure::write('App.baseUrl', '/timesheets/index.php');
783 805
 
784 806
 		$url = new CakeRequest('timesheets');
785  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  807
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
786 808
 
787 809
 		$expected = 'Timesheets';
788  
-		$this->assertEquals($expected, $controller->name);
  810
+		$this->assertEquals($expected, $Dispatcher->controller->name);
789 811
 
790 812
 		$url = new CakeRequest('timesheets/');
791  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  813
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
792 814
 
793  
-		$this->assertEquals('Timesheets', $controller->name);
  815
+		$this->assertEquals('Timesheets', $Dispatcher->controller->name);
794 816
 		$this->assertEquals('/timesheets/index.php', $url->base);
795 817
 
796 818
 		$url = new CakeRequest('test_dispatch_pages/camelCased');
797  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
798  
-		$this->assertEquals('TestDispatchPages', $controller->name);
  819
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
  820
+		$this->assertEquals('TestDispatchPages', $Dispatcher->controller->name);
799 821
 
800 822
 		$url = new CakeRequest('test_dispatch_pages/camelCased/something. .');
801  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
802  
-		$this->assertEquals('something. .', $controller->params['pass'][0], 'Period was chopped off. %s');
  823
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
  824
+		$this->assertEquals('something. .', $Dispatcher->controller->params['pass'][0], 'Period was chopped off. %s');
803 825
 	}
804 826
 
805 827
 /**
@@ -834,18 +856,18 @@ public function testAdminDispatch() {
834 856
 		$response = $this->getMock('CakeResponse');
835 857
 
836 858
 		Router::reload();
837  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  859
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
838 860
 
839  
-		$this->assertEquals('TestDispatchPages', $controller->name);
  861
+		$this->assertEquals('TestDispatchPages', $Dispatcher->controller->name);
840 862
 
841  
-		$this->assertSame($controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
842  
-		$this->assertTrue($controller->params['admin']);
  863
+		$this->assertSame($Dispatcher->controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
  864
+		$this->assertTrue($Dispatcher->controller->params['admin']);
843 865
 
844 866
 		$expected = '/cake/repo/branches/1.2.x.x/index.php/admin/test_dispatch_pages/index/param:value/param2:value2';
845  
-		$this->assertSame($expected, $controller->here);
  867
+		$this->assertSame($expected, $Dispatcher->controller->here);
846 868
 
847 869
 		$expected = '/cake/repo/branches/1.2.x.x/index.php';
848  
-		$this->assertSame($expected, $controller->base);
  870
+		$this->assertSame($expected, $Dispatcher->controller->base);
849 871
 	}
850 872
 
851 873
 /**
@@ -865,22 +887,23 @@ public function testPluginDispatch() {
865 887
 
866 888
 		$url = new CakeRequest('my_plugin/some_pages/home/param:value/param2:value2');
867 889
 		$response = $this->getMock('CakeResponse');
868  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  890
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
869 891
 
870  
-		$result = $Dispatcher->parseParams($url);
  892
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, array('request' => $url));
  893
+		$Dispatcher->parseParams($event);
871 894
 		$expected = array(
872 895
 			'pass' => array('home'),
873 896
 			'named' => array('param' => 'value', 'param2' => 'value2'), 'plugin' => 'my_plugin',
874 897
 			'controller' => 'some_pages', 'action' => 'display'
875 898
 		);
876 899
 		foreach ($expected as $key => $value) {
877  
-			$this->assertEquals($value, $result[$key], 'Value mismatch ' . $key . ' %');
  900
+			$this->assertEquals($value, $url[$key], 'Value mismatch ' . $key . ' %');
878 901
 		}
879 902
 
880  
-		$this->assertSame($controller->plugin, 'MyPlugin');
881  
-		$this->assertSame($controller->name, 'SomePages');
882  
-		$this->assertSame($controller->params['controller'], 'some_pages');
883  
-		$this->assertSame($controller->passedArgs, array('0' => 'home', 'param' => 'value', 'param2' => 'value2'));
  903
+		$this->assertSame($Dispatcher->controller->plugin, 'MyPlugin');
  904
+		$this->assertSame($Dispatcher->controller->name, 'SomePages');
  905
+		$this->assertSame($Dispatcher->controller->params['controller'], 'some_pages');
  906
+		$this->assertSame($Dispatcher->controller->passedArgs, array('0' => 'home', 'param' => 'value', 'param2' => 'value2'));
884 907
 	}
885 908
 
886 909
 /**
@@ -903,12 +926,12 @@ public function testAutomaticPluginDispatch() {
903 926
 
904 927
 		$url = new CakeRequest('my_plugin/other_pages/index/param:value/param2:value2');
905 928
 		$response = $this->getMock('CakeResponse');
906  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  929
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
907 930
 
908  
-		$this->assertSame($controller->plugin, 'MyPlugin');
909  
-		$this->assertSame($controller->name, 'OtherPages');
910  
-		$this->assertSame($controller->action, 'index');
911  
-		$this->assertSame($controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
  931
+		$this->assertSame($Dispatcher->controller->plugin, 'MyPlugin');
  932
+		$this->assertSame($Dispatcher->controller->name, 'OtherPages');
  933
+		$this->assertSame($Dispatcher->controller->action, 'index');
  934
+		$this->assertSame($Dispatcher->controller->passedArgs, array('param' => 'value', 'param2' => 'value2'));
912 935
 
913 936
 		$expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2';
914 937
 		$this->assertSame($expected, $url->here);
@@ -936,12 +959,12 @@ public function testAutomaticPluginControllerDispatch() {
936 959
 		$url = new CakeRequest('my_plugin/my_plugin/add/param:value/param2:value2');
937 960
 		$response = $this->getMock('CakeResponse');
938 961
 
939  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  962
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
940 963
 
941  
-		$this->assertSame($controller->plugin, 'MyPlugin');
942  
-		$this->assertSame($controller->name, 'MyPlugin');
943  
-		$this->assertSame($controller->action, 'add');
944  
-		$this->assertEquals(array('param' => 'value', 'param2' => 'value2'), $controller->params['named']);
  964
+		$this->assertSame($Dispatcher->controller->plugin, 'MyPlugin');
  965
+		$this->assertSame($Dispatcher->controller->name, 'MyPlugin');
  966
+		$this->assertSame($Dispatcher->controller->action, 'add');
  967
+		$this->assertEquals(array('param' => 'value', 'param2' => 'value2'), $Dispatcher->controller->params['named']);
945 968
 
946 969
 		Router::reload();
947 970
 		require CAKE . 'Config' . DS . 'routes.php';
@@ -955,13 +978,13 @@ public function testAutomaticPluginControllerDispatch() {
955 978
 		$pluginUrl = Inflector::underscore($plugin);
956 979
 
957 980
 		$url = new CakeRequest($pluginUrl);
958  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
959  
-		$this->assertSame($controller->plugin, 'MyPlugin');
960  
-		$this->assertSame($controller->name, 'MyPlugin');
961  
-		$this->assertSame($controller->action, 'index');
  981
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
  982
+		$this->assertSame($Dispatcher->controller->plugin, 'MyPlugin');
  983
+		$this->assertSame($Dispatcher->controller->name, 'MyPlugin');
  984
+		$this->assertSame($Dispatcher->controller->action, 'index');
962 985
 
963 986
 		$expected = $pluginUrl;
964  
-		$this->assertEquals($expected, $controller->params['controller']);
  987
+		$this->assertEquals($expected, $Dispatcher->controller->params['controller']);
965 988
 
966 989
 		Configure::write('Routing.prefixes', array('admin'));
967 990
 
@@ -972,19 +995,19 @@ public function testAutomaticPluginControllerDispatch() {
972 995
 		$url = new CakeRequest('admin/my_plugin/my_plugin/add/5/param:value/param2:value2');
973 996
 		$response = $this->getMock('CakeResponse');
974 997
 
975  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  998
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
976 999
 
977  
-		$this->assertEquals('my_plugin', $controller->params['plugin']);
978  
-		$this->assertEquals('my_plugin', $controller->params['controller']);
979  
-		$this->assertEquals('admin_add', $controller->params['action']);
980  
-		$this->assertEquals(array(5), $controller->params['pass']);
981  
-		$this->assertEquals(array('param' => 'value', 'param2' => 'value2'), $controller->params['named']);
982  
-		$this->assertSame($controller->plugin, 'MyPlugin');
983  
-		$this->assertSame($controller->name, 'MyPlugin');
984  
-		$this->assertSame($controller->action, 'admin_add');
  1000
+		$this->assertEquals('my_plugin', $Dispatcher->controller->params['plugin']);
  1001
+		$this->assertEquals('my_plugin', $Dispatcher->controller->params['controller']);
  1002
+		$this->assertEquals('admin_add', $Dispatcher->controller->params['action']);
  1003
+		$this->assertEquals(array(5), $Dispatcher->controller->params['pass']);
  1004
+		$this->assertEquals(array('param' => 'value', 'param2' => 'value2'), $Dispatcher->controller->params['named']);
  1005
+		$this->assertSame($Dispatcher->controller->plugin, 'MyPlugin');
  1006
+		$this->assertSame($Dispatcher->controller->name, 'MyPlugin');
  1007
+		$this->assertSame($Dispatcher->controller->action, 'admin_add');
985 1008
 
986 1009
 		$expected = array(0 => 5, 'param' => 'value', 'param2' => 'value2');
987  
-		$this->assertEquals($expected, $controller->passedArgs);
  1010
+		$this->assertEquals($expected, $Dispatcher->controller->passedArgs);
988 1011
 
989 1012
 		Configure::write('Routing.prefixes', array('admin'));
990 1013
 		CakePlugin::load('ArticlesTest', array('path' => '/fake/path'));
@@ -993,10 +1016,10 @@ public function testAutomaticPluginControllerDispatch() {
993 1016
 
994 1017
 		$Dispatcher = new TestDispatcher();
995 1018
 
996  
-		$controller = $Dispatcher->dispatch(new CakeRequest('admin/articles_test'), $response, array('return' => 1));
997  
-		$this->assertSame($controller->plugin, 'ArticlesTest');
998  
-		$this->assertSame($controller->name, 'ArticlesTest');
999  
-		$this->assertSame($controller->action, 'admin_index');
  1019
+		$Dispatcher->dispatch(new CakeRequest('admin/articles_test'), $response, array('return' => 1));
  1020
+		$this->assertSame($Dispatcher->controller->plugin, 'ArticlesTest');
  1021
+		$this->assertSame($Dispatcher->controller->name, 'ArticlesTest');
  1022
+		$this->assertSame($Dispatcher->controller->action, 'admin_index');
1000 1023
 
1001 1024
 		$expected = array(
1002 1025
 			'pass' => array(),
@@ -1009,7 +1032,7 @@ public function testAutomaticPluginControllerDispatch() {
1009 1032
 			'return' => 1
1010 1033
 		);
1011 1034
 		foreach ($expected as $key => $value) {
1012  
-			$this->assertEquals($expected[$key], $controller->request[$key], 'Value mismatch ' . $key);
  1035
+			$this->assertEquals($expected[$key], $Dispatcher->controller->request[$key], 'Value mismatch ' . $key);
1013 1036
 		}
1014 1037
 	}
1015 1038
 
@@ -1029,11 +1052,11 @@ public function testAutomaticPluginDispatchWithShortAccess() {
1029 1052
 		$url = new CakeRequest('my_plugin/');
1030 1053
 		$response = $this->getMock('CakeResponse');
1031 1054
 
1032  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
1033  
-		$this->assertEquals('my_plugin', $controller->params['controller']);
1034  
-		$this->assertEquals('my_plugin', $controller->params['plugin']);
1035  
-		$this->assertEquals('index', $controller->params['action']);
1036  
-		$this->assertFalse(isset($controller->params['pass'][0]));
  1055
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
  1056
+		$this->assertEquals('my_plugin', $Dispatcher->controller->params['controller']);
  1057
+		$this->assertEquals('my_plugin', $Dispatcher->controller->params['plugin']);
  1058
+		$this->assertEquals('index', $Dispatcher->controller->params['action']);
  1059
+		$this->assertFalse(isset($Dispatcher->controller->params['pass'][0]));
1037 1060
 	}
1038 1061
 
1039 1062
 /**
@@ -1058,25 +1081,25 @@ public function testPluginShortCutUrlsWithControllerThatNeedsToBeLoaded() {
1058 1081
 		$url = new CakeRequest('test_plugin/');
1059 1082
 		$response = $this->getMock('CakeResponse');
1060 1083
 
1061  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
1062  
-		$this->assertEquals('test_plugin', $controller->params['controller']);
1063  
-		$this->assertEquals('test_plugin', $controller->params['plugin']);
1064  
-		$this->assertEquals('index', $controller->params['action']);
1065  
-		$this->assertFalse(isset($controller->params['pass'][0]));
  1084
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
  1085
+		$this->assertEquals('test_plugin', $Dispatcher->controller->params['controller']);
  1086
+		$this->assertEquals('test_plugin', $Dispatcher->controller->params['plugin']);
  1087
+		$this->assertEquals('index', $Dispatcher->controller->params['action']);
  1088
+		$this->assertFalse(isset($Dispatcher->controller->params['pass'][0]));
1066 1089
 
1067 1090
 		$url = new CakeRequest('/test_plugin/tests/index');
1068  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
1069  
-		$this->assertEquals('tests', $controller->params['controller']);
1070  
-		$this->assertEquals('test_plugin', $controller->params['plugin']);
1071  
-		$this->assertEquals('index', $controller->params['action']);
1072  
-		$this->assertFalse(isset($controller->params['pass'][0]));
  1091
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
  1092
+		$this->assertEquals('tests', $Dispatcher->controller->params['controller']);
  1093
+		$this->assertEquals('test_plugin', $Dispatcher->controller->params['plugin']);
  1094
+		$this->assertEquals('index', $Dispatcher->controller->params['action']);
  1095
+		$this->assertFalse(isset($Dispatcher->controller->params['pass'][0]));
1073 1096
 
1074 1097
 		$url = new CakeRequest('/test_plugin/tests/index/some_param');
1075  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
1076  
-		$this->assertEquals('tests', $controller->params['controller']);
1077  
-		$this->assertEquals('test_plugin', $controller->params['plugin']);
1078  
-		$this->assertEquals('index', $controller->params['action']);
1079  
-		$this->assertEquals('some_param', $controller->params['pass'][0]);
  1098
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
  1099
+		$this->assertEquals('tests', $Dispatcher->controller->params['controller']);
  1100
+		$this->assertEquals('test_plugin', $Dispatcher->controller->params['plugin']);
  1101
+		$this->assertEquals('index', $Dispatcher->controller->params['action']);
  1102
+		$this->assertEquals('some_param', $Dispatcher->controller->params['pass'][0]);
1080 1103
 
1081 1104
 		App::build();
1082 1105
 	}
@@ -1095,7 +1118,7 @@ public function testAutomaticPluginControllerMissingActionDispatch() {
1095 1118
 		$url = new CakeRequest('my_plugin/not_here/param:value/param2:value2');
1096 1119
 		$response = $this->getMock('CakeResponse');
1097 1120
 
1098  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  1121
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
1099 1122
 	}
1100 1123
 
1101 1124
 /**
@@ -1113,7 +1136,7 @@ public function testAutomaticPluginControllerIndexMissingAction() {
1113 1136
 		$url = new CakeRequest('my_plugin/param:value/param2:value2');
1114 1137
 		$response = $this->getMock('CakeResponse');
1115 1138
 
1116  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  1139
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
1117 1140
 	}
1118 1141
 
1119 1142
 /**
@@ -1132,14 +1155,14 @@ public function testTestPluginDispatch() {
1132 1155
 
1133 1156
 		$url = new CakeRequest('/test_plugin/tests/index');
1134 1157
 		$response = $this->getMock('CakeResponse');
1135  
-		$result = $Dispatcher->dispatch($url, $response, array('return' => 1));
  1158
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
1136 1159
 		$this->assertTrue(class_exists('TestsController'));
1137 1160
 		$this->assertTrue(class_exists('TestPluginAppController'));
1138 1161
 		$this->assertTrue(class_exists('PluginsComponent'));
1139 1162
 
1140  
-		$this->assertEquals('tests', $result->params['controller']);
1141  
-		$this->assertEquals('test_plugin', $result->params['plugin']);
1142  
-		$this->assertEquals('index', $result->params['action']);
  1163
+		$this->assertEquals('tests', $Dispatcher->controller->params['controller']);
  1164
+		$this->assertEquals('test_plugin', $Dispatcher->controller->params['plugin']);
  1165
+		$this->assertEquals('index', $Dispatcher->controller->params['action']);
1143 1166
 
1144 1167
 		App::build();
1145 1168
 	}
@@ -1155,23 +1178,23 @@ public function testChangingParamsFromBeforeFilter() {
1155 1178
 		$url = new CakeRequest('some_posts/index/param:value/param2:value2');
1156 1179
 
1157 1180
 		try {
1158  
-			$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  1181
+			$Dispatcher->dispatch($url, $response, array('return' => 1));
1159 1182
 			$this->fail('No exception.');
1160 1183
 		} catch (MissingActionException $e) {
1161 1184
 			$this->assertEquals('Action SomePostsController::view() could not be found.', $e->getMessage());
1162 1185
 		}
1163 1186
 
1164 1187
 		$url = new CakeRequest('some_posts/something_else/param:value/param2:value2');
1165  
-		$controller = $Dispatcher->dispatch($url, $response, array('return' => 1));
  1188
+		$Dispatcher->dispatch($url, $response, array('return' => 1));
1166 1189
 
1167 1190
 		$expected = 'SomePosts';
1168  
-		$this->assertEquals($expected, $controller->name);
  1191
+		$this->assertEquals($expected, $Dispatcher->controller->name);
1169 1192
 
1170 1193
 		$expected = 'change';
1171  
-		$this->assertEquals($expected, $controller->action);
  1194
+		$this->assertEquals($expected, $Dispatcher->controller->action);
1172 1195
 
1173 1196
 		$expected = array('changed');
1174  
-		$this->assertSame($expected, $controller->params['pass']);
  1197
+		$this->assertSame($expected, $Dispatcher->controller->params['pass']);
1175 1198
 	}
1176 1199
 
1177 1200
 /**
@@ -1328,16 +1351,18 @@ public function testAsset($url, $file) {
1328 1351
  * @return void
1329 1352
  */
1330 1353
 	public function testMissingAssetProcessor404() {
1331  
-		$response = $this->getMock('CakeResponse', array('_sendHeader'));
  1354
+		$response = $this->getMock('CakeResponse', array('send'));
1332 1355
 		$Dispatcher = new TestDispatcher();
1333 1356
 		Configure::write('Asset.filter', array(
1334 1357
 			'js' => '',
1335 1358
 			'css' => null
1336 1359
 		));
1337 1360
 
1338  
-		ob_start();
1339  
-		$this->assertTrue($Dispatcher->asset('ccss/cake.generic.css', $response));
1340  
-		$result = ob_get_clean();
  1361
+		$request = new CakeRequest('ccss/cake.generic.css');
  1362
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, compact('request', 'response'));
  1363
+		$this->assertSame($response, $Dispatcher->asset($event));
  1364
+		$this->assertEquals('404', $response->statusCode());
  1365
+		$this->assertTrue($event->isStopped());
1341 1366
 	}
1342 1367
 
1343 1368
 /**
@@ -1352,17 +1377,36 @@ public function testAssetFilterForThemeAndPlugins() {
1352 1377
 			'js' => '',
1353 1378
 			'css' => ''
1354 1379
 		));
1355  
-		$this->assertTrue($Dispatcher->asset('theme/test_theme/ccss/cake.generic.css', $response));
1356  
-
1357  
-		$this->assertTrue($Dispatcher->asset('theme/test_theme/cjs/debug_kit.js', $response));
1358 1380
 
1359  
-		$this->assertTrue($Dispatcher->asset('test_plugin/ccss/cake.generic.css', $response));
1360  
-
1361  
-		$this->assertTrue($Dispatcher->asset('test_plugin/cjs/debug_kit.js', $response));
1362  
-
1363  
-		$this->assertFalse($Dispatcher->asset('css/ccss/debug_kit.css', $response));
1364  
-
1365  
-		$this->assertFalse($Dispatcher->asset('js/cjs/debug_kit.js', $response));
  1381
+		$request = new CakeRequest('theme/test_theme/ccss/cake.generic.css');
  1382
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, compact('request', 'response'));
  1383
+		$this->assertSame($response, $Dispatcher->asset($event));
  1384
+		$this->assertTrue($event->isStopped());
  1385
+
  1386
+		$request = new CakeRequest('theme/test_theme/cjs/debug_kit.js');
  1387
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, compact('request', 'response'));
  1388
+		$this->assertSame($response, $Dispatcher->asset($event));
  1389
+		$this->assertTrue($event->isStopped());
  1390
+
  1391
+		$request = new CakeRequest('test_plugin/ccss/cake.generic.css');
  1392
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, compact('request', 'response'));
  1393
+		$this->assertSame($response, $Dispatcher->asset($event));
  1394
+		$this->assertTrue($event->isStopped());
  1395
+
  1396
+		$request = new CakeRequest('test_plugin/cjs/debug_kit.js');
  1397
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, compact('request', 'response'));
  1398
+		$this->assertSame($response, $Dispatcher->asset($event));
  1399
+		$this->assertTrue($event->isStopped());
  1400
+
  1401
+		$request = new CakeRequest('css/ccss/debug_kit.css');
  1402
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, compact('request', 'response'));
  1403
+		$this->assertNull($Dispatcher->asset($event));
  1404
+		$this->assertFalse($event->isStopped());
  1405
+
  1406
+		$request = new CakeRequest('js/cjs/debug_kit.js');
  1407
+		$event = new CakeEvent('DispatcherTest', $Dispatcher, compact('request', 'response'));
  1408
+		$this->assertNull($Dispatcher->asset($event));
  1409
+		$this->assertFalse($event->isStopped());
1366 1410
 	}
1367 1411
 
1368 1412
 /**
@@ -1411,15 +1455,14 @@ public function testFullPageCachingDispatch($url) {
1411 1455
 
1412 1456
 		$dispatcher = new TestDispatcher();
1413 1457
 		$request = new CakeRequest($url);
1414  
-		$response = new CakeResponse();
  1458
+		$response = $this->getMock('CakeResponse', array('send'));
1415 1459
 
1416  
-		ob_start();
1417 1460
 		$dispatcher->dispatch($request, $response);
1418  
-		$out = ob_get_clean();
  1461
+		$out = $response->body();
1419 1462
 
1420  
-		ob_start();
1421  
-		$dispatcher->cached($request->here());
1422  
-		$cached = ob_get_clean();
  1463
+		$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request, 'response' => $response));
  1464
+		$response = $dispatcher->cached($event);
  1465
+		$cached = $response->body();
1423 1466
 
1424 1467
 		$cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
1425 1468
 
@@ -1441,16 +1484,20 @@ public function testHttpMethodOverrides() {
1441 1484
 		$_SERVER['REQUEST_METHOD'] = 'POST';
1442 1485
 		$dispatcher = new Dispatcher();
1443 1486
 
1444  
-		$result = $dispatcher->parseParams(new CakeRequest('/posts'));
  1487
+		$request = new CakeRequest('/posts');
  1488
+		$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
  1489
+		$dispatcher->parseParams($event);
1445 1490
 		$expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST');
1446 1491
 		foreach ($expected as $key => $value) {
1447  
-			$this->assertEquals($value, $result[$key], 'Value mismatch for ' . $key . ' %s');
  1492
+			$this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
1448 1493
 		}
1449 1494
 
1450 1495
 		$_SERVER['REQUEST_METHOD'] = 'GET';
1451 1496
 		$_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
1452 1497
 
1453  
-		$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
  1498
+		$request = new CakeRequest('/posts/5');
  1499
+		$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
  1500
+		$dispatcher->parseParams($event);
1454 1501
 		$expected = array(
1455 1502
 			'pass' => array('5'),
1456 1503
 			'named' => array(),
@@ -1461,24 +1508,28 @@ public function testHttpMethodOverrides() {
1461 1508
 			'[method]' => 'PUT'
1462 1509
 		);
1463 1510
 		foreach ($expected as $key => $value) {
1464  
-			$this->assertEquals($value, $result[$key], 'Value mismatch for ' . $key . ' %s');
  1511
+			$this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
1465 1512
 		}
1466 1513
 
1467 1514
 		unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
1468 1515
 		$_SERVER['REQUEST_METHOD'] = 'GET';
1469 1516
 
1470  
-		$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
  1517
+		$request = new CakeRequest('/posts/5');
  1518
+		$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
  1519
+		$dispatcher->parseParams($event);
1471 1520
 		$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET');
1472 1521
 		foreach ($expected as $key => $value) {
1473  
-			$this->assertEquals($value, $result[$key], 'Value mismatch for ' . $key . ' %s');
  1522
+			$this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
1474 1523
 		}
1475 1524
 
1476 1525
 		$_POST['_method'] = 'PUT';
1477 1526
 
1478  
-		$result = $dispatcher->parseParams(new CakeRequest('/posts/5'));
  1527
+		$request = new CakeRequest('/posts/5');
  1528
+		$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
  1529
+		$dispatcher->parseParams($event);
1479 1530
 		$expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT');
1480 1531
 		foreach ($expected as $key => $value) {
1481  
-			$this->assertEquals($value, $result[$key], 'Value mismatch for ' . $key . ' %s');
  1532
+			$this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
1482 1533
 		}
1483 1534
 
1484 1535
 		$_POST['_method'] = 'POST';
@@ -1486,13 +1537,15 @@ public function testHttpMethodOverrides() {
1486 1537
 		$_POST['extra'] = 'data';
1487 1538
 		$_SERVER = array();
1488 1539
 
1489  
-		$result = $dispatcher->parseParams(new CakeRequest('/posts'));
  1540
+		$request = new CakeRequest('/posts');
  1541
+		$event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
  1542
+		$dispatcher->parseParams($event);
1490 1543
 		$expected = array(
1491 1544
 			'pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add',
1492 1545
 			'[method]' => 'POST', 'data' => array('extra' => 'data', 'Post' => array('title' => 'New Post')),
1493 1546
 		);
1494 1547
 		foreach ($expected as $key => $value) {
1495  
-			$this->assertEquals($value, $result[$key], 'Value mismatch for ' . $key . ' %s');
  1548
+			$this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
1496 1549
 		}
1497 1550
 
1498 1551
 		unset($_POST['_method']);
3  lib/Cake/View/View.php
@@ -557,8 +557,7 @@ public function renderCache($filename, $timeStart) {
557 557
 					header('Content-type: text/xml');
558 558
 				}
559 559
 				$commentLength = strlen('<!--cachetime:' . $match['1'] . '-->');
560  
-				echo substr($out, $commentLength);
561  
-				return true;
  560
+				return substr($out, $commentLength);
562 561
 			}
563 562
 		}
564 563
 	}

0 notes on commit d17a471

Mark Story

It might be nice to move asset, and cached into dispatcher filters, and have them as 'defaults'. That would provide people with some examples of hows to use the feature, and give people the option of removing/replacing them.

Please sign in to comment.
Something went wrong with that request. Please try again.