framework/console/CConsoleCommand.php
public function run($args)
	{
		list($action, $options, $args)=$this->resolveRequest($args);
		$methodName='action'.$action;
		if(!preg_match('/^\w+$/',$action) || !method_exists($this,$methodName))
			$this->usageError("Unknown action: ".$action);

		$method=new ReflectionMethod($this,$methodName);
		$params=array();
		// named and unnamed options
		foreach($method->getParameters() as $i=>$param)
		{
			$name=$param->getName();
			if(isset($options[$name]))
			{
				if($param->isArray())
					$params[]=is_array($options[$name]) ? $options[$name] : array($options[$name]);
				elseif(!is_array($options[$name]))
					$params[]=$options[$name];
				else
					$this->usageError("Option --$name requires a scalar. Array is given.");
			}
			elseif($name==='args')
				$params[]=$args;
			elseif($param->isDefaultValueAvailable())
				$params[]=$param->getDefaultValue();
			else
				$this->usageError("Missing required option --$name.");
			unset($options[$name]);
		}

		// try global options
		if(!empty($options))
		{
			$class=new ReflectionClass(get_class($this));
			foreach($options as $name=>$value)
			{
				if($class->hasProperty($name))
				{
					$property=$class->getProperty($name);
					if($property->isPublic() && !$property->isStatic())
					{
						$this->$name=$value;
						unset($options[$name]);
					}
				}
			}
		}

		if(!empty($options))
			$this->usageError("Unknown options: ".implode(', ',array_keys($options)));

		$exitCode=0;
		if($this->beforeAction($action,$params))
		{
			$exitCode=$method->invokeArgs($this,$params);
			$exitCode=$this->afterAction($action,$params,is_int($exitCode)?$exitCode:0);
		}
		return $exitCode;
	}
public function run($args)
	{
		list($action, $options, $args)=$this->resolveRequest($args);
		$methodName='action'.$action;
		if(!preg_match('/^\w+$/',$action) || !method_exists($this,$methodName))
			$this->usageError("Unknown action: ".$action);

		$method=new ReflectionMethod($this,$methodName);
		$params=array();
		// named and unnamed options
		foreach($method->getParameters() as $i=>$param)
		{
			$name=$param->getName();
			if(isset($options[$name]))
			{
				if($param->isArray())
					$params[]=is_array($options[$name]) ? $options[$name] : array($options[$name]);
				elseif(!is_array($options[$name]))
					$params[]=$options[$name];
				else
					$this->usageError("Option --$name requires a scalar. Array is given.");
			}
			elseif($name==='args')
				$params[]=$args;
			elseif($param->isDefaultValueAvailable())
				$params[]=$param->getDefaultValue();
			else
				$this->usageError("Missing required option --$name.");
			unset($options[$name]);
		}

		// try global options
		if(!empty($options))
		{
			$class=new ReflectionClass(get_class($this));
			foreach($options as $name=>$value)
			{
				if($class->hasProperty($name))
				{
					$property=$class->getProperty($name);
					if($property->isPublic() && !$property->isStatic())
					{
						$this->$name=$value;
						unset($options[$name]);
					}
				}
			}
		}

		if(!empty($options))
			$this->usageError("Unknown options: ".implode(', ',array_keys($options)));

		$exitCode=0;
		if($this->beforeAction($action,$params))
		{
			$exitCode=$method->invokeArgs($this,$params);
			$exitCode=$this->afterAction($action,$params,is_int($exitCode)?$exitCode:0);
		}
		return $exitCode;
	}
public function run ( $ args ) { list ( $ action , $ options , $ args ) = $ this -> resolveRequest ( $ args ) ; $ methodName = 'action' . $ action ; if ( ! preg_match ( '/^\w+$/' , $ action ) || ! method_exists ( $ this , $ methodName ) ) $ this -> usageError ( "Unknown action: " . $ action ) ; $ method = new ReflectionMethod ( $ this , $ methodName ) ; $ params = array ( ) ; // named and unnamed options foreach ( $ method -> getParameters ( ) as $ i => $ param ) { $ name = $ param -> getName ( ) ; if ( isset ( $ options [ $ name ] ) ) { if ( $ param -> isArray ( ) ) $ params [ ] = is_array ( $ options [ $ name ] ) ? $ options [ $ name ] : array ( $ options [ $ name ] ) ; elseif ( ! is_array ( $ options [ $ name ] ) ) $ params [ ] = $ options [ $ name ] ; else $ this -> usageError ( "Option --$name requires a scalar. Array is given." ) ; } elseif ( $ name === 'args' ) $ params [ ] = $ args ; elseif ( $ param -> isDefaultValueAvailable ( ) ) $ params [ ] = $ param -> getDefaultValue ( ) ; else $ this -> usageError ( "Missing required option --$name." ) ; unset ( $ options [ $ name ] ) ; } // try global options if ( ! empty ( $ options ) ) { $ class = new ReflectionClass ( get_class ( $ this ) ) ; foreach ( $ options as $ name => $ value ) { if ( $ class -> hasProperty ( $ name ) ) { $ property = $ class -> getProperty ( $ name ) ; if ( $ property -> isPublic ( ) && ! $ property -> isStatic ( ) ) { $ this -> $ name = $ value ; unset ( $ options [ $ name ] ) ; } } } } if ( ! empty ( $ options ) ) $ this -> usageError ( "Unknown options: " . implode ( ', ' , array_keys ( $ options ) ) ) ; $ exitCode = 0 ; if ( $ this -> beforeAction ( $ action , $ params ) ) { $ exitCode = $ method -> invokeArgs ( $ this , $ params ) ; $ exitCode = $ this -> afterAction ( $ action , $ params , is_int ( $ exitCode ) ? $ exitCode : 0 ) ; } return $ exitCode ; }
Executes the command.
The default implementation will parse the input parameters and
dispatch the command request to an appropriate action with the corresponding
option values
@param array $args command line parameters for this command.
@return integer application exit code, which is returned by the invoked action. 0 if the action did not return anything.
(return value is available since version 1.1.11)
Executes the command . The default implementation will parse the input parameters and dispatch the command request to an appropriate action with the corresponding option values