Skip to content

Commit

Permalink
Merge branch 'clean-get' into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 21, 2011
2 parents 8cbd9fc + 440a890 commit 6338299
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 380 deletions.
2 changes: 1 addition & 1 deletion app/webroot/.htaccess
Expand Up @@ -2,5 +2,5 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
11 changes: 6 additions & 5 deletions app/webroot/index.php
Expand Up @@ -70,10 +70,11 @@
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {

if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/favicon.ico') {
return;
} else {
require LIBS . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest(isset($_GET['url']) ? $_GET['url'] : null));
}

require LIBS . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest());
2 changes: 1 addition & 1 deletion cake/console/templates/skel/webroot/.htaccess
Expand Up @@ -2,5 +2,5 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
11 changes: 6 additions & 5 deletions cake/console/templates/skel/webroot/index.php
Expand Up @@ -70,10 +70,11 @@
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {

if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/favicon.ico') {
return;
} else {
require LIBS . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest(isset($_GET['url']) ? $_GET['url'] : null));
}

require LIBS . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest());
98 changes: 24 additions & 74 deletions cake/libs/cake_request.php
Expand Up @@ -112,7 +112,7 @@ class CakeRequest implements ArrayAccess {
* @return void
*/
public function __construct($url = null, $parseEnvironment = true) {
$this->base = $this->_base();
$this->_base();
if (empty($url)) {
$url = $this->_url();
}
Expand Down Expand Up @@ -167,98 +167,50 @@ protected function _processGet() {
} else {
$query = $_GET;
}

if (strpos($this->url, '?') !== false) {
list(, $querystr) = explode('?', $this->url);
parse_str($querystr, $queryArgs);
$query += $queryArgs;
$query += $queryArgs;
}
if (isset($this->params['url'])) {
$query = array_merge($this->params['url'], $query);
}
$query['url'] = $this->url;
$this->query = $query;
}

/**
* Returns the REQUEST_URI from the server environment, or, failing that,
* constructs a new one, using the PHP_SELF constant and other variables.
* Get the request uri. Looks in PATH_INFO first, as this is the exact value we need prepared
* by PHP. Following that, REQUEST_URI, PHP_SELF, HTTP_X_REWRITE_URL and argv are checked in that order.
* Each of these server variables have the base path, and query strings stripped off
*
* @return string URI
* @return string URI The CakePHP request path that is being accessed.
*/
protected function _uri() {
foreach (array('HTTP_X_REWRITE_URL', 'REQUEST_URI', 'argv') as $var) {
protected function _url() {
$pathInfo = env('PATH_INFO');
if (!empty($pathInfo)) {
return $pathInfo;
}
foreach (array('PHP_SELF', 'REQUEST_URI', 'HTTP_X_REWRITE_URL', 'argv') as $var) {
if ($uri = env($var)) {
if ($var == 'argv') {
$uri = $uri[0];
$uri = $url[0];
}
break;
}
}
$base = $this->base;

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

if ($base) {
$uri = preg_replace('/^(?:\/)?(?:' . preg_quote($base, '/') . ')?(?:url=)?/', '', $uri);
}
if (PHP_SAPI == 'isapi') {
$uri = preg_replace('/^(?:\/)?(?:\/)?(?:\?)?(?:url=)?/', '', $uri);
}
if (!empty($uri)) {
if (key($_GET) && strpos(key($_GET), '?') !== false) {
unset($_GET[key($_GET)]);
}
$uri = explode('?', $uri, 2);

if (isset($uri[1])) {
parse_str($uri[1], $_GET);
}
$uri = $uri[0];
} else {
$uri = env('QUERY_STRING');
if (strpos($uri, $base) === 0) {
$uri = substr($uri, strlen($base));
}
if (is_string($uri) && strpos($uri, 'index.php') !== false) {
list(, $uri) = explode('index.php', $uri, 2);
if (strpos($uri, '?') !== false) {
$uri = parse_url($uri, PHP_URL_PATH);
}
if (empty($uri) || $uri == '/' || $uri == '//') {
return '';
return '/';
}
return str_replace('//', '/', '/' . $uri);
}

/**
* Returns and sets the $_GET[url] derived from the REQUEST_URI
*
* @return string URL
*/
protected function _url() {
if (empty($_GET['url'])) {
$uri = $this->_uri();
$base = $this->base;

$url = null;
$tmpUri = preg_replace('/^(?:\?)?(?:\/)?/', '', $uri);
$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));
}

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

/**
Expand All @@ -279,8 +231,7 @@ protected function _base() {
return $this->base = $base;
}
if (!$baseUrl) {
$replace = array('<', '>', '*', '\'', '"');
$base = str_replace($replace, '', dirname(env('PHP_SELF')));
$base = dirname(env('SCRIPT_NAME'));

if ($webroot === 'webroot' && $webroot === basename($base)) {
$base = dirname($base);
Expand All @@ -294,7 +245,7 @@ protected function _base() {
}

$this->webroot = $base .'/';
return $base;
return $this->base = $base;
}

$file = '/' . basename($baseUrl);
Expand All @@ -306,7 +257,6 @@ protected function _base() {
$this->webroot = $base . '/';

$docRoot = env('DOCUMENT_ROOT');
$script = realpath(env('SCRIPT_FILENAME'));
$docRootContainsWebroot = strpos($docRoot, $dir . '/' . $webroot);

if (!empty($base) || !$docRootContainsWebroot) {
Expand All @@ -317,7 +267,7 @@ protected function _base() {
$this->webroot .= $webroot . '/';
}
}
return $base . $file;
return $this->base = $base . $file;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cake/libs/controller/components/auth.php
Expand Up @@ -289,8 +289,8 @@ public function startup($controller) {

$url = '';

if (isset($request->query['url'])) {
$url = $request->query['url'];
if (isset($request->url)) {
$url = $request->url;
}
$url = Router::normalize($url);
$loginAction = Router::normalize($this->loginAction);
Expand Down
27 changes: 13 additions & 14 deletions cake/tests/cases/console/shells/api.test.php
Expand Up @@ -66,20 +66,19 @@ public function testMethodNameDetection () {
'8. getResponse()',
'9. header($status)',
'10. httpCodes($code = NULL)',
'11. isAuthorized()',
'12. loadModel($modelClass = NULL, $id = NULL)',
'13. paginate($object = NULL, $scope = array (), $whitelist = array ())',
'14. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)',
'15. redirect($url, $status = NULL, $exit = true)',
'16. referer($default = NULL, $local = false)',
'17. render($action = NULL, $layout = NULL, $file = NULL)',
'18. set($one, $two = NULL)',
'19. setAction($action)',
'20. setRequest($request)',
'21. shutdownProcess()',
'22. startupProcess()',
'23. validate()',
'24. validateErrors()'
'11. loadModel($modelClass = NULL, $id = NULL)',
'12. paginate($object = NULL, $scope = array (), $whitelist = array ())',
'13. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)',
'14. redirect($url, $status = NULL, $exit = true)',
'15. referer($default = NULL, $local = false)',
'16. render($view = NULL, $layout = NULL)',
'17. set($one, $two = NULL)',
'18. setAction($action)',
'19. setRequest($request)',
'20. shutdownProcess()',
'21. startupProcess()',
'22. validate()',
'23. validateErrors()'
);
$this->Shell->expects($this->at(2))->method('out')->with($expected);

Expand Down

0 comments on commit 6338299

Please sign in to comment.