Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fORM.php
r480 r499 Hide Line Numbers 10 10 * @link http://flourishlib.com/fORM 11 11 * 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] 13 14 * @changes 1.0.0b4 Fixed a bug with retrieving fActiveRecord methods registered for all classes [wb, 2009-01-14] 14 15 * @changes 1.0.0b3 Fixed a static method callback constant [wb, 2008-12-17] … … 19 20 { 20 21 // The following constants allow for nice looking callbacks to static methods 21 const addCustom TableClassMapping = 'fORM::addCustomTableClassMapping';22 const addCustomClassTableMapping = 'fORM::addCustomClassTableMapping'; 22 23 const callHookCallbacks = 'fORM::callHookCallbacks'; 23 24 const callReflectCallbacks = 'fORM::callReflectCallbacks'; … … 55 56 56 57 /** 58 * Custom mappings for class <-> table 59 * 60 * @var array 61 */ 62 static private $class_table_map = array(); 63 64 /** 57 65 * Custom column names for columns in fActiveRecord classes 58 66 * … … 110 118 static private $scalarize_callbacks = array(); 111 119 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 122 123 * 123 124 * By default, all database tables are assumed to be plural nouns in 124 125 * `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 128 130 * @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; 135 136 } 136 137 … … 276 277 static public function classize($table) 277 278 { 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; 282 285 } 283 286 … … 841 844 static public function reset() 842 845 { 846 self::$class_table_map = array(); 843 847 self::$active_record_method_callbacks = array(); 844 848 self::$column_names = array(); 845 self::$configured = array();846 849 self::$hook_callbacks = array(); 847 self::$identity_map = array();848 850 self::$objectify_callbacks = array(); 849 851 self::$record_names = array(); … … 852 854 self::$replicate_callbacks = array(); 853 855 self::$scalarize_callbacks = array(); 854 self::$table_class_map = array();855 856 } 856 857 … … 894 895 $class = self::getClass($class); 895 896 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]; 902 901 } 903 902
