mirror of
https://github.com/yiisoft/yii.git
synced 2026-03-06 00:04:07 +01:00
merge from 1.0
This commit is contained in:
90
framework/cli/commands/shell/ModuleCommand.php
Normal file
90
framework/cli/commands/shell/ModuleCommand.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* ModuleCommand class file.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright © 2008-2009 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
* @version $Id: ModuleCommand.php 433 2008-12-30 22:59:17Z qiang.xue $
|
||||
*/
|
||||
|
||||
/**
|
||||
* ModuleCommand generates a controller class.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @version $Id: ModuleCommand.php 433 2008-12-30 22:59:17Z qiang.xue $
|
||||
* @package system.cli.commands.shell
|
||||
* @since 1.0.3
|
||||
*/
|
||||
class ModuleCommand extends CConsoleCommand
|
||||
{
|
||||
/**
|
||||
* @var string the template file for the controller class.
|
||||
* Defaults to null, meaning using 'framework/cli/views/shell/controller/controller.php'.
|
||||
*/
|
||||
public $templateFile;
|
||||
|
||||
public function getHelp()
|
||||
{
|
||||
return <<<EOD
|
||||
USAGE
|
||||
module <module-ID>
|
||||
|
||||
DESCRIPTION
|
||||
This command generates an application module.
|
||||
|
||||
PARAMETERS
|
||||
* module-ID: required, module ID. It is case-sensitive.
|
||||
|
||||
EOD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the action.
|
||||
* @param array command line parameters specific for this command
|
||||
*/
|
||||
public function run($args)
|
||||
{
|
||||
if(!isset($args[0]))
|
||||
{
|
||||
echo "Error: module ID is required.\n";
|
||||
echo $this->getHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
$moduleID=$args[0];
|
||||
$moduleClass=ucfirst($moduleID).'Module';
|
||||
$modulePath=Yii::app()->getModulePath().DIRECTORY_SEPARATOR.$moduleID;
|
||||
|
||||
$sourceDir=realpath(dirname(__FILE__).'/../../views/shell/module');
|
||||
if($sourceDir===false)
|
||||
die('Unable to locate the source directory.');
|
||||
$list=$this->buildFileList($sourceDir,$modulePath);
|
||||
$list['module.php']['target']=$modulePath.DIRECTORY_SEPARATOR.$moduleClass.'.php';
|
||||
$list['module.php']['callback']=array($this,'generateModuleClass');
|
||||
$list['module.php']['params']=array('moduleClass'=>$moduleClass);
|
||||
$list[$moduleClass.'.php']=$list['module.php'];
|
||||
unset($list['module.php']);
|
||||
|
||||
$this->copyFiles($list);
|
||||
|
||||
echo <<<EOD
|
||||
|
||||
Module '{$moduleID}' has been created under the following folder:
|
||||
$modulePath
|
||||
|
||||
You may access it in the browser using the following URL:
|
||||
http://hostname/path/to/index.php?r=$moduleID
|
||||
|
||||
Note, the module needs to be installed first by adding '{$moduleID}'
|
||||
to the 'modules' property in the application configuration.
|
||||
|
||||
EOD;
|
||||
}
|
||||
|
||||
public function generateModuleClass($source,$params)
|
||||
{
|
||||
return $this->renderFile($source,$params,true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user