mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
updating Dispatcher with changes for base. Allows setting Configure::write('App.base', '/my/base/path'); in bootstrap.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5478 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
32fef5ada3
commit
de4d316d4d
5 changed files with 66 additions and 42 deletions
|
@ -75,7 +75,6 @@ if (empty( $_GET['output'])) {
|
|||
}
|
||||
|
||||
$dispatch =& new Dispatcher();
|
||||
$dispatch->base = env('SCRIPT_NAME');
|
||||
$dispatch->baseUrl();
|
||||
define('BASE', $dispatch->webroot);
|
||||
|
||||
|
|
|
@ -75,7 +75,6 @@ if (empty( $_GET['output'])) {
|
|||
}
|
||||
|
||||
$dispatch =& new Dispatcher();
|
||||
$dispatch->base = env('SCRIPT_NAME');
|
||||
$dispatch->baseUrl();
|
||||
define('BASE', $dispatch->webroot);
|
||||
|
||||
|
|
|
@ -86,8 +86,15 @@ class Dispatcher extends Object {
|
|||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function __construct($url = null) {
|
||||
function __construct($url = null, $base = false) {
|
||||
parent::__construct();
|
||||
|
||||
if($base !== false) {
|
||||
Configure::write('App.base', $base);
|
||||
}
|
||||
|
||||
$this->base = Configure::read('App.base');
|
||||
|
||||
if ($url !== null) {
|
||||
return $this->dispatch($url);
|
||||
}
|
||||
|
@ -213,6 +220,7 @@ class Dispatcher extends Object {
|
|||
array_push($controller->components, $controller->webservices);
|
||||
array_push($controller->helpers, $controller->webservices);
|
||||
}
|
||||
|
||||
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot, 'passedArgs' => $controller->passedArgs, 'argSeparator' => $controller->argSeparator, 'namedArgs' => $controller->namedArgs, 'webservices' => $controller->webservices)));
|
||||
$controller->_initComponents();
|
||||
|
||||
|
@ -386,12 +394,17 @@ class Dispatcher extends Object {
|
|||
* @access public
|
||||
*/
|
||||
function baseUrl() {
|
||||
$base = $this->base;
|
||||
if($this->base !== false) {
|
||||
$this->webroot = $this->base .'/';
|
||||
return $this->base;
|
||||
}
|
||||
|
||||
$base = '';
|
||||
$this->webroot = '/';
|
||||
|
||||
$baseUrl = Configure::read('baseUrl');
|
||||
$app = Configure::read('app');
|
||||
$webroot = Configure::read('webroot');
|
||||
$baseUrl = Configure::read('App.baseUrl');
|
||||
$app = Configure::read('App.dir');
|
||||
$webroot = Configure::read('App.webroot');
|
||||
|
||||
$file = $script = null;
|
||||
if (!$baseUrl && $this->base == false) {
|
||||
|
@ -403,14 +416,14 @@ class Dispatcher extends Object {
|
|||
}
|
||||
|
||||
$file = basename($base);
|
||||
if (($baseUrl || $this->base) && strpos($file, '.php') !== false) {
|
||||
if ($baseUrl && strpos($file, '.php') !== false) {
|
||||
$baseUrl = true;
|
||||
$file = '/'. $file;
|
||||
}
|
||||
|
||||
$base = dirname($base);
|
||||
|
||||
if ($base == '/' || $base == '.') {
|
||||
if (in_array($base, array(DS, '.'))) {
|
||||
$base = '';
|
||||
}
|
||||
|
||||
|
@ -467,7 +480,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;
|
||||
|
@ -485,6 +498,7 @@ class Dispatcher extends Object {
|
|||
$pluginPath = Inflector::camelize($this->plugin).'.';
|
||||
|
||||
}
|
||||
|
||||
if ($pluginPath . $controller && loadController($pluginPath . $controller)) {
|
||||
if(!class_exists($ctrlClass) && $this->plugin) {
|
||||
$controller = Inflector::camelize($params['plugin']);
|
||||
|
@ -500,8 +514,8 @@ class Dispatcher extends Object {
|
|||
return $controller;
|
||||
}
|
||||
|
||||
if(!$ctrlClass) {
|
||||
$controller = Inflector::camelize($this->plugin);
|
||||
if(!class_exists($ctrlClass)) {
|
||||
$controller = Inflector::camelize($this->params['controller']);
|
||||
$this->plugin = null;
|
||||
return $controller;
|
||||
}
|
||||
|
|
|
@ -435,6 +435,11 @@ class Configure extends Object {
|
|||
*/
|
||||
function __loadBootstrap($boot) {
|
||||
$_this =& Configure::getInstance();
|
||||
$baseUrl = false;
|
||||
if (defined('BASE_URL')) {
|
||||
$baseUrl = BASE_URL;
|
||||
}
|
||||
$_this->write('App', array('base'=> false, 'baseUrl'=> $baseUrl, 'dir'=> APP_DIR, 'webroot'=> WEBROOT_DIR));
|
||||
$modelPaths = null;
|
||||
$viewPaths = null;
|
||||
$controllerPaths = null;
|
||||
|
@ -452,14 +457,6 @@ class Configure extends Object {
|
|||
$_this->__buildHelperPaths($helperPaths);
|
||||
$_this->__buildComponentPaths($componentPaths);
|
||||
$_this->__buildBehaviorPaths($behaviorPaths);
|
||||
|
||||
$_this->write('app', APP_DIR);
|
||||
$_this->write('webroot', WEBROOT_DIR);
|
||||
$baseUrl = false;
|
||||
if (defined('BASE_URL')) {
|
||||
$baseUrl = BASE_URL;
|
||||
}
|
||||
$_this->write('baseUrl', $baseUrl);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -127,9 +127,9 @@ class DispatcherTest extends UnitTestCase {
|
|||
function setUp() {
|
||||
$this->_get = $_GET;
|
||||
$_GET = array();
|
||||
Configure::write('baseUrl', false);
|
||||
Configure::write('app', 'app');
|
||||
Configure::write('webroot', 'webroot');
|
||||
Configure::write('App.baseUrl', false);
|
||||
Configure::write('App.dir', 'app');
|
||||
Configure::write('App.webroot', 'webroot');
|
||||
|
||||
}
|
||||
|
||||
|
@ -218,9 +218,7 @@ class DispatcherTest extends UnitTestCase {
|
|||
function testBaseUrlAndWebrootWithModRewrite() {
|
||||
$dispatcher =& new Dispatcher();
|
||||
|
||||
Configure::write('app', 'app');
|
||||
Configure::write('webroot', 'webroot');
|
||||
Configure::write('baseUrl', false);
|
||||
Configure::write('App.baseUrl', false);
|
||||
|
||||
$dispatcher->base = false;
|
||||
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
|
||||
|
@ -241,7 +239,7 @@ class DispatcherTest extends UnitTestCase {
|
|||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
|
||||
Configure::write('app', 'auth');
|
||||
Configure::write('App.dir', 'auth');
|
||||
|
||||
$dispatcher->base = false;;
|
||||
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
|
||||
|
@ -252,7 +250,7 @@ class DispatcherTest extends UnitTestCase {
|
|||
$expectedWebroot = '/demos/auth/';
|
||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
Configure::write('app', 'code');
|
||||
Configure::write('App.dir', 'code');
|
||||
|
||||
$dispatcher->base = false;;
|
||||
$_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents';
|
||||
|
@ -265,47 +263,64 @@ 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';
|
||||
|
||||
Configure::write('App.base', '/control');
|
||||
|
||||
$dispatcher =& new Dispatcher();
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '/control';
|
||||
$this->assertEqual($expected, $result);
|
||||
$expectedWebroot = '/control/';
|
||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
Configure::write('App.base', false);
|
||||
}
|
||||
|
||||
function testBaseUrlAndWebrootWithBaseUrl() {
|
||||
$dispatcher =& new Dispatcher();
|
||||
|
||||
Configure::write('app', 'app');
|
||||
Configure::write('App.dir', 'app');
|
||||
|
||||
Configure::write('baseUrl', '/app/webroot/index.php');
|
||||
Configure::write('App.baseUrl', '/app/webroot/index.php');
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '/app/index.php';
|
||||
$this->assertEqual($expected, $result);
|
||||
$expectedWebroot = '/app/webroot/';
|
||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
Configure::write('baseUrl', '/app/webroot/test.php');
|
||||
Configure::write('App.baseUrl', '/app/webroot/test.php');
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '/app/test.php';
|
||||
$this->assertEqual($expected, $result);
|
||||
$expectedWebroot = '/app/webroot/';
|
||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
Configure::write('baseUrl', '/app/index.php');
|
||||
Configure::write('App.baseUrl', '/app/index.php');
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '/app/index.php';
|
||||
$this->assertEqual($expected, $result);
|
||||
$expectedWebroot = '/app/webroot/';
|
||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
Configure::write('baseUrl', '/index.php');
|
||||
Configure::write('App.baseUrl', '/index.php');
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '/index.php';
|
||||
$this->assertEqual($expected, $result);
|
||||
$expectedWebroot = '/';
|
||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
Configure::write('baseUrl', '/CakeBB/app/webroot/index.php');
|
||||
Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '/CakeBB/app/index.php';
|
||||
$this->assertEqual($expected, $result);
|
||||
$expectedWebroot = '/CakeBB/app/webroot/';
|
||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
Configure::write('baseUrl', '/CakeBB/app/index.php');
|
||||
Configure::write('App.baseUrl', '/CakeBB/app/index.php');
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '/CakeBB/app/index.php';
|
||||
$this->assertEqual($expected, $result);
|
||||
|
@ -313,7 +328,7 @@ class DispatcherTest extends UnitTestCase {
|
|||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
|
||||
Configure::write('baseUrl', '/CakeBB/index.php');
|
||||
Configure::write('App.baseUrl', '/CakeBB/index.php');
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '/CakeBB/index.php';
|
||||
$this->assertEqual($expected, $result);
|
||||
|
@ -324,25 +339,25 @@ class DispatcherTest extends UnitTestCase {
|
|||
|
||||
function testBaseUrlAndWebrootWithBase() {
|
||||
$dispatcher =& new Dispatcher();
|
||||
Configure::write('baseUrl',false);
|
||||
$dispatcher->base = '/app/webroot';
|
||||
Configure::write('App.baseUrl',false);
|
||||
$dispatcher->base = '/app';
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '/app';
|
||||
$this->assertEqual($expected, $result);
|
||||
$expectedWebroot = '/app/';
|
||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
$dispatcher->base = '/app';
|
||||
$dispatcher->base = '';
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '';
|
||||
$this->assertEqual($expected, $result);
|
||||
$expectedWebroot = '/';
|
||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
||||
Configure::write('app', 'testbed');
|
||||
$dispatcher->base = '/cake/testbed/webroot/test.php';
|
||||
Configure::write('App.dir', 'testbed');
|
||||
$dispatcher->base = '/cake/testbed/webroot';
|
||||
$result = $dispatcher->baseUrl();
|
||||
$expected = '/cake/testbed/test.php';
|
||||
$expected = '/cake/testbed/webroot';
|
||||
$this->assertEqual($expected, $result);
|
||||
$expectedWebroot = '/cake/testbed/webroot/';
|
||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||
|
|
Loading…
Reference in a new issue