root

Changeset 499

Show
Ignore:
Timestamp:
01/26/09 08:39:52 (2 years ago)
Author:
wbond
Message:

BackwardsCompatibilityBreak - renamed fORM::addCustomTableClassMapping() to fORM::addCustomClassTableMapping() and swapped the parameters

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fORM.php

    r480 r499 Hide Line Numbers
    1010 * @link       http://flourishlib.com/fORM 
    1111 *  
    12  * @version    1.0.0b4 
     12 * @version    1.0.0b5 
     13 * @changes    1.0.0b5  Backwards compatibility break - renamed ::addCustomTableClassMapping() to ::addCustomClassTableMapping() and swapped the parameters [wb, 2009-01-26] 
    1314 * @changes    1.0.0b4  Fixed a bug with retrieving fActiveRecord methods registered for all classes [wb, 2009-01-14] 
    1415 * @changes    1.0.0b3  Fixed a static method callback constant [wb, 2008-12-17] 
     
    1920{ 
    2021    // The following constants allow for nice looking callbacks to static methods 
    21     const addCustomTableClassMapping = 'fORM::addCustomTableClassMapping'; 
     22    const addCustomClassTableMapping = 'fORM::addCustomClassTableMapping'; 
    2223    const callHookCallbacks          = 'fORM::callHookCallbacks'; 
    2324    const callReflectCallbacks       = 'fORM::callReflectCallbacks'; 
     
    5556     
    5657    /** 
     58     * Custom mappings for class <-> table 
     59     *  
     60     * @var array 
     61     */ 
     62    static private $class_table_map = array(); 
     63     
     64    /** 
    5765     * Custom column names for columns in fActiveRecord classes 
    5866     *  
     
    110118    static private $scalarize_callbacks = array(); 
    111119     
    112     /** 
    113      * Custom mappings for table <-> class 
    114      *  
    115      * @var array 
    116      */ 
    117     static private $table_class_map = array(); 
    118      
    119      
    120     /** 
    121      * Allows non-standard table to class mapping 
     120     
     121    /** 
     122     * Allows non-standard class to table mapping 
    122123     *  
    123124     * By default, all database tables are assumed to be plural nouns in 
    124125     * `underscore_notation` and all class names are assumed to be singular 
    125      * nouns in `UpperCamelCase`. This method allows arbitrary table to  
    126      * class mapping. 
    127      *  
     126     * nouns in `UpperCamelCase`. This method allows arbitrary class to  
     127     * table mapping. 
     128     *  
     129     * @param  string $class  The name of the class 
    128130     * @param  string $table  The name of the database table 
    129      * @param  string $class  The name of the class 
    130      * @return void 
    131      */ 
    132     static public function addCustomTableClassMapping($table, $class) 
    133     { 
    134         self::$table_class_map[$table] = $class; 
     131     * @return void 
     132     */ 
     133    static public function addCustomClassTableMapping($class, $table) 
     134    { 
     135        self::$class_table_map[$class] = $table; 
    135136    } 
    136137     
     
    276277    static public function classize($table) 
    277278    { 
    278         if (!isset(self::$table_class_map[$table])) { 
    279             self::$table_class_map[$table] = fGrammar::camelize(fGrammar::singularize($table), TRUE); 
    280         } 
    281         return self::$table_class_map[$table]; 
     279        if (!$class = array_search($table, self::$class_table_map)) { 
     280            $class = fGrammar::camelize(fGrammar::singularize($table), TRUE); 
     281            self::$class_table_map[$class] = $table; 
     282        } 
     283         
     284        return $class; 
    282285    } 
    283286     
     
    841844    static public function reset() 
    842845    { 
     846        self::$class_table_map                = array(); 
    843847        self::$active_record_method_callbacks = array(); 
    844848        self::$column_names                   = array(); 
    845         self::$configured                     = array(); 
    846849        self::$hook_callbacks                 = array(); 
    847         self::$identity_map                   = array(); 
    848850        self::$objectify_callbacks            = array(); 
    849851        self::$record_names                   = array(); 
     
    852854        self::$replicate_callbacks            = array(); 
    853855        self::$scalarize_callbacks            = array(); 
    854         self::$table_class_map                = array(); 
    855856    } 
    856857     
     
    894895        $class = self::getClass($class); 
    895896         
    896         if (!$table = array_search($class, self::$table_class_map)) { 
    897             $table = fGrammar::underscorize(fGrammar::pluralize($class)); 
    898             self::$table_class_map[$table] = $class; 
    899         } 
    900          
    901         return $table; 
     897        if (!isset(self::$class_table_map[$class])) { 
     898            self::$class_table_map[$class] = fGrammar::underscorize(fGrammar::pluralize($class)); 
     899        } 
     900        return self::$class_table_map[$class]; 
    902901    } 
    903902