Show
Ignore:
Timestamp:
10/24/07 22:20:19 (15 months ago)
Author:
jwage
Message:

Added to autoloading to support caching the loaded model paths so we can retrieve them with autoload.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine.php

    r2989 r3002  
    434434     */ 
    435435    private static $_debug = false; 
     436     
     437    /** 
     438     * _loadedModels 
     439     *  
     440     * Array of all the loaded models and the path to each one for autoloading 
     441     * 
     442     * @var string 
     443     */ 
     444    private static $_loadedModels = array(); 
    436445 
    437446    /** 
     
    549558    public static function loadModels($directory) 
    550559    { 
    551         $declared = get_declared_classes(); 
    552          
    553560        if ($directory !== null) { 
     561            $manager = Doctrine_Manager::getInstance(); 
     562             
    554563            foreach ((array) $directory as $dir) { 
    555564                $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), 
     
    559568                    $e = explode('.', $file->getFileName()); 
    560569                    if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { 
    561                         require_once $file->getPathName(); 
     570                        self::$_loadedModels[$e[0]] = $file->getPathName(); 
    562571                    } 
    563572                } 
    564573            } 
    565              
    566             $declared = array_diff(get_declared_classes(), $declared); 
    567         } 
    568          
    569         return self::getLoadedModels($declared); 
     574        } 
     575 
     576        return self::getLoadedModels(array_keys(self::$_loadedModels)); 
    570577    } 
    571578 
     
    968975    /** 
    969976     * compile 
     977     * 
    970978     * method for making a single file of most used doctrine runtime components 
    971979     * including the compiled file instead of multiple files (in worst 
     
    983991 
    984992    /** 
     993     * autoload 
     994     * 
    985995     * simple autoload function 
    986996     * returns true if the class was loaded, otherwise false 
     
    989999     * @return boolean 
    9901000     */ 
    991     public static function autoload($classname) 
    992     { 
    993         if (class_exists($classname, false)) { 
     1001    public static function autoload($className) 
     1002    { 
     1003        if (class_exists($className, false)) { 
    9941004            return false; 
    9951005        } 
     
    9991009        } 
    10001010         
    1001         $class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $classname) . '.php'; 
    1002  
    1003         if ( ! file_exists($class)) { 
    1004             return false; 
    1005         } 
    1006  
    1007         require_once($class); 
    1008  
    1009         return true; 
     1011        $class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; 
     1012 
     1013        if (file_exists($class)) { 
     1014            require_once($class); 
     1015             
     1016            return true; 
     1017        } 
     1018         
     1019        $loadedModels = self::$_loadedModels; 
     1020         
     1021        if (isset($loadedModels[$className]) && file_exists($loadedModels[$className])) { 
     1022            require_once($loadedModels[$className]); 
     1023             
     1024            return true; 
     1025        } 
     1026 
     1027        return false; 
    10101028    } 
    10111029 
     
    10431061 
    10441062    /** 
     1063     * tableize 
     1064     * 
    10451065     * returns table name from class name 
    10461066     * 
     
    10541074 
    10551075    /** 
     1076     * classify 
     1077     * 
    10561078     * returns class name from table name 
    10571079     * 
     
    10651087 
    10661088    /** 
     1089     * classifyCallback 
     1090     * 
    10671091     * Callback function to classify a classname propperly.  
    10681092     * 
     
    10761100 
    10771101    /** 
     1102     * isValidClassName 
     1103     * 
    10781104     * checks for valid class name (uses camel case and underscores) 
    10791105     * 
     
    10891115        return true; 
    10901116    } 
     1117     
     1118    /** 
     1119     * makeDirectories 
     1120     *  
     1121     * Makes the directories for a path recursively 
     1122     * 
     1123     * @param string $path  
     1124     * @return void 
     1125     */ 
     1126    public static function makeDirectories($path, $mode = 0777) 
     1127    { 
     1128        if (is_dir($path) || is_file($path)) 
     1129        { 
     1130          return true; 
     1131        } 
     1132 
     1133        return mkdir($path, $mode, true);  
     1134    } 
    10911135}