From da7c53b37455677ed32f0ae8e0f5228c8561d1a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Lorenzo=20Rodri=CC=81guez?= Date: Fri, 3 Dec 2010 16:54:50 -0430 Subject: [PATCH] Beging of an experiment: a class utoloader for cakephp through emulating the keyword "use" of php 5.3 --- cake/libs/app.php | 19 +++++++++++++++++++ cake/libs/dispatcher.php | 13 ++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/cake/libs/app.php b/cake/libs/app.php index f18bb0719..66df9c93b 100644 --- a/cake/libs/app.php +++ b/cake/libs/app.php @@ -201,6 +201,12 @@ class App { */ private static $__objects = array(); +/** + * Holds the location of each class + * + */ + private static $__classMap = array(); + /** * Used to read information stored path * @@ -430,6 +436,17 @@ class App { self::$__objects[$type] = $values; } + public static function uses($className, $location) { + self::$__classMap[$className] = $location; + } + + public static function load($className) { + if (isset(self::$__classMap[$className])) { + return App::import(self::$__classMap[$className], $className, false); + } + return false; + } + /** * Finds classes based on $name or specific file(s) to search. Calling App::import() will * not construct any classes contained in the files. It will only find and require() the file. @@ -887,3 +904,5 @@ class App { } } } + +spl_autoload_register(array('App', 'load')); \ No newline at end of file diff --git a/cake/libs/dispatcher.php b/cake/libs/dispatcher.php index cb14d18ba..1a3738e89 100644 --- a/cake/libs/dispatcher.php +++ b/cake/libs/dispatcher.php @@ -24,10 +24,12 @@ /** * List of helpers to include */ -App::import('Core', 'Router', false); -App::import('Core', 'CakeRequest', false); -App::import('Core', 'CakeResponse', false); -App::import('Controller', 'Controller', false); +App::uses('Router', 'Core'); +App::uses('CakeRequest', 'Core'); +App::uses('CakeResponse', 'Core'); +App::uses('Controller', 'Controller'); +App::uses('View', 'View'); +App::uses('Debugger', 'Core'); /** * Dispatcher converts Requests into controller actions. It uses the dispatched Request @@ -270,9 +272,6 @@ class Dispatcher { } if (file_exists($filename)) { - if (!class_exists('View')) { - App::import('View', 'View', false); - } $controller = null; $view = new View($controller); return $view->renderCache($filename, microtime(true));