Browse Source

Fix issue in RequestHandlerComponent.

Fixes issues where response and request properties would
not be set as the initialize() callback would have not fired.

Fixes #2190
Fixes #2189
mark_story 14 years ago
parent
commit
550076d75e

+ 5 - 3
lib/Cake/Controller/Component/RequestHandlerComponent.php

@@ -91,8 +91,12 @@ class RequestHandlerComponent extends Component {
  * @param array $settings Array of settings.
  */
 	public function __construct(ComponentCollection $collection, $settings = array()) {
-		$this->addInputType('xml', array(array($this, 'convertXml')));
 		parent::__construct($collection, $settings);
+		$this->addInputType('xml', array(array($this, 'convertXml')));
+
+		$Controller = $collection->getController();
+		$this->request = $Controller->request;
+		$this->response = $Controller->response;
 	}
 
 /**
@@ -107,8 +111,6 @@ class RequestHandlerComponent extends Component {
  * @see Router::parseExtensions()
  */
 	public function initialize($controller, $settings = array()) {
-		$this->request = $controller->request;
-		$this->response = $controller->response;
 		if (isset($this->request->params['ext'])) {
 			$this->ext = $this->request->params['ext'];
 		}

+ 2 - 9
lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php

@@ -30,13 +30,6 @@ App::uses('Router', 'Routing');
 class RequestHandlerTestController extends Controller {
 
 /**
- * name property
- *
- * @var string
- */
-	public $name = 'RequestHandlerTest';
-
-/**
  * uses property
  *
  * @var mixed null
@@ -117,9 +110,8 @@ class RequestHandlerComponentTest extends CakeTestCase {
 		$request = new CakeRequest('controller_posts/index');
 		$response = new CakeResponse();
 		$this->Controller = new RequestHandlerTestController($request, $response);
+		$this->Controller->constructClasses();
 		$this->RequestHandler = new RequestHandlerComponent($this->Controller->Components);
-		$this->RequestHandler->request = $request;
-		$this->RequestHandler->response = $response;
 		$this->_extensions = Router::extensions();
 	}
 
@@ -148,6 +140,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
 			'ajaxLayout' => 'test_ajax'
 		);
 		$Collection = new ComponentCollection();
+		$Collection->init($this->Controller);
 		$RequestHandler = new RequestHandlerComponent($Collection, $settings);
 		$this->assertEqual($RequestHandler->ajaxLayout, 'test_ajax');
 	}