Changeset 420
- Timestamp:
- 10/22/07 08:37:24 (1 year ago)
- Files:
-
- trunk/lib/AkActionController.php (modified) (1 diff)
- trunk/lib/AkActiveRecord.php (modified) (2 diffs)
- trunk/lib/AkActiveRecord/AkHasAndBelongsToMany.php (modified) (4 diffs)
- trunk/lib/AkActiveRecord/AkHasMany.php (modified) (1 diff)
- trunk/lib/AkInflector.php (modified) (3 diffs)
- trunk/lib/AkUnitTest.php (modified) (1 diff)
- trunk/script/migrate (modified) (2 diffs)
- trunk/test/unit/lib/AkInflector.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/AkActionController.php
r412 r420 872 872 foreach (get_included_files() as $file_name){ 873 873 if(strstr($file_name,AK_CONTROLLERS_DIR)){ 874 $controllers[] = AkInflector:: modulize(str_replace(array(AK_CONTROLLERS_DIR.DS,'.php'),'',$file_name));874 $controllers[] = AkInflector::classify(str_replace(array(AK_CONTROLLERS_DIR.DS,'.php', DS, '//'),array('','','/', '/'),$file_name)); 875 875 } 876 876 } trunk/lib/AkActiveRecord.php
r408 r420 1655 1655 $available_types = array_merge(array($this->getModelName()),$this->getSubclasses()); 1656 1656 foreach ($available_types as $subclass){ 1657 $type_condition[] = ' '.$table_name.'.'.$inheritance_column.' = \''.AkInflector:: demodulize($subclass).'\' ';1657 $type_condition[] = ' '.$table_name.'.'.$inheritance_column.' = \''.AkInflector::humanize(AkInflector::underscore($subclass)).'\' '; 1658 1658 } 1659 1659 return empty($type_condition) ? '' : '('.join('OR',$type_condition).') '; … … 1783 1783 } 1784 1784 $value = $this->{'get'.AkInflector::camelize($attribute)}(); 1785 return $this->getInheritanceColumn() === $attribute ? AkInflector:: demodulize($value) : $value;1785 return $this->getInheritanceColumn() === $attribute ? AkInflector::humanize(AkInflector::underscore($value)) : $value; 1786 1786 } 1787 1787 if(isset($this->$attribute) || (!isset($this->$attribute) && $this->isCombinedAttribute($attribute))){ trunk/lib/AkActiveRecord/AkHasAndBelongsToMany.php
r336 r420 118 118 { 119 119 $default_options = array( 120 'class_name' => empty($options['class_name']) ? AkInflector:: modulize($association_id) : $options['class_name'],120 'class_name' => empty($options['class_name']) ? AkInflector::classify($association_id) : $options['class_name'], 121 121 'table_name' => false, 122 122 'join_table' => false, … … 158 158 159 159 $options['join_table'] = empty($options['join_table']) ? join('_', $join_tables) : $options['join_table']; 160 $options['join_class_name'] = empty($options['join_class_name']) ? join(array_map(array('AkInflector',' modulize'),array_map(array('AkInflector','singularize'), $join_tables))) : $options['join_class_name'];160 $options['join_class_name'] = empty($options['join_class_name']) ? join(array_map(array('AkInflector','classify'),array_map(array('AkInflector','singularize'), $join_tables))) : $options['join_class_name']; 161 161 $options['foreign_key'] = empty($options['foreign_key']) ? AkInflector::underscore($owner_name).'_id' : $options['foreign_key']; 162 162 $options['association_foreign_key'] = empty($options['association_foreign_key']) ? AkInflector::underscore($associated_name).'_id' : $options['association_foreign_key']; … … 554 554 { 555 555 if(!$this->Owner->isNewRecord()){ 556 $success = true; 556 557 $options = $this->getOptions($this->association_id); 557 558 if(strtolower($options['join_class_name']) != strtolower(get_class($this->JoinObject))){ … … 570 571 $this->JoinObject =& $this->JoinObject->create(array($options['foreign_key']=> $foreign_key, $options['association_foreign_key']=> $association_foreign_key)); 571 572 $success = !$this->JoinObject->isNewRecord(); 572 }else{573 $success = true;574 573 } 575 574 } trunk/lib/AkActiveRecord/AkHasMany.php
r328 r420 87 87 88 88 $default_options = array( 89 'class_name' => empty($options['class_name']) ? AkInflector:: modulize($association_id) : $options['class_name'],89 'class_name' => empty($options['class_name']) ? AkInflector::classify($association_id) : $options['class_name'], 90 90 'conditions' => false, 91 91 'order' => false, trunk/lib/AkInflector.php
r318 r420 374 374 375 375 /** 376 * Converts a table name to its class name according to rails376 * Converts a table name to its class name according to Akelos 377 377 * naming conventions. 378 378 * … … 426 426 // }}} 427 427 428 428 /** 429 * Removes the module name from a module/path, Module::name or Module_ControllerClassName. 430 * 431 * Example: AkInflector::demodulize('admin/dashboard_controller'); //=> dashboard_controller 432 * AkInflector::demodulize('Admin_DashboardController'); //=> DashboardController 433 * AkInflector::demodulize('Admin::Dashboard'); //=> Dashboard 434 */ 429 435 function demodulize($module_name) 430 436 { 431 $module_name = preg_replace('/^.*::/','',$module_name); 432 return AkInflector::humanize(AkInflector::underscore($module_name)); 433 } 434 435 function modulize($module_description) 436 { 437 return AkInflector::camelize(AkInflector::singularize($module_description)); 438 } 439 440 437 return (strstr($module_name, '/') || strstr($module_name, '::') ? preg_replace('/^.*(::|\/)/', '', $module_name) : substr($module_name, 1+strrpos($module_name,'_'))); 438 } 439 441 440 /** 442 441 * Transforms a string to its unaccented version. … … 472 471 function foreignKey($class_name, $separate_class_name_and_id_with_underscore = true) 473 472 { 474 return AkInflector::underscore(AkInflector:: demodulize($class_name)).($separate_class_name_and_id_with_underscore ? "_id" : "id");473 return AkInflector::underscore(AkInflector::humanize(AkInflector::underscore($class_name))).($separate_class_name_and_id_with_underscore ? "_id" : "id"); 475 474 } 476 475 trunk/lib/AkUnitTest.php
r388 r420 81 81 continue; 82 82 } 83 $class_name = AkInflector:: modulize($table);83 $class_name = AkInflector::classify($table); 84 84 if($this->instantiateModel($class_name)){ 85 85 $items = Ak::convert('yaml','array',file_get_contents($file)); trunk/script/migrate
r392 r420 31 31 require_once(AK_LIB_DIR.DS.'utils'.DS.'generators'.DS.'AkelosGenerator.php'); 32 32 33 $installer_name = AkInflector::camelize(array_shift($options)).'Installer'; 33 $installer = array_shift($options); 34 $installer_class_name = AkInflector::camelize(AkInflector::demodulize($installer)).'Installer'; 34 35 $command = count($options) > 0 ? array_shift($options) : 'usage'; 35 36 36 37 37 $file = AK_APP_DIR.DS.'installers'.DS. AkInflector::underscore($installer_name).'.php';38 $file = AK_APP_DIR.DS.'installers'.DS.rtrim(join('/',array_map(array('AkInflector','underscore'), explode('/',$installer.'/'))),'/').'_installer.php'; 38 39 39 if($installer_ name == 'Installer'){40 if($installer_class_name == 'Installer'){ 40 41 $files = Ak::dir(AK_APP_DIR.DS.'installers'); 41 42 if(empty($files)){ … … 57 58 }else{ 58 59 require_once($file); 59 if(!class_exists($installer_ name)){60 if(!class_exists($installer_class_name)){ 60 61 echo Ak::t("\n\n Could not find load the installer. Class doesn't exists\n\n"); 61 62 }else{ 62 $installer = new $installer_ name();63 $installer = new $installer_class_name(); 63 64 if(!method_exists($installer,$command)){ 64 65 echo Ak::t("\n\n Could not find the method %method for the installer %installer\n\n", 65 array('%method'=>$command,'%installer'=>$installer_ name));66 array('%method'=>$command,'%installer'=>$installer_class_name)); 66 67 }else{ 67 68 $installer->$command($options); trunk/test/unit/lib/AkInflector.php
r318 r420 299 299 } 300 300 } 301 302 function test_should_demodulize() 303 { 304 $this->assertEqual(AkInflector::demodulize('admin/dashboard_controller'), 'dashboard_controller'); 305 $this->assertEqual(AkInflector::demodulize('Admin_DashboardController'), 'DashboardController'); 306 $this->assertEqual(AkInflector::demodulize('Admin::Dashboard'), 'Dashboard'); 307 } 301 308 302 309 }
