diff --git a/lib/Cake/Controller/PagesController.php b/lib/Cake/Controller/PagesController.php index bc7a380e7fa..60d9e02900e 100644 --- a/lib/Cake/Controller/PagesController.php +++ b/lib/Cake/Controller/PagesController.php @@ -20,6 +20,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('AppController', 'Controller'); + /** * Static content controller * diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index eb7d0319f28..b85aa9921cd 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -207,6 +207,12 @@ class App { */ private static $__classMap = array(); +/** + * Holds the possible paths for each package name + * + */ + private static $__packages = array(); + /** * Used to read information stored path * @@ -218,10 +224,10 @@ class App { * @return string array */ public static function path($type) { - if (!isset(self::${$type})) { + if (!isset(self::$__packages[$type])) { return array(); } - return self::${$type}; + return self::$__packages[$type]; } /** @@ -234,14 +240,14 @@ public static function path($type) { */ public static function build($paths = array(), $reset = false) { $defaults = array( - 'models' => array(MODELS), - 'behaviors' => array(BEHAVIORS), - 'datasources' => array(MODELS . 'datasources'), - 'controllers' => array(CONTROLLERS), - 'components' => array(COMPONENTS), + 'Model' => array(MODELS), + 'Model/Behavior' => array(BEHAVIORS), + 'Datasource' => array(MODELS . 'datasources'), + 'Controller' => array(CONTROLLERS), + 'Controller/Component' => array(COMPONENTS), 'libs' => array(APPLIBS), - 'views' => array(VIEWS), - 'helpers' => array(HELPERS), + 'View' => array(VIEWS), + 'View/Helper' => array(HELPERS), 'locales' => array(APP . 'locale' . DS), 'shells' => array( APP . 'console' . DS . 'shells' . DS, @@ -254,7 +260,7 @@ public static function build($paths = array(), $reset = false) { if ($reset == true) { foreach ($paths as $type => $new) { - self::${$type} = (array)$new; + self::$__packages[$type] = (array)$new; } return $paths; } @@ -263,27 +269,19 @@ public static function build($paths = array(), $reset = false) { $app = array('models' => true, 'controllers' => true, 'helpers' => true); foreach ($defaults as $type => $default) { - $merge = array(); - if (isset($app[$type])) { - $merge = array(APP); - } - if (isset($core[$type])) { - $merge = array_merge($merge, (array)$core[$type]); - } - - if (empty(self::${$type}) || empty($paths)) { - self::${$type} = $default; + if (empty(self::$__packages[$type]) || empty($paths)) { + self::$__packages[$type] = $default; } if (!empty($paths[$type])) { $path = array_flip(array_flip(array_merge( - (array)$paths[$type], self::${$type}, $merge + (array)$paths[$type], self::$__packages[$type], $merge ))); - self::${$type} = array_values($path); + self::$__packages[$type] = array_values($path); } else { - $path = array_flip(array_flip(array_merge(self::${$type}, $merge))); - self::${$type} = array_values($path); + $path = array_flip(array_flip(self::$__packages[$type])); + self::$__packages[$type] = array_values($path); } } } @@ -442,9 +440,15 @@ public static function uses($className, $location) { public static function load($className) { if (isset(self::$__classMap[$className])) { - $file = LIBS . self::$__classMap[$className] . DS . $className . '.php'; - if (file_exists($file)) { - return include $file; + $package = self::$__classMap[$className]; + $paths = self::path($package); + $paths[] = LIBS . self::$__classMap[$className] . DS; + + foreach ($paths as $path) { + $file = $path . $className . '.php'; + if (file_exists($file)) { + return include $file; + } } } return false; @@ -900,6 +904,4 @@ public static function shutdown() { Cache::write('object_map', self::$__objects, '_cake_core_'); } } -} - -spl_autoload_register(array('App', 'load')); \ No newline at end of file +} \ No newline at end of file diff --git a/cake/libs/model/app_model.php b/lib/Cake/Model/AppModel.php similarity index 100% rename from cake/libs/model/app_model.php rename to lib/Cake/Model/AppModel.php diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index 1fd36319c30..251b56f6e2f 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -223,10 +223,7 @@ protected function _getController($request) { if (!$ctrlClass) { return false; } - $ctrlClass .= 'Controller'; - if (class_exists($ctrlClass)) { - return new $ctrlClass($request); - } + return new $ctrlClass($request); } /** @@ -245,8 +242,11 @@ protected function _loadController($request) { $controller = Inflector::camelize($request->params['controller']); } if ($pluginPath . $controller) { - if (App::import('Controller', $pluginPath . $controller)) { - return $controller; + $class = $controller . 'Controller'; + App::uses('AppController', 'Controller'); + App::uses($class, $pluginPath . 'Controller'); + if (class_exists($class)) { + return $class; } } return false; diff --git a/lib/Cake/Utility/ClassRegistry.php b/lib/Cake/Utility/ClassRegistry.php index cc2ebeb3b21..a80abdc986e 100644 --- a/lib/Cake/Utility/ClassRegistry.php +++ b/lib/Cake/Utility/ClassRegistry.php @@ -134,14 +134,17 @@ public static function &init($class, $type = null) { return $model; } - if (class_exists($class) || App::import($type, $pluginPath . $class)) { + App::uses('Model', 'Model'); + App::uses('AppModel', 'Model'); + App::uses($class, $pluginPath . $type); + if (class_exists($class)) { ${$class} = new $class($settings); } elseif ($type === 'Model') { - if ($plugin && class_exists($plugin . 'AppModel')) { - $appModel = $plugin . 'AppModel'; - } else { + //if ($plugin && class_exists($plugin . 'AppModel')) { + // $appModel = $plugin . 'AppModel'; + //} else { $appModel = 'AppModel'; - } + //} $settings['name'] = $class; ${$class} = new $appModel($settings); } diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 9ca29b464fa..c080ccc6565 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -799,7 +799,7 @@ protected function _paths($plugin = null, $cached = true) { return $this->__paths; } $paths = array(); - $viewPaths = App::path('views'); + $viewPaths = App::path('View'); $corePaths = array_flip(App::core('views')); if (!empty($plugin)) { diff --git a/lib/Cake/bootstrap.php b/lib/Cake/bootstrap.php index 1e649440e18..f7ca698e30a 100644 --- a/lib/Cake/bootstrap.php +++ b/lib/Cake/bootstrap.php @@ -222,6 +222,8 @@ require LIBS . 'Core' . DS .'App.php'; require LIBS . 'Error' . DS . 'exceptions.php'; +spl_autoload_register(array('App', 'load')); + App::uses('ErrorHandler', 'Error'); App::uses('Configure', 'Core'); App::uses('Cache', 'Cache');