示例#1
0
 /**
  * @param AppKernel $kernel
  * @param \Zero\Component\Kernel\Container $app_container
  * @throws \Exception
  */
 public static function process(AppKernel $kernel, $app_container)
 {
     global $argv;
     if (!isset($argv[1])) {
         throw new \Exception("命令行第一个参数应该是需要调用的方法");
     }
     $controller = $argv[1];
     if (strpos($controller, ':') === false) {
         throw new \Exception("第一个参数错误,格式应该为<module_name>:<command_name>:<action_name>");
     }
     $arguments = array_splice($argv, 2);
     try {
         list($module_name, $command_name, $action_name) = explode(':', $controller);
         $module = $kernel->getModule($module_name);
         $command = $module->getCommand($command_name, $action_name);
         if (method_exists($command, '__invoke')) {
             /** @var \Symfony\Component\HttpFoundation\Response $response */
             call_user_func_array($command, $arguments);
         } else {
             throw new \Exception('Command must has the __invoke public function!');
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }