Skip to content

Commit

Permalink
Re-adding support for PHP's include_path.
Browse files Browse the repository at this point in the history
Moving constants that are made of other constants into bootstrap.php
  • Loading branch information
markstory committed Aug 4, 2011
1 parent e083b21 commit 721c438
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 46 deletions.
27 changes: 22 additions & 5 deletions app/Console/cake.php
Expand Up @@ -3,8 +3,6 @@
/**
* Command-line code generation utility to automate programmer chores.
*
* Shell dispatcher class
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
Expand All @@ -15,10 +13,29 @@
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package app.console
* @since CakePHP(tm) v 1.2.0.5012
* @package app.Console
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'lib'. DIRECTORY_SEPARATOR . 'Cake' . DIRECTORY_SEPARATOR . 'Console' . DIRECTORY_SEPARATOR . 'ShellDispatcher.php');
$ds = DIRECTORY_SEPARATOR;
$dispatcher = 'Cake' . $ds . 'Console' . $ds . 'ShellDispatcher.php';
$found = false;
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));

foreach ($paths as $path) {
if (file_exists($path . $ds . $dispatcher)) {
$found = $path;
}
}

if (!$found && function_exists('ini_set')) {
$root = dirname(dirname(dirname(__FILE__)));
ini_set('include_path', $root . $ds. 'lib' . PATH_SEPARATOR . ini_get('include_path'));
}

if (!include($dispatcher)) {
trigger_error('Could not locate CakePHP core files.', E_USER_ERROR);
}
unset($paths, $path, $found, $dispatcher, $root, $ds);

return ShellDispatcher::run($argv);
27 changes: 20 additions & 7 deletions app/webroot/index.php
Expand Up @@ -44,13 +44,17 @@
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(__FILE__))));
}

/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
* Un-comment this line to specify a fixed path to CakePHP.
* This should point at the directory containg `Cake`.
*
* For ease of development CakePHP uses PHP's include_path. If you
* cannot modify your include_path set this value.
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
}
//define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');

/**
* Editing below this line should NOT be necessary.
Expand All @@ -63,11 +67,20 @@
if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
}
if (!include('Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
} else {
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
}
if (!include(CORE_PATH . 'Cake' . DS . 'bootstrap.php')) {
if (!empty($failed)) {
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);
}

Expand Down
24 changes: 17 additions & 7 deletions app/webroot/test.php
Expand Up @@ -44,13 +44,14 @@
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(__FILE__))));
}

/**
* The absolute path to the "Cake" directory, WITHOUT a trailing DS.
*
* For ease of development CakePHP uses PHP's include_path. If you
* need to cannot modify your include_path, you can set this path.
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
}
//define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');

/**
* Editing below this line should not be necessary.
Expand All @@ -63,11 +64,20 @@
if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
}
if (!include('Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
} else {
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
}
if (!include(CORE_PATH . 'Cake' . DS . 'bootstrap.php')) {
if (!empty($failed)) {
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);
}

Expand Down
28 changes: 21 additions & 7 deletions lib/Cake/Console/Templates/skel/webroot/index.php
Expand Up @@ -44,13 +44,17 @@
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(__FILE__))));
}

/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
* Un-comment this line to specify a fixed path to CakePHP.
* This should point at the directory containg `Cake`.
*
* For ease of development CakePHP uses PHP's include_path. If you
* need to squeeze a bit more performance you can set this path.
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
}
//define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');

/**
* Editing below this line should NOT be necessary.
Expand All @@ -63,11 +67,20 @@
if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
}
if (!include('Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
} else {
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
}
if (!include(CORE_PATH . 'Cake' . DS . 'bootstrap.php')) {
if (!empty($failed)) {
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);
}

Expand All @@ -76,5 +89,6 @@
}

App::uses('Dispatcher', 'Routing');

$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding'))));
24 changes: 17 additions & 7 deletions lib/Cake/Console/Templates/skel/webroot/test.php
Expand Up @@ -44,13 +44,14 @@
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(__FILE__))));
}

/**
* The absolute path to the "Cake" directory, WITHOUT a trailing DS.
*
* For ease of development CakePHP uses PHP's include_path. If you
* need to cannot modify your include_path, you can set this path.
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
}
//define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');

/**
* Editing below this line should not be necessary.
Expand All @@ -63,11 +64,20 @@
if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
}
if (!include('Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
} else {
if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
}
if (!include(CORE_PATH . 'Cake' . DS . 'bootstrap.php')) {
if (!empty($failed)) {
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);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Console/cake.php
Expand Up @@ -19,6 +19,6 @@
* @since CakePHP(tm) v 1.2.0.5012
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR. 'ShellDispatcher.php');
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ShellDispatcher.php');

return ShellDispatcher::run($argv);
27 changes: 15 additions & 12 deletions lib/Cake/bootstrap.php
Expand Up @@ -23,18 +23,21 @@
}
error_reporting(E_ALL & ~E_DEPRECATED);

/**
* If the index.php file is used instead of an .htaccess file
* or if the user can not set the web root to use the public
* directory we will define ROOT there, otherwise we set it
* here.
*/
if (!defined('ROOT')) {
define('ROOT', '../');
}
if (!defined('WEBROOT_DIR')) {
define('WEBROOT_DIR', 'webroot');
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(__FILE__)));
}

if (!defined('CORE_PATH')) {
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}

if (!defined('APP_PATH')) {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
}

if (!defined('WEBROOT_DIR')) {
define('WEBROOT_DIR', 'webroot');
}

/**
* Path to the cake directory.
Expand Down

0 comments on commit 721c438

Please sign in to comment.