updating dispatcher to fix cached css/js, changed baseUrl and updated tests

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5496 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-08-06 15:09:51 +00:00
parent efd66066f6
commit b91b501314
2 changed files with 38 additions and 38 deletions

View file

@ -127,7 +127,7 @@ class Dispatcher extends Object {
$this->here = $this->base . '/' . $url;
$this->cached();
$this->cached($url);
$this->params = array_merge($this->parseParams($url), $additionalParams);
@ -414,15 +414,11 @@ class Dispatcher extends Object {
$this->webroot = '/';
$config = Configure::read('App');
$baseUrl = $config['baseUrl'];
$app = $config['dir'];
$webroot = $config['webroot'];
extract($config);
$file = $script = null;
$file = null;
if (!$baseUrl) {
$docRoot = env('DOCUMENT_ROOT');
$script = env('SCRIPT_FILENAME');
$base = r($docRoot, '', $script);
$base = env('PHP_SELF');
} elseif ($baseUrl) {
$base = $baseUrl;
$file = '/' . basename($base);
@ -432,21 +428,26 @@ class Dispatcher extends Object {
if (in_array($base, array(DS, '.'))) {
$base = '';
}
if(strpos($script, $app) !== false && $app === 'app') {
$base = str_replace('/'.$app, '', $base);
}
if (!$baseUrl && $webroot === 'webroot') {
$base = str_replace('/'.$webroot, '', $base);
if(!$baseUrl) {
if($base == '') {
$this->webroot = '/';
return $base;
}
if($dir === 'app') {
$base = str_replace('/app', '', $base);
}
if ($webroot === 'webroot') {
$base = str_replace('/webroot', '', $base);
}
$this->webroot = $base .'/';
return $base;
}
$this->webroot = $base .'/';
if (!$baseUrl) {
return $base;
}
if (strpos($this->webroot, $app) === false) {
$this->webroot .= $app . '/' ;
if (strpos($this->webroot, $dir) === false) {
$this->webroot .= $dir . '/' ;
}
if (strpos($this->webroot, $webroot) === false) {
$this->webroot .= $webroot . '/';
@ -604,17 +605,15 @@ class Dispatcher extends Object {
* @param string $url
* @return string URL
*/
function cached($uri = null) {
if($uri == null) {
$uri = $this->here;
}
if (strpos($uri, 'ccss/') === 0) {
function cached($url) {
if (strpos($url, 'ccss/') === 0) {
include WWW_ROOT . DS . 'css.php';
exit();
}
$folders = array('js' => 'text/javascript', 'css' => 'text/css');
$requestPath = explode('/', $uri);
$requestPath = explode('/', $url);
if (in_array($requestPath[0], array_keys($folders))) {
if (file_exists(VENDORS . join(DS, $requestPath))) {
@ -625,9 +624,9 @@ class Dispatcher extends Object {
}
if (defined('CACHE_CHECK') && CACHE_CHECK === true) {
$filename = CACHE . 'views' . DS . convertSlash($uri) . '.php';
$filename = CACHE . 'views' . DS . convertSlash($url) . '.php';
if (!file_exists($filename)) {
$filename = CACHE . 'views' . DS . convertSlash($uri) . '_index.php';
$filename = CACHE . 'views' . DS . convertSlash($url) . '_index.php';
}
if (file_exists($filename)) {
uses('controller' . DS . 'component', DS . 'view' . DS . 'view');

View file

@ -36,7 +36,7 @@ class TestDispatcher extends Dispatcher {
$classVars = get_object_vars($controller);
if ($missingAction && in_array('scaffold', array_keys($classVars))) {
uses('controller'. DS . 'scaffold');
return new Scaffold($controller, $params);
} elseif ($missingAction && !in_array('scaffold', array_keys($classVars))) {
return $this->cakeError('missingAction', array(
@ -228,6 +228,7 @@ class DispatcherTest extends UnitTestCase {
$dispatcher->base = false;
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
$_SERVER['PHP_SELF'] = '/1.2.x.x/app/webroot/index.php';
$result = $dispatcher->baseUrl();
$expected = '/1.2.x.x';
$this->assertEqual($expected, $result);
@ -237,6 +238,7 @@ class DispatcherTest extends UnitTestCase {
$dispatcher->base = false;
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/app/webroot';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
$_SERVER['PHP_SELF'] = '/index.php';
$result = $dispatcher->baseUrl();
$expected = '';
$this->assertEqual($expected, $result);
@ -249,6 +251,8 @@ class DispatcherTest extends UnitTestCase {
$dispatcher->base = false;;
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/demos/auth/webroot/index.php';
$_SERVER['PHP_SELF'] = '/demos/auth/webroot/index.php';
$result = $dispatcher->baseUrl();
$expected = '/demos/auth';
$this->assertEqual($expected, $result);
@ -260,6 +264,7 @@ class DispatcherTest extends UnitTestCase {
$dispatcher->base = false;;
$_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents';
$_SERVER['SCRIPT_FILENAME'] = '/Library/WebServer/Documents/clients/PewterReport/code/webroot/index.php';
$_SERVER['PHP_SELF'] = '/clients/PewterReport/code/webroot/index.php';
$result = $dispatcher->baseUrl();
$expected = '/clients/PewterReport/code';
$this->assertEqual($expected, $result);
@ -271,7 +276,7 @@ class DispatcherTest extends UnitTestCase {
function testBaseUrlwithModRewriteAlias() {
$_SERVER['DOCUMENT_ROOT'] = '/home/aplusnur/public_html';
$_SERVER['SCRIPT_FILENAME'] = '/home/aplusnur/cake2/app/webroot/index.php';
$_SERVER['SCRIPT_NAME'] = '/control/index.php';
$_SERVER['PHP_SELF'] = '/control/index.php';
Configure::write('App.base', '/control');
@ -288,7 +293,7 @@ class DispatcherTest extends UnitTestCase {
$_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php';
$_SERVER['PHP_SELF'] = '/newaffiliate/index.php';
$dispatcher =& new Dispatcher();
$result = $dispatcher->baseUrl();
$expected = '/newaffiliate';
@ -476,8 +481,7 @@ class DispatcherTest extends UnitTestCase {
function testPluginDispatch() {
$_POST = array();
$_SERVER['DOCUMENT_ROOT'] = '';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
Router::reload();
$dispatcher =& new TestDispatcher();
@ -521,8 +525,7 @@ class DispatcherTest extends UnitTestCase {
function testAutomaticPluginDispatch() {
$_POST = array();
$_SERVER['DOCUMENT_ROOT'] = '';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
Router::reload();
$dispatcher =& new TestDispatcher();
@ -555,8 +558,7 @@ class DispatcherTest extends UnitTestCase {
function testAutomaticPluginControllerDispatch() {
$_POST = array();
$_SERVER['DOCUMENT_ROOT'] = '';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
Router::reload();
$dispatcher =& new TestDispatcher();
@ -580,8 +582,7 @@ class DispatcherTest extends UnitTestCase {
function testAutomaticPluginControllerMissingActionDispatch() {
$_POST = array();
$_SERVER['DOCUMENT_ROOT'] = '';
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
Router::reload();
$dispatcher =& new TestDispatcher();