Skip to content

Commit

Permalink
Beging of an experiment: a class utoloader for cakephp through emulat…
Browse files Browse the repository at this point in the history
…ing the keyword "use" of php 5.3
  • Loading branch information
lorenzo committed Dec 3, 2010
1 parent aa0bad9 commit da7c53b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
19 changes: 19 additions & 0 deletions cake/libs/app.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -430,6 +436,17 @@ public static function setObjects($type, $values) {
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.
Expand Down Expand Up @@ -887,3 +904,5 @@ public static function shutdown() {
}
}
}

spl_autoload_register(array('App', 'load'));
13 changes: 6 additions & 7 deletions cake/libs/dispatcher.php
Expand Up @@ -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
Expand Down Expand Up @@ -270,9 +272,6 @@ public function cached($url) {
}

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));
Expand Down

0 comments on commit da7c53b

Please sign in to comment.