From 88ea612a269eebf4c1a684b7b137609e91f53124 Mon Sep 17 00:00:00 2001 From: gwoo Date: Thu, 2 Aug 2007 19:12:19 +0000 Subject: [PATCH] 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 --- cake/basics.php | 2 +- cake/dispatcher.php | 41 ++++++++++++---------------- cake/tests/cases/dispatcher.test.php | 12 ++++++++ 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index c093512df..356d6be26 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -367,7 +367,7 @@ $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; } else { $name = Inflector::underscore($className); diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 59d96715b..b1b8a3135 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -407,31 +407,30 @@ class Dispatcher extends Object { $webroot = Configure::read('App.webroot'); $file = $script = null; - if (!$baseUrl && $this->base == false) { + if (!$baseUrl) { $docRoot = env('DOCUMENT_ROOT'); $script = env('SCRIPT_FILENAME'); $base = r($docRoot, '', $script); - } elseif ($baseUrl && $this->base == false) { + } elseif ($baseUrl) { $base = $baseUrl; - } - - $file = basename($base); - if ($baseUrl && strpos($file, '.php') !== false) { - $baseUrl = true; - $file = '/'. $file; + $file = '/' . basename($base); } $base = dirname($base); if (in_array($base, array(DS, '.'))) { $base = ''; + $this->webroot = '/'; + return $base . $file; } - if (!$baseUrl && strpos($script, $app) !== false && $app === 'app') { - $base = str_replace($app.'/', '', $base); + if(strpos($script, $app) !== false && $app === 'app') { + $base = str_replace('/'.$app, '', $base); } - $base = str_replace('//', '/', str_replace('/'.$webroot, '', $base)); + if ($webroot === 'webroot') { + $base = str_replace('/'.$webroot, '', $base); + } $this->webroot = $base .'/'; @@ -439,19 +438,13 @@ class Dispatcher extends Object { return $base; } - if ($baseUrl && $base == '') { - return $file; + if (strpos($this->webroot, $app) === false) { + $this->webroot .= $app . '/' ; } - if (strpos($base, $app) === false) { - $this->webroot .= '/' . $app . '/' ; - } - - if ($baseUrl && strpos($this->webroot, $webroot) === false) { + if (strpos($this->webroot, $webroot) === false) { $this->webroot .= $webroot . '/'; } - $this->webroot = str_replace('//', '/', $this->webroot); - return $base . $file; } /** @@ -480,7 +473,7 @@ class Dispatcher extends Object { * @return mixed name of controller if not loaded, or object if loaded * @access protected */ - function &__getController($params = null, $continue = true) { + function __getController($params = null, $continue = true) { if(!$params) { $params = $this->params; @@ -500,12 +493,12 @@ class Dispatcher extends Object { } if ($pluginPath . $controller && loadController($pluginPath . $controller)) { - if(!class_exists($ctrlClass) && $this->plugin) { + if(!class_exists(low($ctrlClass)) && $this->plugin) { $controller = Inflector::camelize($params['plugin']); $ctrlClass = $controller.'Controller'; $params = am($this->params, array('plugin'=> $params['plugin'], 'controller'=> $params['plugin'])); } - if(class_exists($ctrlClass)) { + if(class_exists(low($ctrlClass))) { $controller =& new $ctrlClass(); } } elseif ($continue == true){ @@ -514,7 +507,7 @@ class Dispatcher extends Object { return $controller; } - if(!class_exists($ctrlClass)) { + if(!class_exists(low($ctrlClass))) { $controller = Inflector::camelize($this->params['controller']); $this->plugin = null; return $controller; diff --git a/cake/tests/cases/dispatcher.test.php b/cake/tests/cases/dispatcher.test.php index 45235cb4d..22a7b3024 100644 --- a/cake/tests/cases/dispatcher.test.php +++ b/cake/tests/cases/dispatcher.test.php @@ -278,6 +278,18 @@ class DispatcherTest extends UnitTestCase { $this->assertEqual($expectedWebroot, $dispatcher->webroot); 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() {