是否有可能或建议将Laravel命令分组为嵌套组?

时间:2018-09-30 08:21:22

标签: php laravel command-line artisan

我们看到的是Laravel的工匠命令,其格式为<module>:<action>,因此...

php artisan migrate:refresh
php artisan cache:clear
// etc.

第三方软件包在其中添加了他们的供应商名称,所以我们得到了...

php artisan l5-swagger:generate

尽管这可能适用于特定的软件包,但是如果我想在项目名称和模块名称下为应用程序的本机命令命名,该怎么办?与此类似:

php artisan myapp:auth:create-admin

与简单

相反
php artisan myapp:create-admin
// OR
php artisan auth:create-admin

或者也许我想发疯,在其中也包括我的供应商名称:

php artisan myname:myapp:auth:create-admin

这是一个疯狂的例子,但是简单的,一个额外的命名空间级别肯定会帮助组织命令并保持外观整洁。

已经有这样的命令了吗?可以用类似于对路由进行分组的方式来做到这一点吗?

我想避免创建带有子命令的“超级命令”,例如:

php artisan myapp:command Auth CreateAdmin

1 个答案:

答案 0 :(得分:1)

以下是我的应用程序中可用命令的示例:

 ps4
  ps4:editor:create                       Create first data ThemeEditor in the database. Options : update | dump
  ps4:editor:export-css                   Export CSS
  ps4:editor:import-css                   Import CSS
  ps4:editor:import-value                 Create first data ThemeEditor in the database
  ps4:export:document                     Routine to generate static file base on release section of backoffice
  ps4:export:html                         Export Accessbility as html files in export.zip file : Requirement : You should put zip file on propal folder.
  ps4:generate                            Full document generation
  ps4:generate:blur:image                 Generate image blur for one document.
  ps4:generate:blur:zoom                  Regenerate all Zoom base64 blur
  ps4:generate:image                      Generate all images of your document
  ps4:generate:onepage                    generate concat of all html in one page
  ps4:generate:uglify                     Uglify generated html/assets to be spyproof
  ps4:generate:vocalization               Generate mp3 by page for a document
  ps4:import:documents                    Massive document Import
  ps4:import:html                         Import Accessbility content from html files
  ps4:import:vocalisation                 Import vocalisation files
  ps4:import:xml                          Import Accessbility content from xml file
  ps4:lunch-worker                        Lunch worker and check if they are alive
  ps4:media:image                         Post traitment media image
  ps4:media:video                         Post traitment media video
  ps4:migrate:accessibility-content       Migrate Accessibility to raw content
  ps4:monitoring:worker                   Command line to monitor our worker
  ps4:optimize:article                    Optimize image on article view.
  ps4:page:generate                       Full document generation
  ps4:page:reset-name                     Reset name of page per number page
  ps4:pdf:html                            Generate html files for specific document and specific pdf.
  ps4:pdf:image                           Convert pdf in images with different size, format, quality.
  ps4:pd:2txt                             Extract from pdf all text splitted by page.
  ps4:worker                              Spawn worker for image traitment

您的命令可以通过$signature属性进行配置:

namespace App\Console\Commands\Editor;

use Illuminate\Console\Command;

class CreateCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'ps4:editor:create {foo}';
}