Changeset 421

Show
Ignore:
Timestamp:
10/22/07 16:44:02 (1 year ago)
Author:
bermiferrer
Message:

Rearranging scripts to reduce the hassle of updating local application whenever scripts change.

Preparing generators to work with modules.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGELOG.txt

    r413 r421  
    11SVN 
    22---------------------- 
     3* Removed AkInflector::modulize as it had a misleading name, use AkInflector::classify instead [420] 
    34 
    45* Added support for HTTP Authentication [412]. Example: 
  • trunk/lib/AkInflector.php

    r420 r421  
    435435    function demodulize($module_name) 
    436436    { 
    437         return (strstr($module_name, '/') || strstr($module_name, '::') ? preg_replace('/^.*(::|\/)/', '', $module_name) : substr($module_name, 1+strrpos($module_name,'_'))); 
     437        $module_name = str_replace('::', '/', $module_name); 
     438        return (strstr($module_name, '/') ? preg_replace('/^.*\//', '', $module_name) : (strstr($module_name, '_') ? substr($module_name, 1+strrpos($module_name,'_')) : $module_name)); 
    438439    } 
    439440     
     
    476477    function toControllerFilename($name) 
    477478    { 
    478         return AK_CONTROLLERS_DIR.DS.AkInflector::underscore($name).'_controller.php'; 
     479        $name = str_replace('::', '/', $name); 
     480        return AK_CONTROLLERS_DIR.DS.join(DS, array_map(array('AkInflector','underscore'), strstr($name, '/') ? explode('/', $name) : array($name))).'_controller.php'; 
    479481    } 
    480482 
  • trunk/lib/utils/generators/scaffold/scaffold_generator.php

    r390 r421  
    2828        $this->controller_name = empty($this->controller_name) ? $this->model_name : (AkInflector::camelize($this->controller_name)); 
    2929        $this->controller_file_path = AkInflector::toControllerFilename($this->controller_name); 
    30         $this->controller_class_name = $this->controller_name.'Controller'; 
     30        $this->controller_class_name = str_replace(array('/','::'),'_', $this->controller_name.'Controller'); 
     31        $this->controller_name = AkInflector::demodulize($this->controller_name); 
    3132        $this->controller_human_name = AkInflector::humanize($this->controller_name); 
    3233        $this->helper_var_name = '$'.AkInflector::underscore($this->controller_name).'_helper'; 
     
    3637        $this->singular_controller_name = AkInflector::underscore($this->controller_name); 
    3738 
     39        $this->module_preffix = AkInflector::underscore(substr($this->controller_class_name, 0, strrpos($this->controller_class_name, '_'))); 
     40        $this->module_preffix = empty($this->module_preffix) ? '' : DS.$this->module_preffix;     
     41                 
     42         
    3843        $this->files = array( 
    3944        'controller.php' => $this->controller_file_path, 
     
    4247         */ 
    4348        // 'functional_test.php' => AK_TEST_DIR.DS.'functional'.DS.'test_'.$this->controller_class_name.'.php', 
    44         'helper.php' => AK_HELPERS_DIR.DS.trim($this->helper_var_name,'$').'.php', 
     49        'helper.php' => AK_HELPERS_DIR.$this->module_preffix.DS.trim($this->helper_var_name,'$').'.php', 
    4550        'layout' => AK_VIEWS_DIR.DS.'layouts'.DS.$this->singular_controller_name.'.tpl', 
    46         'view_add' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'add.tpl', 
    47         'view_destroy' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'destroy.tpl', 
    48         'view_edit' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'edit.tpl', 
    49         'view_listing' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'listing.tpl', 
    50         'view_show' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'show.tpl', 
    51         'form' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'_form.tpl', 
     51        'view_add' => AK_VIEWS_DIR.$this->module_preffix.DS.$this->singular_controller_name.DS.'add.tpl', 
     52        'view_destroy' => AK_VIEWS_DIR.$this->module_preffix.DS.$this->singular_controller_name.DS.'destroy.tpl', 
     53        'view_edit' => AK_VIEWS_DIR.$this->module_preffix.DS.$this->singular_controller_name.DS.'edit.tpl', 
     54        'view_listing' => AK_VIEWS_DIR.$this->module_preffix.DS.$this->singular_controller_name.DS.'listing.tpl', 
     55        'view_show' => AK_VIEWS_DIR.$this->module_preffix.DS.$this->singular_controller_name.DS.'show.tpl', 
     56        'form' => AK_VIEWS_DIR.$this->module_preffix.DS.$this->singular_controller_name.DS.'_form.tpl', 
    5257        ); 
    53  
     58         
    5459        $this->user_actions = array(); 
    5560        foreach ((array)@$this->actions as $action){ 
    56             $this->user_actions[$action] = AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.$action.'.tpl'; 
     61            $this->user_actions[$action] = AK_VIEWS_DIR.$this->module_preffix.DS.$this->singular_controller_name.DS.$action.'.tpl'; 
    5762        } 
     63         
    5864    } 
    5965 
     
    7480        $model_files = array( 
    7581        'model'=>$this->model_file_path, 
    76         'installer'=>AK_APP_DIR.DS.'installers'.DS.$this->singular_name.'_installer.php', 
     82        'installer'=>AK_APP_DIR.DS.'installers'.$this->module_preffix.DS.$this->singular_name.'_installer.php', 
    7783        'model_unit_test'=>AK_TEST_DIR.DS.'unit'.DS.'app'.DS.'models'.DS.$this->singular_name.'.php', 
    7884        'model_fixture'=>    AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.'models'.DS.$this->singular_name.'.php', 
    79         'installer_fixture'=>AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.'installers'.DS.$this->singular_name.'_installer.php' 
     85        'installer_fixture'=>AK_TEST_DIR.DS.'fixtures'.DS.'app'.DS.'installers'.$this->module_preffix.DS.$this->singular_name.'_installer.php' 
    8086        ); 
    81  
     87         
    8288        $this->_template_vars = (array)$this; 
    8389        foreach ($model_files as $template=>$file_path){ 
  • trunk/script/console

    r392 r421  
    11#!/usr/bin/env php 
    22<?php 
    3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
    4  
    5 // +----------------------------------------------------------------------+ 
    6 // | Akelos Framework - http://www.akelos.org                             | 
    7 // +----------------------------------------------------------------------+ 
    8 // | Copyright (c) 2002-2006, Akelos Media, S.L.  & Bermi Ferrer Martinez | 
    9 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 
    10 // +----------------------------------------------------------------------+ 
    11  
    12 /** 
    13  * @package ActiveSupport 
    14  * @subpackage Scripts 
    15  * @author Bermi Ferrer <bermi a.t akelos c.om> 
    16  * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 
    17  * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 
    18  */ 
    193 
    204ob_start('ob_logstdout', 2); 
    215 
    226define('AK_CONSOLE_MODE', true); 
     7define('AK_ENABLE_AKELOS_ARGS', true);  
    238defined('AK_ENVIRONMENT') ? null : define('AK_ENVIRONMENT', 'development'); 
    24 define('AK_ENABLE_AKELOS_ARGS', true);  
    259include(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); 
    26  
    27 error_reporting(defined('AK_ERROR_REPORTING_ON_SCRIPTS') ? AK_ERROR_REPORTING_ON_SCRIPTS : 0); 
    28  
    29 require_once(AK_LIB_DIR.DS.'Ak.php'); 
    30 require_once(AK_LIB_DIR.DS.'AkObject.php'); 
    31 require_once(AK_LIB_DIR.DS.'AkInflector.php'); 
    32 require_once(AK_LIB_DIR.DS.'AkPhpParser.php'); 
    33  
    34 defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ? ($dsn='') : Ak::db(&$dsn); 
    35 defined('AK_RECODE_UTF8_ON_CONSOLE_TO') ? null : define('AK_RECODE_UTF8_ON_CONSOLE_TO', false); 
    36  
    37 require_once(AK_LIB_DIR.DS.'AkActiveRecord.php'); 
    38 require_once(AK_APP_DIR.DS.'shared_model.php'); 
    39 require_once(AK_LIB_DIR.DS.'utils'.DS.'generators'.DS.'AkelosGenerator.php'); 
    40 require_once(AK_LIB_DIR.DS.'AkInstaller.php'); 
     10require_once(AK_LIB_DIR.DS.'utils'.DS.'scripts'.DS.'console.php'); 
    4111 
    4212 
    43 if ($id_dir = opendir(AK_MODELS_DIR.DS)){ 
    44     while (false !== ($file = readdir($id_dir))){ 
    45         if ($file != "." && $file != ".." && $file != '.svn' && $file[0] != '_' && substr($file,-12,8) != '_service'){ 
    46             if(!is_dir(AK_MODELS_DIR.DS.$file)){ 
    47                 include_once(AK_MODELS_DIR.DS.$file); 
    48             } 
    49         } 
    50     } 
    51     closedir($id_dir); 
    52 } 
    53  
    54 define('AK_PROMT',fopen("php://stdin","r")); 
    55  
    56 $join_command = false; 
    57 $promt_line = ">>> "; 
    58 while(true){ 
    59     if(empty($__promt_for_command)){ 
    60         $__promt_for_command = true; 
    61         echo "\nWelcome to the Akelos Framework Interactive Console\n\n>> "; 
    62     } 
    63  
    64     $command = ($join_command ? $command : '').fgets(AK_PROMT,25600); 
    65  
    66     if(substr(trim($command,"\n\r "), -1) == '\\'){ 
    67         $command = rtrim($command, "\\\n\r"); 
    68         $join_command = true; 
    69         echo "... "; 
    70         continue; 
    71     }else{ 
    72         $join_command = false; 
    73     } 
    74  
    75     switch (trim(strtolower($command),"\n\r\t ();")) { 
    76         case 'exit': 
    77         case 'die': 
    78         fclose(AK_PROMT); 
    79         exit; 
    80         break; 
    81  
    82         case '': 
    83         echo "... "; 
    84         break; 
    85  
    86         case '<': 
    87         $command = $last_command; 
    88         echo "running command: ".$command; 
    89  
    90         default: 
    91  
    92         $last_command = $command; 
    93  
    94         $_script_name = array_shift(explode(' ',trim($command).' ')); 
    95          
    96         $_script_file_name = AK_OS == 'WINDOWS' ? $_script_name : dirname(__FILE__).DS.$_script_name; 
    97  
    98         if (file_exists($_script_file_name)){ 
    99              
    100             $command = trim(substr(trim($command),strlen($_script_name))); 
    101                 echo "\n"; 
    102                 passthru((AK_OS == 'WINDOWS' ? 'php -q ':'').$_script_file_name.' '.escapeshellcmd($command)); 
    103                 echo "\n>>> "; 
    104  
    105         }else{ 
    106  
    107             ob_start(); 
    108             $parser = new AkPhpParser($command); 
    109             echo $parser->parse() === 0 ? '' : "..."; 
    110             if(!$parser->hasErrors()){ 
    111                 eval($parser->code); 
    112             }else{ 
    113                 echo "\nPHP Error: \n".join("\n", $parser->getErrors())."\n"; 
    114             } 
    115  
    116             $result = ob_get_contents(); 
    117             ob_end_clean(); 
    118  
    119             $result = strstr($result,": eval()") ? 
    120             strip_tags(array_shift(explode(': eval()',$result))) : 
    121             $result; 
    122  
    123             Ak::file_add_contents(AK_LOG_DIR.DS.'command_line.log',$promt_line.$command."\n".$result."\n"); 
    124             echo empty($result) ? $promt_line : "\n". 
    125             (AK_RECODE_UTF8_ON_CONSOLE_TO ? Ak::recode($result, AK_RECODE_UTF8_ON_CONSOLE_TO) : $result). 
    126             "\n\n$promt_line"; 
    127         } 
    128         break; 
    129     } 
    130 } 
    131 fclose(AK_PROMT); 
    13213 
    13314?> 
  • trunk/script/generate

    r339 r421  
    11#!/usr/bin/env php 
    22<?php 
    3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
    4  
    5 // +----------------------------------------------------------------------+ 
    6 // | Akelos Framework - http://www.akelos.org                             | 
    7 // +----------------------------------------------------------------------+ 
    8 // | Copyright (c) 2002-2006, Akelos Media, S.L.  & Bermi Ferrer Martinez | 
    9 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 
    10 // +----------------------------------------------------------------------+ 
    11  
    12 /** 
    13  * @package AkelosFramework 
    14  * @subpackage Generators 
    15  * @author Bermi Ferrer <bermi a.t akelos c.om> 
    16  * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 
    17  * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 
    18  */ 
    193 
    204defined('AK_ENVIRONMENT') ? null : define('AK_ENVIRONMENT', 'development'); 
    215include(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); 
    22 error_reporting(defined('AK_ERROR_REPORTING_ON_SCRIPTS') ? AK_ERROR_REPORTING_ON_SCRIPTS : 0); 
    23 require_once(AK_LIB_DIR.DS.'Ak.php'); 
    24 require_once(AK_LIB_DIR.DS.'AkObject.php'); 
    25 require_once(AK_LIB_DIR.DS.'AkInflector.php'); 
    26 defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ? ($dsn='') : Ak::db(&$dsn); 
    27 array_shift($argv); 
    28 $command = join(' ',$argv); 
    29  
    30 require_once(AK_LIB_DIR.DS.'utils'.DS.'generators'.DS.'AkelosGenerator.php'); 
    31  
    32 $Generator = new AkelosGenerator(); 
    33 $Generator->runCommand($command); 
    34  
    35 echo "\n"; 
     6require_once(AK_LIB_DIR.DS.'utils'.DS.'scripts'.DS.'generate.php'); 
    367 
    378?> 
  • trunk/script/migrate

    r420 r421  
    11#!/usr/bin/env php 
    22<?php 
    3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
    4  
    5 // +----------------------------------------------------------------------+ 
    6 // | Akelos Framework - http://www.akelos.org                             | 
    7 // +----------------------------------------------------------------------+ 
    8 // | Copyright (c) 2002-2006, Akelos Media, S.L.  & Bermi Ferrer Martinez | 
    9 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 
    10 // +----------------------------------------------------------------------+ 
    11  
    12 /** 
    13  * @package ActiveSupport 
    14  * @subpackage Scripts 
    15  * @author Bermi Ferrer <bermi a.t akelos c.om> 
    16  * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 
    17  * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 
    18  */ 
    193 
    204defined('AK_ENVIRONMENT') ? null : define('AK_ENVIRONMENT', 'development'); 
    215include(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); 
    22 error_reporting(defined('AK_ERROR_REPORTING_ON_SCRIPTS') ? AK_ERROR_REPORTING_ON_SCRIPTS : 0); 
    23 require_once(AK_LIB_DIR.DS.'Ak.php'); 
    24 require_once(AK_LIB_DIR.DS.'AkObject.php'); 
    25 require_once(AK_LIB_DIR.DS.'AkInflector.php'); 
    26 defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ? ($dsn='') : Ak::db(&$dsn); 
    27 array_shift($argv); 
    28 $options = $argv; 
    29  
    30 require_once(AK_LIB_DIR.DS.'AkInstaller.php'); 
    31 require_once(AK_LIB_DIR.DS.'utils'.DS.'generators'.DS.'AkelosGenerator.php'); 
    32  
    33 $installer = array_shift($options); 
    34 $installer_class_name = AkInflector::camelize(AkInflector::demodulize($installer)).'Installer'; 
    35 $command = count($options) > 0 ? array_shift($options) : 'usage'; 
    36  
    37  
    38 $file = AK_APP_DIR.DS.'installers'.DS.rtrim(join('/',array_map(array('AkInflector','underscore'), explode('/',$installer.'/'))),'/').'_installer.php'; 
    39  
    40 if($installer_class_name == 'Installer'){ 
    41     $files = Ak::dir(AK_APP_DIR.DS.'installers'); 
    42     if(empty($files)){ 
    43         echo Ak::t("\n  Could not find installers at %dir  \n", array('%dir'=>AK_APP_DIR.DS.'installers')); 
    44  
    45     }else{ 
    46         echo Ak::t("\n  You must supply a valid installer name like : \n"); 
    47         echo Ak::t("\n  > ./script/migrate my_installer_name install\n\n"); 
    48         echo Ak::t("  Available installers are:  \n\n"); 
    49         foreach($files as $file){ 
    50             if(preg_match('/(.*)_installer\.php$/', $file, $match)){ 
    51                 echo ' * '.$match[1]."\n"; 
    52             }         
    53         } 
    54         echo "\n"; 
    55     } 
    56 }elseif(!file_exists($file)){ 
    57     echo Ak::t("\n\n  Could not locate the installer file %file\n\n",array('%file'=>$file)); 
    58 }else{ 
    59     require_once($file); 
    60     if(!class_exists($installer_class_name)){ 
    61         echo Ak::t("\n\n  Could not find load the installer. Class doesn't exists\n\n"); 
    62     }else{ 
    63         $installer = new $installer_class_name(); 
    64         if(!method_exists($installer,$command)){ 
    65             echo Ak::t("\n\n  Could not find the method %method for the installer %installer\n\n", 
    66             array('%method'=>$command,'%installer'=>$installer_class_name)); 
    67         }else{ 
    68             $installer->$command($options); 
    69         } 
    70     } 
    71 
    72  
    73  
    74 echo "\n"; 
     6require_once(AK_LIB_DIR.DS.'utils'.DS.'scripts'.DS.__FILE__.'.php'); 
    757 
    768?> 
  • trunk/script/plugin

    r392 r421  
    11#!/usr/bin/env php 
    22<?php 
    3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
    4  
    5 // +----------------------------------------------------------------------+ 
    6 // | Akelos Framework - http://www.akelos.org                             | 
    7 // +----------------------------------------------------------------------+ 
    8 // | Copyright (c) 2002-2006, Akelos Media, S.L.  & Bermi Ferrer Martinez | 
    9 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 
    10 // +----------------------------------------------------------------------+ 
    11  
    12 /** 
    13  * @package ActiveSupport 
    14  * @subpackage Scripts 
    15  * @author Bermi Ferrer <bermi a.t akelos c.om> 
    16  * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 
    17  * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 
    18  */ 
    193 
    204defined('AK_ENVIRONMENT') ? null : define('AK_ENVIRONMENT', 'development'); 
    215include(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); 
    22 error_reporting(defined('AK_ERROR_REPORTING_ON_SCRIPTS') ? AK_ERROR_REPORTING_ON_SCRIPTS : 0); 
    23 require_once(AK_LIB_DIR.DS.'Ak.php'); 
    24 require_once(AK_LIB_DIR.DS.'AkObject.php'); 
    25 require_once(AK_LIB_DIR.DS.'AkInflector.php'); 
    26 require_once(AK_LIB_DIR.DS.'AkPlugin.php'); 
    27 require_once(AK_LIB_DIR.DS.'AkPlugin/AkPluginManager.php'); 
    28 defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ? ($dsn='') : Ak::db(&$dsn); 
    29  
    30 $ak_app_dir = AK_APP_DIR; 
    31 $script_name = array_shift($argv); 
    32 $command = strtolower(array_shift($argv)); 
    33 array_unshift($argv, $script_name); 
    34 $_SERVER['argv'] = $argv; 
    35  
    36 $available_commands = array('list', 'sources', 'source', 'unsource', 'discover', 'install', 'remove', 'info'); 
    37  
    38 if(!in_array($command, $available_commands)){ 
    39     echo <<<BANNER 
    40 Usage: {$script_name} command [OPTIONS] 
    41  
    42 Akelos plugin manager. 
    43  
    44 COMMANDS 
    45  
    46   discover   Discover plugin repositories. 
    47   list       List available plugins. 
    48   install    Install plugin(s) from known repositories or URLs. 
    49   update     Update installed plugins. 
    50   remove     Uninstall plugins. 
    51   source     Add a plugin source repository. 
    52   unsource   Remove a plugin repository. 
    53   sources    List currently configured plugin repositories. 
    54  
    55  
    56 EXAMPLES 
    57  
    58   Install a plugin: 
    59     {$script_name} install acts_as_versioned 
    60      
    61   Install a plugin from a subversion URL: 
    62     {$script_name} install http://svn.akelos.org/plugins/acts_as_versioned 
    63  
    64   Install a plugin and add a svn:externals entry to app/vendor/plugins 
    65     {$script_name} install -x acts_as_versioned 
    66  
    67   List all available plugins: 
    68     {$script_name} list 
    69  
    70   List plugins in the specified repository: 
    71     {$script_name} list --source=http://svn.akelos.org/plugins/ 
    72  
    73   Discover and prompt to add new repositories: 
    74     {$script_name} discover 
    75  
    76   Discover new repositories but just list them, don't add anything: 
    77     {$script_name} discover -l 
    78  
    79   Add a new repository to the source list: 
    80     {$script_name} source http://svn.akelos.org/plugins/ 
    81  
    82   Remove a repository from the source list: 
    83     {$script_name} unsource http://svn.akelos.org/plugins/ 
    84  
    85   Show currently configured repositories: 
    86     {$script_name} sources 
    87  
    88 BANNER; 
    89     exit; 
    90 
    91  
    92  
    93 set_time_limit(0); 
    94 error_reporting(E_ALL); 
    95  
    96 require_once (AK_VENDOR_DIR.DS.'pear'.DS.'Console'.DS.'Getargs.php'); 
    97 function get_console_options_for($description, $console_configuration) 
    98 
    99     global $script_name, $argv; 
    100  
    101     $args =& Console_Getargs::factory($console_configuration); 
    102     if (PEAR::isError($args)) { 
    103  
    104         $replacements = array( 
    105         '-p --parameters values(1-...)' => 'install  plugin_name,URL  ...', 
    106         'Usage: '.basename(__FILE__) =>"Usage: $script_name", 
    107         '[param1] ' => 'plugin_name PLUGIN_URL' 
    108         ); 
    109         echo "\n$description\n".str_repeat('-', strlen($description)+1)."\n"; 
    110         if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) { 
    111             echo str_replace(array_keys($replacements), array_values($replacements), 
    112             Console_Getargs::getHelp($console_configuration, null, $args->getMessage()))."\n"; 
    113         } else if ($args->getCode() === CONSOLE_GETARGS_HELP) { 
    114             echo str_replace(array_keys($replacements), array_values($replacements), 
    115             @Console_Getargs::getHelp($console_configuration))."\n"; 
    116         } 
    117         exit; 
    118     } 
    119     return $args->getValues(); 
    120 
    121  
    122  
    123 $PluginManager = new AkPluginManager(); 
    124  
    125  
    126  
    127 /** 
    128  * List available plugins. 
    129  */ 
    130 if($command == 'list') { 
    131  
    132     $options = get_console_options_for('List available plugins.', array( 
    133     'source'    => array('short' => 's', 'desc' =>  "Use the specified plugin repositories. --source URL1 URL2", 'max'=> -1, 'min'=> 1), 
    134     'local'     => array('short' => 'l', 'desc' =>  "List locally installed plugins.", 'max' => 0), 
    135     'remote'    => array('short' => 'r', 'desc' =>  "List remotely available plugins. This is the default behavior", 'max' => 0) 
    136     )); 
    137  
    138     if(isset($options['local']) && isset($options['remote'])){ 
    139         die("Local and remote arguments can not be used simultaneously\n"); 
    140     } 
    141     if(!empty($options['source'])){ 
    142         $PluginManager->tmp_repositories = Ak::toArray($options['source']); 
    143     } 
    144     $installed_plugins = $PluginManager->getInstalledPlugins(); 
    145     if(isset($options['local'])){ 
    146         if(empty($installed_plugins)){ 
    147             die("There are not plugins intalled at {$ak_app_dir}/vendor/plugins\n"); 
    148         }else{ 
    149             echo "Plugins installed at  {$ak_app_dir}/vendor/plugins:\n\n"; 
    150             foreach ($installed_plugins as $plugin){ 
    151                 echo " * ".$plugin." (".rtrim($PluginManager->getRepositoryForPlugin($plugin),'/')."/$plugin)\n"; 
    152             } 
    153             die("\n"); 
    154         } 
    155     }else{ 
    156         $plugins = $PluginManager->getPlugins(true); 
    157         if(empty($plugins)){ 
    158             die("Could not find remote plugins\n"); 
    159         }else{ 
    160             $repsositories = array(); 
    161             foreach ($plugins as $plugin => $repository){ 
    162                 if(empty($repsositories[$repository])){ 
    163                     $repsositories[$repository] = array(); 
    164                 } 
    165                 if(in_array($plugin, $installed_plugins)){ 
    166                     array_unshift($repsositories[$repository], '[INSTALLED] '.$plugin); 
    167                 }else{ 
    168                     $repsositories[$repository][] = $plugin; 
    169                 } 
    170             } 
    171             foreach ($repsositories as $repsository=>$plugins){ 
    172                 echo "Plugins available at $repository:\n"; 
    173                 echo join(", ",$plugins)."\n\n"; 
    174             } 
    175         } 
    176     } 
    177     die(); 
    178 
    179  
    180  
    181  
    182 /** 
    183  * List configured plugin repositories. 
    184  */ 
    185 if($command == 'sources') { 
    186     $options = get_console_options_for('List configured plugin repositories.', array( 
    187     'check'     => array('short' => 'c', 'desc' =>  "Report status of repository.", 'max' => 0) 
    188     )); 
    189     $repositories = $PluginManager->getAvailableRepositories(true); 
    190  
    191     foreach ($repositories as $repository){ 
    192         $checked = isset($options['check']) && !Ak::url_get_contents($repository, array('timeout'=>5)) ? ' [Connection timeout].' : ''; 
    193         echo " * $repository$checked\n"; 
    194     } 
    195     die(); 
    196 
    197  
    198  
    199  
    200  
    201 /** 
    202  * Adds a repository to the default search list. 
    203  */ 
    204 if($command == 'source') { 
    205     array_shift($argv); 
    206     $options = Ak::toArray($argv); 
    207  
    208     if(empty($options)){ 
    209         die("You need to provide at least one repository to add to the default search list.\n"); 
    210     } 
    211  
    212     foreach ($options as $repository){ 
    213         if(Ak::url_get_contents($repository, array('timeout'=>10))){ 
    214             $PluginManager->addRepository($repository); 
    215             echo "Added: $repository\n"; 
    216         }else{ 
    217             echo "Not added: Connection error for repository $repository.\n"; 
    218         } 
    219     } 
    220     die(); 
    221 
    222  
    223  
    224  
    225  
    226 /** 
    227  * Removes a repository to the default search list. 
    228  */ 
    229 if($command == 'unsource') { 
    230     array_shift($argv); 
    231     $options = Ak::toArray($argv); 
    232  
    233     if(empty($options)){ 
    234         die("You need to provide at least one repository to remove from the default search list.\n"); 
    235     } 
    236  
    237     foreach ($options as $repository){ 
    238         $PluginManager->removeRepository($repository); 
    239         echo "Removed: $repository\n"; 
    240     } 
    241     die(); 
    242 
    243  
    244  
    245  
    246  
    247 /** 
    248  * Discover repositories referenced on a page. 
    249  */ 
    250 if($command == 'discover') { 
    251  
    252     $options = get_console_options_for('Discover repositories referenced on a page.', array( 
    253     'source'     => array('short' => 's', 'desc' =>  "Use the specified plugin repositories instead of the default.", 'max' => 1), 
    254     'list'     => array('short' => 'l', 'desc' =>  "List but don't prompt or add discovered repositories.", 'max' => 0), 
    255     'no-prompt'     => array('short' => 'n', 'desc' =>  "Add all new repositories without prompting.", 'max' => 0) 
    256     )); 
    257  
    258     if(!empty($options['source'])){ 
    259         $PluginManager->respository_discovery_page = $options['source']; 
    260     } 
    261  
    262     $repositories = $PluginManager->getDiscoveredRepositories(); 
    263     $default = 'Y'; 
    264  
    265     foreach ($repositories as $repository){ 
    266         echo "* $repository"; 
    267         if(!empty($options['list'])){ 
    268             echo "\n"; 
    269         }else{ 
    270             echo $default == 'Y' ? "[Y/n]:" : "[y/N]:"; 
    271  
    272             $key = trim(strtolower(fgetc(STDIN))); 
    273  
    274             if((empty($key) && $default == 'N') || $key == 'n'){ 
    275                 echo "Skipped $repository.\n"; 
    276                 $default = 'N'; 
    277             }elseif((empty($key) && $default == 'Y') || $key == 'y'){ 
    278                 if(Ak::url_get_contents($repository, array('timeout'=>10))){ 
    279                     $PluginManager->addRepository($repository); 
    280                     echo "Added $repository.\n"; 
    281                 }else{ 
    282                     echo "Not added: Connection error for repository $repository.\n"; 
    283                 } 
    284                 $default = 'Y'; 
    285             } 
    286  
    287             if(!empty($key)){ 
    288                 fgetc(STDIN); 
    289             } 
    290         } 
    291  
    292     } 
    293     die(); 
    294 
    295  
    296  
    297  
    298  
    299 /** 
    300  * Discover repositories referenced on a page. 
    301  */ 
    302 if($command == 'install') { 
    303  
    304     $options = get_console_options_for('Install one or more plugins.', array( 
    305     CONSOLE_GETARGS_PARAMS => array('short' => 'p', 'desc' =>  "You can specify plugin names as given in 'plugin list' output or absolute URLs to a plugin repository.", 'max' => -1, 'min' => 1), 
    306     'externals'     => array('short' => 'x', 'desc' =>  "Use svn:externals to grab the plugin. Enables plugin updates and plugin versioning.", 'max' => 0), 
    307     'checkout'     => array('short' => 'o', 'desc' =>  "Use svn checkout to grab the plugin. Enables updating but does not add a svn:externals entry.", 'max' => 0), 
    308     'revision'     => array('short' => 'r', 'desc' =>  "Checks out the given revision from subversion. Ignored if subversion is not used.", 'max' => 1, 'min' => 1), 
    309     'force'     => array('short' => 'f', 'desc' =>  "Reinstalls a plugin if it's already installed.", 'max' => 0), 
    310     )); 
    311  
    312     if(empty($options['parameters'])){ 
    313         die("You must supply at least one plugin name or plugin URL to install.\n"); 
    314     } 
    315  
    316     $best = $PluginManager->guessBestInstallMethod($options); 
    317     if($best == 'http' && (!empty($options['externals']) ||  !empty($options['checkout']))){ 
    318         die("Cannot install using subversion because `svn' cannot be found in your PATH\n"); 
    319     }elseif ($best == 'export' && !empty($options['externals'])){ 
    320         die("Cannot install using externals because this project is not under subversion."); 
    321     }elseif ($best == 'export' && !empty($options['checkout'])){ 
    322         die("Cannot install using checkout because this project is not under subversion."); 
    323     } 
    324  
    325     $plugins = Ak::toArray($options['parameters']); 
    326  
    327     foreach ($plugins as $plugin){ 
    328         $repository = null; 
    329         $plugin_name = basename($plugin); 
    330         if($plugin_name != $plugin){ 
    331             $repository = preg_replace('/\/?'.$plugin_name.'$/', '', trim($plugin)); 
    332         } 
    333         echo "\nInstalling $plugin\n"; 
    334         $PluginManager->installPlugin($plugin_name, $repository, $options); 
    335     } 
    336  
    337     echo "Done.\n"; 
    338     die(); 
    339 
    340  
    341  
    342  
    343  
    344 /** 
    345  * Remove plugins. 
    346  */ 
    347 if($command == 'remove') { 
    348  
    349     $options = get_console_options_for('Remove plugins.', array( 
    350     CONSOLE_GETARGS_PARAMS => array('short' => 'p', 'desc' =>  "You can specify plugin names as given in 'plugin list' output or absolute URLs to a plugin repository.", 'max' => -1, 'min' => 1))); 
    351  
    352     if(empty($options['parameters'])){ 
    353         die("You must supply at least one plugin name or plugin URL to uninstall.\n"); 
    354     } 
    355  
    356     $plugins = Ak::toArray($options['parameters']); 
    357  
    358     foreach ($plugins as $plugin){ 
    359         $plugin_name = basename($plugin); 
    360         echo "\nUninstalling $plugin\n"; 
    361         $PluginManager->uninstallPlugin($plugin_name); 
    362     } 
    363  
    364     echo "Done.\n"; 
    365     die(); 
    366 
    367  
    368  
    369  
    370  
    371 /** 
    372  * Shows plugin info at plugin_path/ABOUT. 
    373  */ 
    374 if($command == 'info') { 
    375  
    376     $options = get_console_options_for('Remove plugins.', array( 
    377     CONSOLE_GETARGS_PARAMS => array('short' => 'p', 'desc' =>  "Plugin names as given in 'plugin list' output or absolute URL to a plugin repository.", 'max' => 1, 'min' => 1))); 
    378  
    379     if(empty($options['parameters'])){ 
    380         die("You must supply a plugins name or plugin URL.\n"); 
    381     } 
    382  
    383     $plugin = $options['parameters']; 
    384     $plugin_name = basename($plugin); 
    385     if($plugin_name != $plugin){ 
    386         $repository = preg_replace('/\/?'.$plugin_name.'$/', '', trim($plugin)); 
    387     }else { 
    388         $repository = $PluginManager->getRepositoryForPlugin($plugin_name); 
    389     } 
    390  
    391     $about = Ak::url_get_contents(rtrim($repository,'/').'/'.$plugin_name.'/ABOUT', array('timeout'=>10)); 
    392     echo empty($about) ? "Could not get plugin information." : $about; 
    393  
    394     die("\n"); 
    395 
     6require_once(AK_LIB_DIR.DS.'utils'.DS.'scripts'.DS.'plugin.php'); 
    3967 
    3978?> 
  • trunk/script/test

    r392 r421  
    11#!/usr/bin/env php 
    22<?php 
    3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
    4  
    5 // +----------------------------------------------------------------------+ 
    6 // | Akelos Framework - http://www.akelos.org                             | 
    7 // +----------------------------------------------------------------------+ 
    8 // | Copyright (c) 2002-2006, Akelos Media, S.L.  & Bermi Ferrer Martinez | 
    9 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 
    10 // +----------------------------------------------------------------------+ 
    11  
    12 /** 
    13  * @package ActiveSupport 
    14  * @subpackage Scripts 
    15  * @author Bermi Ferrer <bermi a.t akelos c.om> 
    16  * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 
    17  * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 
    18  */ 
    19  
    203 
    214error_reporting(E_ALL); 
    22  
    235defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); 
    246defined('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION') ? null : define('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION', false); 
    25  
    267require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'test'.DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); 
    27  
    288$argv = array_map('trim',$argv); 
    299array_shift($argv); 
    30  
    3110$tests_dir = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'test'); 
    32 $____skip_tests = array('Simple','Unit','Web','AkWeb'); 
    33  
    34 foreach ($argv as $_test_file){ 
    35     $_test_file = strstr($_test_file,'.php') ? trim($_test_file, '/') : $_test_file.'.php'; 
    36     $_test_file = substr($_test_file,0,5) == 'test/' ? substr($_test_file,5) : $_test_file; 
    37     $_test_file = $tests_dir.DIRECTORY_SEPARATOR.$_test_file; 
    38     if(!file_exists($_test_file)){ 
    39         echo "\nCould not load $_test_file test file\n"; 
    40     }else{ 
    41         require($_test_file); 
    42             foreach(get_declared_classes() as $____class){ 
    43                 if(preg_match('/(.+)TestCase$/i', $____class, $match)){ 
    44                     if(!preg_match('/^('.join('|',$____skip_tests).')$/i',$match[1])){ 
    45                         $____skip_tests[] = $match[1]; 
    46                         ak_test($match[1].'TestCase', true); 
    47                     } 
    48                 } 
    49             } 
    50         echo $_test_file."\n"; 
    51     } 
    52 
    53  
    54  
    55  
     11require_once(AK_LIB_DIR.DS.'utils'.DS.'scripts'.DS.'test.php'); 
    5612 
    5713?> 
  • trunk/test/unit/lib/AkInflector.php

    r420 r421  
    305305        $this->assertEqual(AkInflector::demodulize('Admin_DashboardController'), 'DashboardController'); 
    306306        $this->assertEqual(AkInflector::demodulize('Admin::Dashboard'), 'Dashboard'); 
    307     } 
    308  
     307        $this->assertEqual(AkInflector::demodulize('User'), 'User'); 
     308    } 
     309 
     310    function test_should_get_controller_file_name() 
     311    { 
     312        $this->assertEqual(AkInflector::toControllerFilename('admin'), AK_CONTROLLERS_DIR.DS.'admin_controller.php'); 
     313        $this->assertEqual(AkInflector::toControllerFilename('user_authentication'), AK_CONTROLLERS_DIR.DS.'user_authentication_controller.php'); 
     314        $this->assertEqual(AkInflector::toControllerFilename('admin/users'), AK_CONTROLLERS_DIR.DS.'admin'.DS.'users_controller.php'); 
     315    } 
    309316} 
    310317