adding fix to Dispatcher for tclineks wacky webroot, fixing failing dispatcher tests on php4

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5479 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-08-02 19:12:19 +00:00
parent de4d316d4d
commit 88ea612a26
3 changed files with 30 additions and 25 deletions

View file

@ -367,7 +367,7 @@
$className = $name . 'Controller'; $className = $name . 'Controller';
if (class_exists($className) && get_parent_class($className) == $parent) { if (class_exists(low($className)) && low(get_parent_class($className)) == low($parent)) {
return true; return true;
} else { } else {
$name = Inflector::underscore($className); $name = Inflector::underscore($className);

View file

@ -407,31 +407,30 @@ class Dispatcher extends Object {
$webroot = Configure::read('App.webroot'); $webroot = Configure::read('App.webroot');
$file = $script = null; $file = $script = null;
if (!$baseUrl && $this->base == false) { if (!$baseUrl) {
$docRoot = env('DOCUMENT_ROOT'); $docRoot = env('DOCUMENT_ROOT');
$script = env('SCRIPT_FILENAME'); $script = env('SCRIPT_FILENAME');
$base = r($docRoot, '', $script); $base = r($docRoot, '', $script);
} elseif ($baseUrl && $this->base == false) { } elseif ($baseUrl) {
$base = $baseUrl; $base = $baseUrl;
} $file = '/' . basename($base);
$file = basename($base);
if ($baseUrl && strpos($file, '.php') !== false) {
$baseUrl = true;
$file = '/'. $file;
} }
$base = dirname($base); $base = dirname($base);
if (in_array($base, array(DS, '.'))) { if (in_array($base, array(DS, '.'))) {
$base = ''; $base = '';
$this->webroot = '/';
return $base . $file;
} }
if (!$baseUrl && strpos($script, $app) !== false && $app === 'app') { if(strpos($script, $app) !== false && $app === 'app') {
$base = str_replace($app.'/', '', $base); $base = str_replace('/'.$app, '', $base);
} }
$base = str_replace('//', '/', str_replace('/'.$webroot, '', $base)); if ($webroot === 'webroot') {
$base = str_replace('/'.$webroot, '', $base);
}
$this->webroot = $base .'/'; $this->webroot = $base .'/';
@ -439,19 +438,13 @@ class Dispatcher extends Object {
return $base; return $base;
} }
if ($baseUrl && $base == '') { if (strpos($this->webroot, $app) === false) {
return $file; $this->webroot .= $app . '/' ;
} }
if (strpos($base, $app) === false) { if (strpos($this->webroot, $webroot) === false) {
$this->webroot .= '/' . $app . '/' ;
}
if ($baseUrl && strpos($this->webroot, $webroot) === false) {
$this->webroot .= $webroot . '/'; $this->webroot .= $webroot . '/';
} }
$this->webroot = str_replace('//', '/', $this->webroot);
return $base . $file; return $base . $file;
} }
/** /**
@ -480,7 +473,7 @@ class Dispatcher extends Object {
* @return mixed name of controller if not loaded, or object if loaded * @return mixed name of controller if not loaded, or object if loaded
* @access protected * @access protected
*/ */
function &__getController($params = null, $continue = true) { function __getController($params = null, $continue = true) {
if(!$params) { if(!$params) {
$params = $this->params; $params = $this->params;
@ -500,12 +493,12 @@ class Dispatcher extends Object {
} }
if ($pluginPath . $controller && loadController($pluginPath . $controller)) { if ($pluginPath . $controller && loadController($pluginPath . $controller)) {
if(!class_exists($ctrlClass) && $this->plugin) { if(!class_exists(low($ctrlClass)) && $this->plugin) {
$controller = Inflector::camelize($params['plugin']); $controller = Inflector::camelize($params['plugin']);
$ctrlClass = $controller.'Controller'; $ctrlClass = $controller.'Controller';
$params = am($this->params, array('plugin'=> $params['plugin'], 'controller'=> $params['plugin'])); $params = am($this->params, array('plugin'=> $params['plugin'], 'controller'=> $params['plugin']));
} }
if(class_exists($ctrlClass)) { if(class_exists(low($ctrlClass))) {
$controller =& new $ctrlClass(); $controller =& new $ctrlClass();
} }
} elseif ($continue == true){ } elseif ($continue == true){
@ -514,7 +507,7 @@ class Dispatcher extends Object {
return $controller; return $controller;
} }
if(!class_exists($ctrlClass)) { if(!class_exists(low($ctrlClass))) {
$controller = Inflector::camelize($this->params['controller']); $controller = Inflector::camelize($this->params['controller']);
$this->plugin = null; $this->plugin = null;
return $controller; return $controller;

View file

@ -278,6 +278,18 @@ class DispatcherTest extends UnitTestCase {
$this->assertEqual($expectedWebroot, $dispatcher->webroot); $this->assertEqual($expectedWebroot, $dispatcher->webroot);
Configure::write('App.base', false); Configure::write('App.base', false);
Configure::write('App.dir', 'affiliate');
Configure::write('App.webroot', 'newaffiliate');
$_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/abtravaff/html/newaffiliate/index.php';
$dispatcher =& new Dispatcher();
$result = $dispatcher->baseUrl();
$expected = '/newaffiliate';
$this->assertEqual($expected, $result);
$expectedWebroot = '/newaffiliate/';
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
} }
function testBaseUrlAndWebrootWithBaseUrl() { function testBaseUrlAndWebrootWithBaseUrl() {