Skip to content
Permalink
Browse files

Making Router::setRequestInfo() able to accept arrays. It will conver…

…t older style arrays into a CakeRequest object for later use.

Updating uses of Router::setRequestInfo() to just pass the object where possible.
  • Loading branch information...
markstory committed May 2, 2010
1 parent e336df6 commit 26279851e15a10f0021500e7690edb057a220c5f
@@ -116,9 +116,7 @@ public function dispatch($url = null, $additionalParams = array()) {
$controller = $this->_getController();
if (!is_object($controller)) {
Router::setRequestInfo(array(
$this->params, array('base' => $request->base, 'webroot' => $request->webroot)
));
Router::setRequestInfo($request);
return $this->cakeError('missingController', array(array(
'className' => Inflector::camelize($request->params['controller']) . 'Controller',
'webroot' => $request->webroot,
@@ -594,9 +594,17 @@ function __connectDefaultRoutes() {
* @param array $params Parameters and path information
* @return void
*/
public static function setRequestInfo(CakeRequest $request) {
public static function setRequestInfo($request) {
$self = Router::getInstance();
$self->__params[] = $request;
if ($request instanceof CakeRequest) {
$self->__params[] = $request;
} else {
$requestObj = new CakeRequest();
$request += array(array(), array());
$request[0] += array('controller' => false, 'action' => false, 'plugin' => null);
$requestObj->addParams($request[0])->addPaths($request[1]);
$self->__params[] = $requestObj;
}
}
/**
@@ -622,10 +630,10 @@ public static function getRequest($current = false) {
public static function getParams($current = false) {
$self = Router::getInstance();
if ($current) {
return $self->__params[count($self->__params) - 1];
return $self->__params[count($self->__params) - 1]->params;
}
if (isset($self->__params[0])) {
return $self->__params[0];
return $self->__params[0]->params;
}
return array();
}
@@ -234,7 +234,7 @@ function __writeFile($content, $timestamp, $useCallbacks = false) {
$controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\');
$controller->data = $this->data = unserialize(\'' . str_replace("'", "\\'", serialize($this->data)) . '\');
$controller->theme = $this->theme = \'' . $this->theme . '\';
Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));';
Router::setRequestInfo($this->params);';
if ($useCallbacks == true) {
$file .= '
@@ -1189,7 +1189,7 @@ public function testTestPluginDispatch() {
));
App::objects('plugin', null, false);
Router::reload();
Router::parse(new CakeRequest('/'));
Router::parse('/');
$url = '/test_plugin/tests/index';
$result = $Dispatcher->dispatch($url, array('return' => 1));
@@ -1940,22 +1940,23 @@ public function testGetParams() {
$paths = array('base' => '/', 'here' => '/products/display/5', 'webroot' => '/webroot');
$params = array('param1' => '1', 'param2' => '2');
Router::setRequestInfo(array($params, $paths));
$expected = array(
'plugin' => null, 'controller' => false, 'action' => false,
'param1' => '1', 'param2' => '2'
'param1' => '1', 'param2' => '2', 'form' => array()
);
$this->assertEqual(Router::getparams(), $expected);
$this->assertEqual(Router::getparam('controller'), false);
$this->assertEqual(Router::getparam('param1'), '1');
$this->assertEqual(Router::getparam('param2'), '2');
$this->assertEqual(Router::getParams(), $expected);
$this->assertEqual(Router::getParam('controller'), false);
$this->assertEqual(Router::getParam('param1'), '1');
$this->assertEqual(Router::getParam('param2'), '2');
Router::reload();
$params = array('controller' => 'pages', 'action' => 'display');
Router::setRequestInfo(array($params, $paths));
$expected = array('plugin' => null, 'controller' => 'pages', 'action' => 'display');
$this->assertEqual(Router::getparams(), $expected);
$this->assertEqual(Router::getparams(true), $expected);
$expected = array('plugin' => null, 'controller' => 'pages', 'action' => 'display', 'form' => array());
$this->assertEqual(Router::getParams(), $expected);
$this->assertEqual(Router::getParams(true), $expected);
}
/**

0 comments on commit 2627985

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