diff --git a/application/admin/command/Api.php b/application/admin/command/Api.php index 97f1f5ecda0f6b204760595760237d704587b14f..c2ce2f2c06b6a39a04f07d69c9aa46b9d57222e6 100644 --- a/application/admin/command/Api.php +++ b/application/admin/command/Api.php @@ -26,6 +26,7 @@ class Api extends Command ->addOption('author', 'a', Option::VALUE_OPTIONAL, 'document author', $site['name']) ->addOption('class', 'c', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'extend class', null) ->addOption('language', 'l', Option::VALUE_OPTIONAL, 'language', 'zh-cn') + ->addOption('controller', 't', Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, 'controller name', null) ->setDescription('Build Api document from controller'); } @@ -80,16 +81,25 @@ class Api extends Command throw new Exception("Please make sure opcache already enabled, Get help:https://forum.fastadmin.net/d/1321"); } } - - $controllerDir = $moduleDir . Config::get('url_controller_layer') . DS; - $files = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($controllerDir), - \RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($files as $name => $file) { - if (!$file->isDir() && $file->getExtension() == 'php') { - $filePath = $file->getRealPath(); + //控制器名 + $controller = $input->getOption('controller') ?: ''; + if(!$controller) { + $controllerDir = $moduleDir . Config::get('url_controller_layer') . DS; + $files = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($controllerDir), + \RecursiveIteratorIterator::LEAVES_ONLY + ); + + foreach ($files as $name => $file) { + if (!$file->isDir() && $file->getExtension() == 'php') { + $filePath = $file->getRealPath(); + $classes[] = $this->get_class_from_file($filePath); + } + } + } + else{ + foreach ($controller as $index => $item) { + $filePath=$moduleDir . Config::get('url_controller_layer') . DS .$item.'.php'; $classes[] = $this->get_class_from_file($filePath); } }