代码之家  ›  专栏  ›  技术社区  ›  aalaap

是否可以或建议将Laravel命令分组到嵌套组中?

  •  0
  • aalaap  · 技术社区  · 6 年前

    我们看到Laravel的artisan命令的典型格式是 <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 回复  |  直到 6 年前
        1
  •  1
  •   Yanis-git    6 年前

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

     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}';
    }