Skip to content

Commit

Permalink
Removing duplicated code and moving methods to protected.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed May 1, 2010
1 parent 4deacf0 commit 1b5c0cc
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions cake/libs/cake_request.php
Expand Up @@ -59,7 +59,7 @@ class CakeRequest implements ArrayAccess {
public $base = false;

/**
* webroot directory for the request.
* webroot path segment for the request.
*
* @var string
*/
Expand Down Expand Up @@ -175,7 +175,7 @@ public function uri() {
}
}

$base = preg_replace('/^\//', '', '' . Configure::read('App.baseUrl'));
$base = trim(Configure::read('App.baseUrl'), '/');

if ($base) {
$uri = preg_replace('/^(?:\/)?(?:' . preg_quote($base, '/') . ')?(?:url=)?/', '', $uri);
Expand Down Expand Up @@ -208,42 +208,32 @@ public function uri() {
/**
* Returns and sets the $_GET[url] derived from the REQUEST_URI
*
* @param string $uri Request URI
* @param string $base Base path
* @return string URL
*/
public function _url($uri = null, $base = null) {
protected function _url() {
if (empty($_GET['url'])) {
if ($uri == null) {
$uri = $this->uri();
}
if ($base == null) {
$base = $this->base;
}
$uri = $this->uri();
$base = $this->base;

$url = null;
$tmpUri = preg_replace('/^(?:\?)?(?:\/)?/', '', $uri);
$baseDir = preg_replace('/^\//', '', dirname($base)) . '/';
$baseDir = trim(dirname($base) . '/', '/');

if ($tmpUri === '/' || $tmpUri == $baseDir || $tmpUri == $base) {
$url = '/';
} else {
$elements = array();
if ($base && strpos($uri, $base) !== false) {
$elements = explode($base, $uri);
} elseif (preg_match('/^[\/\?\/|\/\?|\?\/]/', $uri)) {
$elements = array(1 => preg_replace('/^[\/\?\/|\/\?|\?\/]/', '', $uri));
} else {
$elements = array();
}

if (!empty($elements[1])) {
$url = $elements[1];
} else {
$url = '/';
}

if (strpos($url, '/') === 0 && $url != '/') {
$url = substr($url, 1);
}
}
} else {
$url = $_GET['url'];
Expand All @@ -259,7 +249,7 @@ public function _url($uri = null, $base = null) {
*
* @return string Base URL
*/
public function _base() {
protected function _base() {
$dir = $webroot = null;
$config = Configure::read('App');
extract($config);
Expand All @@ -270,7 +260,7 @@ public function _base() {

if ($base !== false) {
$this->webroot = $base . '/';
return $this->base = $base;
return $base;
}
if (!$baseUrl) {
$replace = array('<', '>', '*', '\'', '"');
Expand Down

0 comments on commit 1b5c0cc

Please sign in to comment.