Changeset 420

Show
Ignore:
Timestamp:
10/22/07 08:37:24 (1 year ago)
Author:
bermiferrer
Message:

AkInflector::demodulize() has been modified so it converts Module_ClassName or ClassName? and module/path to path. Removed also repeated and unneeded AkInflector::modulize method, use AkInflector::classify instead. Closes #83

Fixing modules path on controller. Closes #82

Fixed un-initialized variable $success in habtm associations.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/AkActionController.php

    r412 r420  
    872872        foreach (get_included_files() as $file_name){ 
    873873            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)); 
    875875            } 
    876876        } 
  • trunk/lib/AkActiveRecord.php

    r408 r420  
    16551655         $available_types = array_merge(array($this->getModelName()),$this->getSubclasses()); 
    16561656         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)).'\' '; 
    16581658         } 
    16591659         return empty($type_condition) ? '' : '('.join('OR',$type_condition).') '; 
     
    17831783            } 
    17841784            $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; 
    17861786        } 
    17871787        if(isset($this->$attribute) || (!isset($this->$attribute) && $this->isCombinedAttribute($attribute))){ 
  • trunk/lib/AkActiveRecord/AkHasAndBelongsToMany.php

    r336 r420  
    118118    { 
    119119        $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'], 
    121121        'table_name' => false, 
    122122        'join_table' => false, 
     
    158158 
    159159        $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']; 
    161161        $options['foreign_key'] = empty($options['foreign_key']) ? AkInflector::underscore($owner_name).'_id' : $options['foreign_key']; 
    162162        $options['association_foreign_key'] = empty($options['association_foreign_key']) ? AkInflector::underscore($associated_name).'_id' : $options['association_foreign_key']; 
     
    554554    { 
    555555        if(!$this->Owner->isNewRecord()){ 
     556            $success = true; 
    556557            $options = $this->getOptions($this->association_id); 
    557558            if(strtolower($options['join_class_name']) != strtolower(get_class($this->JoinObject))){ 
     
    570571                    $this->JoinObject =& $this->JoinObject->create(array($options['foreign_key']=> $foreign_key, $options['association_foreign_key']=> $association_foreign_key)); 
    571572                    $success = !$this->JoinObject->isNewRecord(); 
    572                 }else{ 
    573                     $success = true; 
    574573                } 
    575574            } 
  • trunk/lib/AkActiveRecord/AkHasMany.php

    r328 r420  
    8787 
    8888        $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'], 
    9090        'conditions' => false, 
    9191        'order' => false, 
  • trunk/lib/AkInflector.php

    r318 r420  
    374374 
    375375    /** 
    376     * Converts a table name to its class name according to rail
     376    * Converts a table name to its class name according to Akelo
    377377    * naming conventions. 
    378378    *  
     
    426426    // }}} 
    427427 
    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    */ 
    429435    function demodulize($module_name) 
    430436    { 
    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     
    441440    /** 
    442441     * Transforms a string to its unaccented version.  
     
    472471    function foreignKey($class_name, $separate_class_name_and_id_with_underscore = true) 
    473472    { 
    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"); 
    475474    } 
    476475 
  • trunk/lib/AkUnitTest.php

    r388 r420  
    8181                continue; 
    8282            } 
    83             $class_name = AkInflector::modulize($table); 
     83            $class_name = AkInflector::classify($table); 
    8484            if($this->instantiateModel($class_name)){ 
    8585                $items = Ak::convert('yaml','array',file_get_contents($file)); 
  • trunk/script/migrate

    r392 r420  
    3131require_once(AK_LIB_DIR.DS.'utils'.DS.'generators'.DS.'AkelosGenerator.php'); 
    3232 
    33 $installer_name = AkInflector::camelize(array_shift($options)).'Installer'; 
     33$installer = array_shift($options); 
     34$installer_class_name = AkInflector::camelize(AkInflector::demodulize($installer)).'Installer'; 
    3435$command = count($options) > 0 ? array_shift($options) : 'usage'; 
    3536 
    3637 
    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'; 
    3839 
    39 if($installer_name == 'Installer'){ 
     40if($installer_class_name == 'Installer'){ 
    4041    $files = Ak::dir(AK_APP_DIR.DS.'installers'); 
    4142    if(empty($files)){ 
     
    5758}else{ 
    5859    require_once($file); 
    59     if(!class_exists($installer_name)){ 
     60    if(!class_exists($installer_class_name)){ 
    6061        echo Ak::t("\n\n  Could not find load the installer. Class doesn't exists\n\n"); 
    6162    }else{ 
    62         $installer = new $installer_name(); 
     63        $installer = new $installer_class_name(); 
    6364        if(!method_exists($installer,$command)){ 
    6465            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)); 
    6667        }else{ 
    6768            $installer->$command($options); 
  • trunk/test/unit/lib/AkInflector.php

    r318 r420  
    299299        } 
    300300    } 
     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    } 
    301308 
    302309}