computeFuncParams() public static method

Creates an array of parameters according to the function definition
public static computeFuncParams ( ReflectionFunctionAbstract $reflection, array $args, array $options, boolean $needTagInDocComment = true ) : array
$reflection ReflectionFunctionAbstract
$args array
$options array
$needTagInDocComment boolean Whether the compute-params tag must be present in the doc comment
return array
示例#1
0
 /**
  * If not overriden, will execute the command specified
  * as the first argument
  * 
  * Commands must be defined as methods named after the
  * command, prefixed with execute (eg. create -> executeCreate)
  * 
  * @param array $args
  * @param array $options
  */
 public function execute(array $args, array $options = array())
 {
     if (!count($args)) {
         throw new ConsoleException("Missing subcommand name");
     }
     $command = ucfirst(Utils::camelize(array_shift($args)));
     $methodName = "execute{$command}";
     if (!method_exists($this, $methodName)) {
         throw new ConsoleException("Command '{$command}' does not exist");
     }
     $method = new ReflectionMethod($this, $methodName);
     $params = Utils::computeFuncParams($method, $args, $options);
     return $method->invokeArgs($this, $params);
 }
示例#2
0
 /**
  * Executes a command
  *
  * @param string $command
  * @param array $args
  * @param array $options
  * @return mixed
  */
 public function execute($command = null, array $args = array(), array $options = array())
 {
     $command = $command ?: $this->defaultCommand;
     if (!isset($this->commands[$command])) {
         throw new ConsoleException("Command '{$command}' does not exist");
     }
     $callback = $this->commands[$command];
     if (is_callable($callback)) {
         $params = array($args, $options);
         if (is_string($callback)) {
             if (strpos($callback, '::') !== false) {
                 list($classname, $methodname) = explode('::', $callback);
                 $reflection = new ReflectionMethod($classname, $methodname);
             } else {
                 $reflection = new ReflectionFunction($callback);
             }
             $params = Utils::computeFuncParams($reflection, $args, $options);
         }
         $params[] = $this;
         return call_user_func_array($callback, $params);
     }
     $method = new ReflectionMethod($callback, 'execute');
     $params = Utils::computeFuncParams($method, $args, $options);
     return $method->invokeArgs(new $callback($this), $params);
 }