Skip to content

Commit

Permalink
Adding cache support for class loader
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Dec 5, 2010
1 parent fcd23b0 commit 0596f5a
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lib/Cake/Core/App.php
Expand Up @@ -440,13 +440,19 @@ public static function uses($className, $location) {

public static function load($className) {
if (isset(self::$__classMap[$className])) {

if ($file = self::__mapped($className)) {
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)) {
self::__map($file, $className);
return include $file;
}
}
Expand Down Expand Up @@ -678,38 +684,36 @@ private static function __load($file) {
*
* @param string $file full path to file
* @param string $name unique name for this map
* @param string $type type object being mapped
* @param string $plugin camelized if object is from a plugin, the name of the plugin
* @return void
* @access private
*/
private static function __map($file, $name, $type, $plugin) {
private static function __map($file, $name, $plugin = null) {
if ($plugin) {
self::$__map['Plugin'][$plugin][$type][$name] = $file;
self::$__map['Plugin'][$plugin][$name] = $file;
} else {
self::$__map[$type][$name] = $file;
self::$__map[$name] = $file;
}
}

/**
* Returns a file's complete path.
*
* @param string $name unique name
* @param string $type type object
* @param string $plugin camelized if object is from a plugin, the name of the plugin
* @return mixed, file path if found, false otherwise
* @access private
*/
private static function __mapped($name, $type, $plugin) {
private static function __mapped($name, $plugin = null) {
if ($plugin) {
if (isset(self::$__map['Plugin'][$plugin][$type]) && isset(self::$__map['Plugin'][$plugin][$type][$name])) {
return self::$__map['Plugin'][$plugin][$type][$name];
if (isset(self::$__map['Plugin'][$plugin][$name])) {
return self::$__map['Plugin'][$plugin][$name];
}
return false;
}

if (isset(self::$__map[$type]) && isset(self::$__map[$type][$name])) {
return self::$__map[$type][$name];
if (isset(self::$__map[$name])) {
return self::$__map[$name];
}
return false;
}
Expand Down Expand Up @@ -897,9 +901,6 @@ private static function __list($path, $suffix = false, $extension = false) {
*/
public static function shutdown() {
if (self::$__cache) {
$core = App::core('cake');
unset(self::$__paths[rtrim($core[0], DS)]);
Cache::write('dir_map', array_filter(self::$__paths), '_cake_core_');
Cache::write('file_map', array_filter(self::$__map), '_cake_core_');
Cache::write('object_map', self::$__objects, '_cake_core_');
}
Expand Down

0 comments on commit 0596f5a

Please sign in to comment.