Skip to content
Permalink
Browse files

Updating some uses of Router::setRequestInfo().

  • Loading branch information...
markstory committed May 2, 2010
1 parent 9a18583 commit e336df6de844225a8ab1d44ff9f19aa439767886
Showing with 263 additions and 178 deletions.
  1. +1 −3 cake/dispatcher.php
  2. +33 −34 cake/libs/router.php
  3. +229 −141 cake/tests/cases/libs/router.test.php
@@ -138,9 +138,7 @@ public function dispatch($url = null, $additionalParams = array()) {
}
}
Router::setRequestInfo(array(
$request->params, array('base' => $request->base, 'here' => $request->here, 'webroot' => $request->webroot)
));
Router::setRequestInfo($request);
if ($privateAction) {
return $this->cakeError('privateAction', array(array(
@@ -594,20 +594,23 @@ function __connectDefaultRoutes() {
* @param array $params Parameters and path information
* @return void
*/
public static function setRequestInfo($params) {
$self =& Router::getInstance();
$defaults = array('plugin' => null, 'controller' => null, 'action' => null);
$params[0] = array_merge($defaults, (array)$params[0]);
$params[1] = array_merge($defaults, (array)$params[1]);
list($self->__params[], $self->__paths[]) = $params;
if (count($self->__paths)) {
if (isset($self->__paths[0]['namedArgs'])) {
foreach ($self->__paths[0]['namedArgs'] as $arg => $value) {
$self->named['rules'][$arg] = true;
}
}
public static function setRequestInfo(CakeRequest $request) {
$self = Router::getInstance();
$self->__params[] = $request;
}
/**
* Get the either the current request object, or the first one.
*
* @param boolean $current Whether you want the request from the top of the stack or the first one.
* @return CakeRequest or null.
*/
public static function getRequest($current = false) {
$self = Router::getInstance();
if ($current) {
return $self->__params[count($self->__params) - 1];
}
return isset($self->__params[0]) ? $self->__params[0] : null;
}
/**
@@ -617,7 +620,7 @@ public static function setRequestInfo($params) {
* @return array Parameter information
*/
public static function getParams($current = false) {
$self =& Router::getInstance();
$self = Router::getInstance();
if ($current) {
return $self->__params[count($self->__params) - 1];
}
@@ -649,14 +652,14 @@ public static function getParam($name = 'controller', $current = false) {
* @return array
*/
public static function getPaths($current = false) {
$self =& Router::getInstance();
$self = Router::getInstance();
if ($current) {
return $self->__paths[count($self->__paths) - 1];
return $self->__params[count($self->__params) - 1];
}
if (!isset($self->__paths[0])) {
if (!isset($self->__params[0])) {
return array('base' => null);
}
return $self->__paths[0];
return array('base' => $self->__params[0]->base);
}
/**
@@ -666,7 +669,7 @@ public static function getPaths($current = false) {
* @return void
*/
public static function reload() {
$self =& Router::getInstance();
$self = Router::getInstance();
foreach (get_class_vars('Router') as $key => $val) {
$self->{$key} = $val;
}
@@ -681,7 +684,7 @@ public static function reload() {
* @return boolean Retuns false if no route exists at the position specified by $which.
*/
public static function promote($which = null) {
$self =& Router::getInstance();
$self = Router::getInstance();
if ($which === null) {
$which = count($self->routes) - 1;
}
@@ -724,7 +727,7 @@ public static function promote($which = null) {
* @return string Full translated URL with base path.
*/
public static function url($url = null, $full = false) {
$self =& Router::getInstance();
$self = Router::getInstance();
$defaults = $params = array('plugin' => null, 'controller' => null, 'action' => 'index');
if (is_bool($full)) {
@@ -733,22 +736,18 @@ public static function url($url = null, $full = false) {
extract($full + array('escape' => false, 'full' => false));
}
$path = array('base' => null);
if (!empty($self->__params)) {
// bad hack for detecting if doing a request action.
if (isset($this) && !isset($this->params['requested'])) {
$params = $self->__params[0];
$request = $self->__params[0];
} else {
$params = end($self->__params);
$request = end($self->__params);
}
$params = $request->params;
$path = array('base' => $request->base, 'here' => $request->here);
}
$path = array('base' => null);
if (!empty($self->__paths)) {
if (isset($this) && !isset($this->params['requested'])) {
$path = $self->__paths[0];
} else {
$path = end($self->__paths);
}
}
$base = $path['base'];
$extension = $output = $mapped = $q = $frag = null;
@@ -1038,10 +1037,10 @@ public static function normalize($url = '/') {
} elseif (preg_match('/^[a-z\-]+:\/\//', $url)) {
return $url;
}
$paths = Router::getPaths();
$request = Router::getRequest();
if (!empty($paths['base']) && stristr($url, $paths['base'])) {
$url = preg_replace('/^' . preg_quote($paths['base'], '/') . '/', '', $url, 1);
if (!empty($request->base) && stristr($url, $request->base)) {
$url = preg_replace('/^' . preg_quote($request->base, '/') . '/', '', $url, 1);
}
$url = '/' . $url;
Oops, something went wrong.

0 comments on commit e336df6

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