Commit 094e6cb3 authored by Jonathan.Wage's avatar Jonathan.Wage

Added to autoloading to support caching the loaded model paths so we can...

Added to autoloading to support caching the loaded model paths so we can retrieve them with autoload.
parent 4d527b93
...@@ -433,6 +433,15 @@ final class Doctrine ...@@ -433,6 +433,15 @@ final class Doctrine
* @var boolean $_debug * @var boolean $_debug
*/ */
private static $_debug = false; private static $_debug = false;
/**
* _loadedModels
*
* Array of all the loaded models and the path to each one for autoloading
*
* @var string
*/
private static $_loadedModels = array();
/** /**
* __construct * __construct
...@@ -548,9 +557,9 @@ final class Doctrine ...@@ -548,9 +557,9 @@ final class Doctrine
*/ */
public static function loadModels($directory) public static function loadModels($directory)
{ {
$declared = get_declared_classes();
if ($directory !== null) { if ($directory !== null) {
$manager = Doctrine_Manager::getInstance();
foreach ((array) $directory as $dir) { foreach ((array) $directory as $dir) {
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
RecursiveIteratorIterator::LEAVES_ONLY); RecursiveIteratorIterator::LEAVES_ONLY);
...@@ -558,15 +567,13 @@ final class Doctrine ...@@ -558,15 +567,13 @@ final class Doctrine
foreach ($it as $file) { foreach ($it as $file) {
$e = explode('.', $file->getFileName()); $e = explode('.', $file->getFileName());
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
require_once $file->getPathName(); self::$_loadedModels[$e[0]] = $file->getPathName();
} }
} }
} }
$declared = array_diff(get_declared_classes(), $declared);
} }
return self::getLoadedModels($declared); return self::getLoadedModels(array_keys(self::$_loadedModels));
} }
/** /**
...@@ -967,6 +974,7 @@ final class Doctrine ...@@ -967,6 +974,7 @@ final class Doctrine
/** /**
* compile * compile
*
* method for making a single file of most used doctrine runtime components * method for making a single file of most used doctrine runtime components
* including the compiled file instead of multiple files (in worst * including the compiled file instead of multiple files (in worst
* cases dozens of files) can improve performance by an order of magnitude * cases dozens of files) can improve performance by an order of magnitude
...@@ -982,15 +990,17 @@ final class Doctrine ...@@ -982,15 +990,17 @@ final class Doctrine
} }
/** /**
* autoload
*
* simple autoload function * simple autoload function
* returns true if the class was loaded, otherwise false * returns true if the class was loaded, otherwise false
* *
* @param string $classname * @param string $classname
* @return boolean * @return boolean
*/ */
public static function autoload($classname) public static function autoload($className)
{ {
if (class_exists($classname, false)) { if (class_exists($className, false)) {
return false; return false;
} }
...@@ -998,15 +1008,23 @@ final class Doctrine ...@@ -998,15 +1008,23 @@ final class Doctrine
self::$_path = dirname(__FILE__); self::$_path = dirname(__FILE__);
} }
$class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $classname) . '.php'; $class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
if ( ! file_exists($class)) { if (file_exists($class)) {
return false; require_once($class);
return true;
}
$loadedModels = self::$_loadedModels;
if (isset($loadedModels[$className]) && file_exists($loadedModels[$className])) {
require_once($loadedModels[$className]);
return true;
} }
require_once($class); return false;
return true;
} }
/** /**
...@@ -1042,6 +1060,8 @@ final class Doctrine ...@@ -1042,6 +1060,8 @@ final class Doctrine
} }
/** /**
* tableize
*
* returns table name from class name * returns table name from class name
* *
* @param string $classname * @param string $classname
...@@ -1053,6 +1073,8 @@ final class Doctrine ...@@ -1053,6 +1073,8 @@ final class Doctrine
} }
/** /**
* classify
*
* returns class name from table name * returns class name from table name
* *
* @param string $tablename * @param string $tablename
...@@ -1064,6 +1086,8 @@ final class Doctrine ...@@ -1064,6 +1086,8 @@ final class Doctrine
} }
/** /**
* classifyCallback
*
* Callback function to classify a classname propperly. * Callback function to classify a classname propperly.
* *
* @param array $matches An array of matches from a pcre_replace call * @param array $matches An array of matches from a pcre_replace call
...@@ -1075,6 +1099,8 @@ final class Doctrine ...@@ -1075,6 +1099,8 @@ final class Doctrine
} }
/** /**
* isValidClassName
*
* checks for valid class name (uses camel case and underscores) * checks for valid class name (uses camel case and underscores)
* *
* @param string $classname * @param string $classname
...@@ -1088,4 +1114,22 @@ final class Doctrine ...@@ -1088,4 +1114,22 @@ final class Doctrine
return true; return true;
} }
}
/**
* makeDirectories
*
* Makes the directories for a path recursively
*
* @param string $path
* @return void
*/
public static function makeDirectories($path, $mode = 0777)
{
if (is_dir($path) || is_file($path))
{
return true;
}
return mkdir($path, $mode, true);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment