Show
Ignore:
Timestamp:
10/20/07 03:30:15 (15 months ago)
Author:
jwage
Message:

A little formatting and documentation.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine.php

    r2942 r2943  
    116116    const PARAM_STMT = 4; 
    117117    const PARAM_STR = 2; 
     118 
    118119    /** 
    119120     * ATTRIBUTE CONSTANTS 
     
    181182    const ATTR_THROW_EXCEPTIONS     = 155; 
    182183 
    183  
    184184    /** 
    185185     * LIMIT CONSTANTS 
     
    190190     */ 
    191191    const LIMIT_ROWS       = 1; 
    192      
     192 
    193193    /** 
    194194     * constant for record limiting 
     
    205205     */ 
    206206    const FETCH_IMMEDIATE       = 0; 
    207      
     207 
    208208    /** 
    209209     * BATCH FETCHING 
     
    211211     */ 
    212212    const FETCH_BATCH           = 1; 
    213      
     213 
    214214    /** 
    215215     * LAZY FETCHING 
     
    217217     */ 
    218218    const FETCH_OFFSET          = 3; 
    219      
     219 
    220220    /** 
    221221     * LAZY OFFSET FETCHING 
     
    233233     */ 
    234234    const FETCH_VHOLDER         = 1; 
    235      
     235 
    236236    /** 
    237237     * FETCH RECORD 
     
    243243     */ 
    244244    const FETCH_RECORD          = 2; 
    245      
     245 
    246246    /** 
    247247     * FETCH ARRAY 
    248248     */ 
    249249    const FETCH_ARRAY           = 3; 
    250      
     250 
    251251    /** 
    252252     * PORTABILITY CONSTANTS 
     
    258258     */ 
    259259    const PORTABILITY_NONE          = 0; 
    260      
     260 
    261261    /** 
    262262     * Portability: convert names of tables and fields to case defined in the 
     
    271271     */ 
    272272    const PORTABILITY_RTRIM         = 2; 
    273      
     273 
    274274    /** 
    275275     * Portability: force reporting the number of rows deleted. 
     
    277277     */ 
    278278    const PORTABILITY_DELETE_COUNT  = 4; 
    279      
     279 
    280280    /** 
    281281     * Portability: convert empty values to null strings in data output by 
     
    284284     */ 
    285285    const PORTABILITY_EMPTY_TO_NULL = 8; 
    286      
     286 
    287287    /** 
    288288     * Portability: removes database/table qualifiers from associative indexes 
     
    290290     */ 
    291291    const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16; 
    292      
     292 
    293293    /** 
    294294     * Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions 
     
    296296     */ 
    297297    const PORTABILITY_EXPR          = 32; 
    298      
     298 
    299299    /** 
    300300     * Portability: turn on all portability features. 
     
    311311     */ 
    312312    const LOCK_OPTIMISTIC       = 0; 
    313      
     313 
    314314    /** 
    315315     * mode for pessimistic locking 
    316316     */ 
    317317    const LOCK_PESSIMISTIC      = 1; 
    318      
     318 
    319319    /** 
    320320     * EXPORT CONSTANTS 
     
    322322 
    323323    /** 
    324      * turns of exporting 
     324     * EXPORT_NONE 
    325325     */ 
    326326    const EXPORT_NONE               = 0; 
    327      
    328     /** 
    329      * export tables 
     327 
     328    /** 
     329     * EXPORT_TABLES 
    330330     */ 
    331331    const EXPORT_TABLES             = 1; 
    332      
    333     /** 
    334      * export constraints 
     332 
     333    /** 
     334     * EXPORT_CONSTRAINTS 
    335335     */ 
    336336    const EXPORT_CONSTRAINTS        = 2; 
    337      
    338     /** 
    339      * export plugins 
     337 
     338    /** 
     339     * EXPORT_PLUGINS 
    340340     */ 
    341341    const EXPORT_PLUGINS            = 4; 
    342      
    343     /** 
    344      * export all 
     342 
     343    /** 
     344     * EXPORT_ALL 
    345345     */ 
    346346    const EXPORT_ALL                = 7; 
    347      
     347 
    348348    /** 
    349349     * HYDRATION CONSTANTS 
     
    351351    const HYDRATE_RECORD            = 2; 
    352352     
     353    /** 
     354     * HYDRATE_ARRAY 
     355     */ 
    353356    const HYDRATE_ARRAY             = 3; 
    354357 
     
    358361    const VALIDATE_NONE             = 0; 
    359362 
     363    /** 
     364     * VALIDATE_LENGTHS 
     365     */ 
    360366    const VALIDATE_LENGTHS          = 1; 
    361      
     367 
     368    /** 
     369     * VALIDATE_TYPES 
     370     */ 
    362371    const VALIDATE_TYPES            = 2; 
    363      
     372 
     373    /** 
     374     * VALIDATE_CONSTRAINTS 
     375     */ 
    364376    const VALIDATE_CONSTRAINTS      = 4; 
    365      
     377 
     378    /** 
     379     * VALIDATE_ALL 
     380     */ 
    366381    const VALIDATE_ALL              = 7; 
    367382 
    368383    /** 
     384     * IDENTIFIER_AUTOINC 
     385     * 
    369386     * constant for auto_increment identifier 
    370387     */ 
    371388    const IDENTIFIER_AUTOINC        = 1; 
    372      
    373     /** 
     389 
     390    /** 
     391     * IDENTIFIER_SEQUENCE 
     392     * 
    374393     * constant for sequence identifier 
    375394     */ 
    376395    const IDENTIFIER_SEQUENCE       = 2; 
    377      
    378     /** 
     396 
     397    /** 
     398     * IDENTIFIER_NATURAL 
     399     * 
    379400     * constant for normal identifier 
    380401     */ 
    381402    const IDENTIFIER_NATURAL        = 3; 
    382      
    383     /** 
     403 
     404    /** 
     405     * IDENTIFIER_COMPOSITE 
     406     * 
    384407     * constant for composite identifier 
    385408     */ 
    386409    const IDENTIFIER_COMPOSITE      = 4; 
    387      
    388     /** 
     410 
     411    /** 
     412     * Path 
     413     * 
    389414     * @var string $path            doctrine root directory 
    390415     */ 
    391416    private static $_path; 
    392      
    393     /** 
     417 
     418    /** 
     419     * Debug 
     420     * 
     421     * Bool true/false 
     422     * 
    394423     * @var boolean $_debug 
    395424     */ 
    396425    private static $_debug = false; 
    397      
     426 
    398427    /** 
    399428     * __construct 
     
    406435        throw new Doctrine_Exception('Doctrine is static class. No instances can be created.'); 
    407436    } 
    408      
     437 
    409438    /** 
    410439     * debug 
     
    421450        return self::$_debug; 
    422451    } 
    423      
     452 
    424453    /** 
    425454     * getPath 
     
    436465        return self::$_path; 
    437466    } 
    438      
     467 
    439468    /** 
    440469     * loadAll 
     
    447476        return self::loadAllRuntimeClasses(); 
    448477    } 
    449      
     478 
    450479    /** 
    451480     * importSchema 
     
    460489        return self::generateModelsFromDb($directory, $databases); 
    461490    } 
    462      
     491 
    463492    /** 
    464493     * exportSchema 
     
    472501        return self::createTablesFromModels($directory); 
    473502    } 
    474      
     503 
    475504    /** 
    476505     * exportSql 
     
    483512        return self::generateSqlFromModels($directory); 
    484513    } 
    485      
     514 
    486515    /** 
    487516     * loadAllRuntimeClasses 
     
    499528        } 
    500529    } 
    501      
     530 
    502531    /** 
    503532     * loadModels 
     
    506535     *  
    507536     * @param string $directory Path to directory of models or array of directory paths 
    508      * @return void 
     537     * @return array $loadedModels 
    509538     */ 
    510539    public static function loadModels($directory) 
     
    530559        return self::getLoadedModels($declared); 
    531560    } 
    532      
     561 
    533562    /** 
    534563     * getLoadedModels 
     
    536565     * Get all the loaded models, you can provide an array of classes or it will use get_declared_classes() 
    537566     *  
     567     * Will filter through an array of classes and return the Doctrine_Records out of them. 
     568     * If you do not specify $classes it will return all of the currently loaded Doctrine_Records 
     569     * 
    538570     * @param $classes Array of classes to filter through, otherwise uses get_declared_classes() 
    539      * @return void 
     571     * @return array $loadedModels 
    540572     */ 
    541573    public static function getLoadedModels($classes = null) 
     
    549581        $loadedModels = array(); 
    550582         
    551         // we iterate trhough the diff of previously declared classes 
    552         // and currently declared classes 
    553         foreach ($classes as $name) { 
     583        foreach ((array) $classes as $name) { 
    554584            $class = new ReflectionClass($name); 
    555585             
     
    569599        return $loadedModels; 
    570600    } 
    571      
     601 
    572602    /** 
    573603     * getConnectionByTableName 
     
    576606     *  
    577607     * @param string $tableName  
    578      * @return void 
     608     * @return object Doctrine_Connection 
    579609     */ 
    580610    public static function getConnectionByTableName($tableName) 
     
    593623        return Doctrine_Manager::connection(); 
    594624    } 
    595      
     625 
    596626    /** 
    597627     * generateModelsFromDb 
     
    602632     * @param array $databases Array of databases to generate models for 
    603633     * @return boolean 
     634     * @throws Exception 
    604635     */ 
    605636    public static function generateModelsFromDb($directory, array $databases = array()) 
     
    607638        return Doctrine_Manager::connection()->import->importSchema($directory, $databases); 
    608639    } 
    609      
     640 
    610641    /** 
    611642     * generateYamlFromDb 
     
    631662        return $result; 
    632663    } 
     664 
    633665    /** 
    634666     * generateModelsFromYaml 
     
    647679        return $import->importSchema($yamlPath, 'yml', $directory); 
    648680    } 
    649      
     681 
    650682    /** 
    651683     * createTablesFromModels 
     
    660692        return Doctrine_Manager::connection()->export->exportSchema($directory); 
    661693    } 
    662      
     694 
    663695    /** 
    664696     * generateSqlFromModels 
    665697     * 
    666698     * @param string $directory  
    667      * @return void 
     699     * @return string $build  String of sql queries. One query per line 
    668700     */ 
    669701    public static function generateSqlFromModels($directory = null) 
     
    694726        return $export->exportSchema($yamlPath, 'yml', $directory); 
    695727    } 
    696      
     728 
    697729    /** 
    698730     * createDatabases 
     
    719751        } 
    720752    } 
    721      
     753 
    722754    /** 
    723755     * dropDatabases 
     
    744776        } 
    745777    } 
    746      
     778 
    747779    /** 
    748780     * dumpData 
     
    760792        return $data->exportData($yamlPath, 'yml', array(), $individualFiles); 
    761793    } 
    762      
     794 
    763795    /** 
    764796     * loadData 
     
    773805    public static function loadData($yamlPath, $append = false) 
    774806    { 
    775         $delete = isset($append) ? ($append ? false : true) : true; 
    776  
    777         if ($delete) 
    778         { 
    779             $models = Doctrine::getLoadedModels(); 
    780  
    781             foreach ($models as $model) 
    782             { 
    783                 $model = new $model(); 
    784  
    785                 $model->getTable()->createQuery()->delete($model)->execute(); 
    786             } 
    787         } 
    788  
    789807        $data = new Doctrine_Data(); 
    790808         
     809        if (!$append) { 
     810            $data->purge(); 
     811        } 
     812         
    791813        return $data->importData($yamlPath, 'yml'); 
    792814    } 
    793      
     815 
    794816    /** 
    795817     * loadDummyData 
     
    803825    public static function loadDummyData($append, $num = 5) 
    804826    { 
    805         $delete = isset($append) ? ($append ? false : true) : true; 
    806  
    807         if ($delete) 
    808         { 
    809           $models = Doctrine::getLoadedModels(); 
    810  
    811           foreach ($models as $model) 
    812           { 
    813             $model = new $model(); 
    814  
    815             $model->getTable()->createQuery()->delete($model)->execute(); 
    816           } 
    817         } 
    818          
    819827        $data = new Doctrine_Data(); 
     828 
     829        if (!$append) { 
     830          $data->purge(); 
     831        } 
    820832         
    821833        return $data->importDummyData($num); 
     
    829841     * @param string $migrationsPath Path to migrations directory which contains your migration classes 
    830842     * @param string $to Version you wish to migrate to. 
    831      * @return void 
     843     * @return bool true 
     844     * @throws new Doctrine_Migration_Exception 
    832845     */ 
    833846    public static function migrate($migrationsPath, $to = null) 
     
    837850        return $migration->migrate($to); 
    838851    } 
    839      
     852 
    840853    /** 
    841854     * generateMigrationClass 
     
    845858     * @param string $className Name of the Migration class to generate 
    846859     * @param string $migrationsPath Path to directory which contains your migration classes 
    847      * @package default 
    848860     */ 
    849861    public static function generateMigrationClass($className, $migrationsPath) 
     
    853865        return $builder->generateMigrationClass($className); 
    854866    } 
    855      
     867 
    856868    /** 
    857869     * generateMigrationsFromDb 
     
    859871     * @param string $migrationsPath  
    860872     * @return void 
     873     * @throws new Doctrine_Migration_Exception 
    861874     */ 
    862875    public static function generateMigrationsFromDb($migrationsPath) 
     
    866879        return $builder->generateMigrationsFromDb(); 
    867880    } 
    868      
     881 
    869882    /** 
    870883     * generateMigrationsFromModels 
     
    902915    { 
    903916        return Doctrine_Manager::connection($adapter, $name); 
     917    } 
     918     
     919    /** 
     920     * fileFinder 
     921     * 
     922     * @param string $type  
     923     * @return void 
     924     */ 
     925    public static function fileFinder($type) 
     926    { 
     927        return Doctrine_FileFinder::type($type); 
    904928    } 
    905929