From b4d655a3c859da494deacc7261994d7cf64d73b8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 5 Aug 2012 13:33:00 -0400 Subject: [PATCH] Consolidate more configuration data. --- App/Config/app.php | 15 +++++++++++-- App/Config/error.php | 15 ++++++++----- App/Config/paths.php | 2 +- App/Config/routes.php | 4 ++-- lib/Cake/Core/App.php | 3 --- lib/Cake/Core/Configure.php | 38 +-------------------------------- lib/Cake/Routing/Dispatcher.php | 2 +- lib/Cake/bootstrap.php | 7 ++++++ 8 files changed, 35 insertions(+), 51 deletions(-) diff --git a/App/Config/app.php b/App/Config/app.php index 5f1b8a0c538..970b7a76d0e 100644 --- a/App/Config/app.php +++ b/App/Config/app.php @@ -2,6 +2,7 @@ namespace App\Config; use Cake\Core\Configure; +use Cake\Core\ClassLoader; /** * CakePHP Debug Level: @@ -18,6 +19,12 @@ */ Configure::write('debug', 2); +/** + * The root namespace your application uses. This should match + * the top level directory. + */ + $namespace = 'App'; + /** * Configure basic information about the application. * @@ -36,12 +43,16 @@ * - www_root - The file path to webroot. */ Configure::write('App', array( - 'namespace' => 'App', + 'namespace' => $namespace, 'encoding' => 'UTF-8', + 'base' => false, 'baseUrl' => false, //'baseUrl' => env('SCRIPT_NAME'), - 'base' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT, )); + + $loader = new ClassLoader($namespace, dirname(APP)); + $loader->register(); + unset($loader, $namespace); diff --git a/App/Config/error.php b/App/Config/error.php index 8b3f35e4214..c92050e244a 100644 --- a/App/Config/error.php +++ b/App/Config/error.php @@ -17,11 +17,11 @@ * * @see ErrorHandler for more information on error handling and configuration. */ - Configure::write('Error', array( + $error = array( 'handler' => 'Cake\Error\ErrorHandler::handleError', 'level' => E_ALL & ~E_DEPRECATED, 'trace' => true - )); + ); /** * Configure the Exception handler used for uncaught exceptions. By default, @@ -39,10 +39,15 @@ * * @see ErrorHandler for more information on exception handling and configuration. */ - Configure::write('Exception', array( + $exception = array( 'handler' => 'Cake\Error\ErrorHandler::handleException', 'renderer' => 'Cake\Error\ExceptionRenderer', 'log' => true - )); + ); - Configure::setErrorHandlers(); + Configure::setErrorHandlers( + $error, + $exception + ); + + unset($error, $exception); diff --git a/App/Config/paths.php b/App/Config/paths.php index 02d6b5badd3..8f5a6afd5b8 100644 --- a/App/Config/paths.php +++ b/App/Config/paths.php @@ -23,7 +23,7 @@ /** * The name of the webroot dir. Defaults to 'webroot' */ -define('WEBROOT_DIR', basename(dirname(__FILE__))); +define('WEBROOT_DIR', 'webroot'); /** * File path to the webroot directory. diff --git a/App/Config/routes.php b/App/Config/routes.php index 393760e0a58..6178caf6222 100644 --- a/App/Config/routes.php +++ b/App/Config/routes.php @@ -30,11 +30,11 @@ * its action called 'display', and we pass a param to select the view file * to use (in this case, /app/View/Pages/home.ctp)... */ - Router::connect('/', array('controller' => 'Pages', 'action' => 'display', 'home')); + Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); /** * ...and connect the rest of 'Pages' controller's urls. */ - Router::connect('/pages/*', array('controller' => 'Pages', 'action' => 'display')); + Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); /** * Load all plugin routes. See the Plugin documentation on diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 5e02af1b994..cb9596b3d24 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -536,9 +536,6 @@ public static function location($className) { * @return void */ public static function init() { - $loader = new ClassLoader(Configure::read('App.namespace'), dirname(APP)); - $loader->register(); - register_shutdown_function(array(__CLASS__, 'shutdown')); } diff --git a/lib/Cake/Core/Configure.php b/lib/Cake/Core/Configure.php index 75bffcd987b..410bb6aecf0 100644 --- a/lib/Cake/Core/Configure.php +++ b/lib/Cake/Core/Configure.php @@ -49,36 +49,6 @@ class Configure { */ protected static $_readers = array(); -/** - * Initializes configure and runs the bootstrap process. - * Bootstrapping includes the following steps: - * - * - Setup App array in Configure. - * - Include app/Config/core.php. - * - Configure core cache configurations. - * - Load App cache files. - * - Include app/Config/bootstrap.php. - * - Setup error/exception handlers. - * - * @param boolean $boot - * @return void - */ - public static function bootstrap($boot = true) { - if ($boot) { - static::write('App', array( - 'base' => false, - 'baseUrl' => false, - 'dir' => APP_DIR, - 'webroot' => WEBROOT_DIR, - 'www_root' => WWW_ROOT - )); - - App::init(); - App::build(); - - } - } - /** * Used to store a dynamic variable in Configure. * @@ -385,13 +355,7 @@ public static function clear() { * @param array $exception The exception handling configuration. * @return void */ - public static function setErrorHandlers($error = null, $exception = null) { - if (!$error) { - $error = self::$_values['Error']; - } - if (!$exception) { - $exception = self::$_values['Exception']; - } + public static function setErrorHandlers($error, $exception) { $level = -1; if (isset($error['level'])) { error_reporting($error['level']); diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index 5387b52585b..e2c58628ca1 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -19,8 +19,8 @@ * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ - namespace Cake\Routing; + use Cake\Controller\Controller; use Cake\Core\App; use Cake\Core\Configure; diff --git a/lib/Cake/bootstrap.php b/lib/Cake/bootstrap.php index ec28cdd28f6..a36585ec06d 100644 --- a/lib/Cake/bootstrap.php +++ b/lib/Cake/bootstrap.php @@ -27,6 +27,13 @@ $loader = new \Cake\Core\ClassLoader('Cake', CORE_PATH); $loader->register(); + +use Cake\Core\App; +use Cake\Core\Configure; + +App::init(); +App::build(); + /** * Full url prefix */