CConsoleCommandRunner
鍖 | system.console |
---|---|
缁ф壙 | class CConsoleCommandRunner » CComponent |
婧愯嚜 | 1.0 |
鐗堟湰 | $Id: CConsoleCommandRunner.php 3426 2011-10-25 00:01:09Z alexander.makarow $ |
婧愮爜 | framework/console/CConsoleCommandRunner.php |
CConsoleCommandRunner绠$悊鍛戒护鍜屾墽琛岃姹傜殑鍛戒护銆
鍏叡灞炴
灞炴 | 绫诲瀷 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|---|
commands | array | 鎵鏈夊彲鐢ㄧ殑鍛戒护鍒楄〃锛堝懡浠ゅ悕瀛=>鍛戒护閰嶇疆锛夈
姣忎竴涓懡浠ら厤缃彲浠ユ槸瀛楃涓叉垨鑰呮槸鏁扮粍銆
濡傛灉鏄墠鑰咃紝瀛楃涓插簲璇ユ槸绫诲悕瀛楁垨鑰呮槸杩欎釜鍛戒护鐨
class path alias銆
濡傛灉鏄悗鑰咃紝鏁扮粍蹇呴』鍖呭惈鐫鈥榗lass鈥欏厓绱狅紝
杩欏厓绱犳寚瀹氫簡鍛戒护鐨勭被鍚嶆垨鑰呮槸YiiBase::getPathOfAlias绫荤殑璺緞銆
鍏跺畠鐨勫湪鏁扮粍鐨勬暟缁勫鐢ㄦ潵鍒濆鍖栫浉鍏崇殑
鍛戒护灞炴с備緥濡傦紝
array( 'email'=>array( 'class'=>'path. |
CConsoleCommandRunner |
scriptName | string | 鍏ュ彛鏂囦欢鍚嶅瓧 | CConsoleCommandRunner |
鍏叡鏂规硶
鏂规硶 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|
__call() | 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 | CComponent |
__get() | 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 | CComponent |
__isset() | 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 | CComponent |
__set() | 璁剧疆涓涓粍浠剁殑灞炴у笺 | CComponent |
__unset() | 璁剧疆涓涓粍浠剁殑灞炴т负null銆 | CComponent |
addCommands() | 浠庡懡浠よ矾寰勬坊鍔犲懡浠ゃ | CConsoleCommandRunner |
asa() | 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° | CComponent |
attachBehavior() | 闄勫姞涓涓涓哄埌缁勪欢銆 | CComponent |
attachBehaviors() | 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 | CComponent |
attachEventHandler() | 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 | CComponent |
canGetProperty() | 纭畾灞炴ф槸鍚﹀彲璇汇 | CComponent |
canSetProperty() | 纭畾灞炴ф槸鍚﹀彲鍐欍 | CComponent |
createCommand() | CConsoleCommandRunner | |
detachBehavior() | 浠庣粍浠朵腑鍒嗙涓涓涓恒 | CComponent |
detachBehaviors() | 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 | CComponent |
detachEventHandler() | 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 | CComponent |
disableBehavior() | 绂佺敤涓涓檮鍔犺涓恒 | CComponent |
disableBehaviors() | 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 | CComponent |
enableBehavior() | 鍚敤涓涓檮鍔犺涓恒 | CComponent |
enableBehaviors() | 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 | CComponent |
evaluateExpression() | 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 | CComponent |
findCommands() | 鍦ㄦ寚瀹氱殑鐩綍涓嬮潰鎼滅储鍛戒护銆 | CConsoleCommandRunner |
getEventHandlers() | 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 | CComponent |
getScriptName() | 杩斿洖鍏ュ彛鏂囦欢鍚嶅瓧 | CConsoleCommandRunner |
hasEvent() | 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 | CComponent |
hasEventHandler() | 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 | CComponent |
hasProperty() | 纭畾灞炴ф槸鍚﹁瀹氫箟銆 | CComponent |
raiseEvent() | 鍙戣捣涓涓簨浠躲 | CComponent |
run() | 鎵ц璇锋眰鍛戒护銆 | CConsoleCommandRunner |
灞炴ц缁
commands
灞炴
public array $commands;
鎵鏈夊彲鐢ㄧ殑鍛戒护鍒楄〃锛堝懡浠ゅ悕瀛=>鍛戒护閰嶇疆锛夈 姣忎竴涓懡浠ら厤缃彲浠ユ槸瀛楃涓叉垨鑰呮槸鏁扮粍銆 濡傛灉鏄墠鑰咃紝瀛楃涓插簲璇ユ槸绫诲悕瀛楁垨鑰呮槸杩欎釜鍛戒护鐨 class path alias銆 濡傛灉鏄悗鑰咃紝鏁扮粍蹇呴』鍖呭惈鐫鈥榗lass鈥欏厓绱狅紝 杩欏厓绱犳寚瀹氫簡鍛戒护鐨勭被鍚嶆垨鑰呮槸YiiBase::getPathOfAlias绫荤殑璺緞銆 鍏跺畠鐨勫湪鏁扮粍鐨勬暟缁勫鐢ㄦ潵鍒濆鍖栫浉鍏崇殑 鍛戒护灞炴с備緥濡傦紝
array( 'email'=>array( 'class'=>'path.to.Mailer', 'interval'=>3600, ), 'log'=>'path.to.LoggerCommand', )
scriptName
灞炴
鍙
public string getScriptName()
鍏ュ彛鏂囦欢鍚嶅瓧
鏂规硶璇︾粏
addCommands()
鏂规硶
public void addCommands(string $path)
| ||
$path | string | 鍖呭惈鍛戒护绫绘枃浠剁殑鐩綍鍒悕銆 |
婧愮爜锛 framework/console/CConsoleCommandRunner.php#101 (鏄剧ず)
public function addCommands($path)
{
if(($commands=$this->findCommands($path))!==array())
{
foreach($commands as $name=>$file)
{
if(!isset($this->commands[$name]))
$this->commands[$name]=$file;
}
}
}
浠庡懡浠よ矾寰勬坊鍔犲懡浠ゃ 濡傛灉鍛戒护宸茬粡瀛樺湪锛屼細蹇界暐鏂扮殑鍛戒护銆
createCommand()
鏂规硶
public CConsoleCommand createCommand(string $name)
| ||
$name | string | 鍛戒护鍚嶅瓧锛堝ぇ灏忓啓涓嶆晱鎰燂級 |
{return} | CConsoleCommand | 杩斿洖鍛戒护瀵硅薄銆傚鏋滃悕瀛椾笉鍙敤鍒欒繑鍥 null銆 |
婧愮爜锛 framework/console/CConsoleCommandRunner.php#117 (鏄剧ず)
public function createCommand($name)
{
$name=strtolower($name);
if(isset($this->commands[$name]))
{
if(is_string($this->commands[$name])) // class file path or alias
{
if(strpos($this->commands[$name],'/')!==false || strpos($this->commands[$name],'\\')!==false)
{
$className=substr(basename($this->commands[$name]),0,-4);
if(!class_exists($className,false))
require_once($this->commands[$name]);
}
else // an alias
$className=Yii::import($this->commands[$name]);
return new $className($name,$this);
}
else // an array configuration
return Yii::createComponent($this->commands[$name],$name,$this);
}
else if($name==='help')
return new CHelpCommand('help',$this);
else
return null;
}
findCommands()
鏂规硶
public array findCommands(string $path)
| ||
$path | string | 鍖呭惈鍛戒护绫绘枃浠剁殑鐩綍銆 |
{return} | array | 鍛戒护鍒楄〃锛堝懡浠ゅ悕瀛楋紳銆嬪懡浠ょ被鏂囦欢锛 |
婧愮爜锛 framework/console/CConsoleCommandRunner.php#81 (鏄剧ず)
public function findCommands($path)
{
if(($dir=@opendir($path))===false)
return array();
$commands=array();
while(($name=readdir($dir))!==false)
{
$file=$path.DIRECTORY_SEPARATOR.$name;
if(!strcasecmp(substr($name,-11),'Command.php') && is_file($file))
$commands[strtolower(substr($name,0,-11))]=$file;
}
closedir($dir);
return $commands;
}
鍦ㄦ寚瀹氱殑鐩綍涓嬮潰鎼滅储鍛戒护銆
getScriptName()
鏂规硶
public string getScriptName()
| ||
{return} | string | 鍏ュ彛鏂囦欢鍚嶅瓧 |
婧愮爜锛 framework/console/CConsoleCommandRunner.php#71 (鏄剧ず)
public function getScriptName()
{
return $this->_scriptName;
}
run()
鏂规硶
public void run(array $args)
| ||
$args | array | 鐢ㄦ埛鎻愪緵鍙傛暟鍒楄〃锛堝寘鍚叆鍙f枃浠跺悕瀛楀拰鍛戒护鍚嶅瓧锛夈 |
婧愮爜锛 framework/console/CConsoleCommandRunner.php#50 (鏄剧ず)
public function run($args)
{
$this->_scriptName=$args[0];
array_shift($args);
if(isset($args[0]))
{
$name=$args[0];
array_shift($args);
}
else
$name='help';
if(($command=$this->createCommand($name))===null)
$command=$this->createCommand('help');
$command->init();
$command->run($args);
}
鎵ц璇锋眰鍛戒护銆