Changeset 3887

Show
Ignore:
Timestamp:
02/22/08 20:59:43 (17 months ago)
Author:
jwage
Message:

fixes #804

Location:
branches/0.10/lib
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/0.10/lib/Doctrine.php

    r3884 r3887  
    535535     * Recursively load all models from a directory or array of directories 
    536536     * 
    537      * @param string $directory    Path to directory of models or array of directory paths 
    538      * @return array $loadedModels 
    539      */ 
    540     public static function loadModels($directory) 
    541     { 
     537     * @param  string   $directory      Path to directory of models or array of directory paths 
     538     * @param  integer  $forceStyle     Pass value of Doctrine::ATTR_MODEL_LOADING to force a certain style of model loading 
     539     *                                  Allowed Doctrine::MODEL_LOADING_AGGRESSIVE(default) or Doctrine::MODEL_LOADING_CONSERVATIVE 
     540     * @return array    $modelLoading   Array of the models loaded by the operation 
     541     */ 
     542    public static function loadModels($directory, $modelLoading = null) 
     543    { 
     544        $manager = Doctrine_Manager::getInstance(); 
     545 
     546        $modelLoading = $modelLoading === null ? $manager->getAttribute(Doctrine::ATTR_MODEL_LOADING):$modelLoading; 
     547 
    542548        $loadedModels = array(); 
    543549 
    544         if ($directory !== null) { 
    545             $manager = Doctrine_Manager::getInstance(); 
    546  
     550        if ($directory !== null && is_dir($directory)) { 
    547551            foreach ((array) $directory as $dir) { 
    548552                $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), 
     
    552556                    if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { 
    553557 
    554                         if ($manager->getAttribute(Doctrine::ATTR_MODEL_LOADING) == Doctrine::MODEL_LOADING_CONSERVATIVE) { 
     558                        if ($modelLoading == Doctrine::MODEL_LOADING_CONSERVATIVE) { 
    555559                            self::$_loadedModelFiles[$e[0]] = $file->getPathName(); 
    556560                            self::$_pathModels[$file->getPathName()][$e[0]] = $e[0]; 
     
    578582                } 
    579583            } 
     584        } else { 
     585          throw new Doctrine_Exception('You must pass a valid path to a directory containing Doctrine models'); 
    580586        } 
    581587 
     
    914920     * generateMigrationsFromModels 
    915921     * 
    916      * @param string $migrationsPath 
    917      * @param string $modelsPath 
    918      * @return void 
    919      */ 
    920     public static function generateMigrationsFromModels($migrationsPath, $modelsPath = null) 
     922     * @param string  $migrationsPath Path to your Doctrine migration classes 
     923     * @param string  $modelsPath     Path to your Doctrine model classes 
     924     * @param integer $modelLoading   Style of model loading to use for loading the models in order to generate migrations 
     925     * @return void 
     926     */ 
     927    public static function generateMigrationsFromModels($migrationsPath, $modelsPath = null, $modelLoading = null) 
    921928    { 
    922929        $builder = new Doctrine_Migration_Builder($migrationsPath); 
    923930 
    924         return $builder->generateMigrationsFromModels($modelsPath); 
     931        return $builder->generateMigrationsFromModels($modelsPath, $modelLoading); 
    925932    } 
    926933 
  • branches/0.10/lib/Doctrine/Import/Builder.php

    r3884 r3887  
    790790 
    791791        if (isset($definition['generate_once']) && $definition['generate_once'] === true) { 
    792             if (!file_exists($writePath)) { 
     792            if ( ! file_exists($writePath)) { 
    793793                $bytes = file_put_contents($writePath, $code); 
    794794            } 
  • branches/0.10/lib/Doctrine/Migration/Builder.php

    r3884 r3887  
    141141        Doctrine::generateModelsFromDb($directory); 
    142142         
    143         $result = $this->generateMigrationsFromModels($directory); 
     143        $result = $this->generateMigrationsFromModels($directory, Doctrine::MODEL_LOADING_CONSERVATIVE); 
    144144         
    145145        Doctrine_Lib::removeDirectories($directory); 
     
    154154     * @return void 
    155155     */ 
    156     public function generateMigrationsFromModels($modelsPath = null) 
     156    public function generateMigrationsFromModels($modelsPath = null, $modelLoading = null) 
    157157    { 
    158158        if ($modelsPath !== null) { 
    159             $models = Doctrine::filterInvalidModels(Doctrine::loadModels($modelsPath)); 
     159            $models = Doctrine::filterInvalidModels(Doctrine::loadModels($modelsPath, $modelLoading)); 
    160160        } else { 
    161161            $models = Doctrine::getLoadedModels();