Laravel 4:在软件包中部署自定义artisan命令 [英] Laravel 4: Deploy custom artisan command in package

查看:43
本文介绍了Laravel 4:在软件包中部署自定义artisan命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一些自定义的artisan命令,以便更轻松地与我的包一起使用.可以将artisan命令包含在软件包中以便于部署吗?如果可以,怎么办?

I have developed some custom artisan command for easier use with my package. Is it possible to include the artisan command into the package for easier deployment? If can, how?

谢谢.

推荐答案

程序包结构中已设置命令:

Having a command set in your package structure:

<?php namespace App\Artisan;

use Illuminate\Console\Command;

class MyCommand extends Command {

    protected $name = 'mypackage:mycommand';

    protected $description = 'Nice description of my command.';

    public function fire()
    {
        /// do stuff
    }

}

您可以在您的服务提供商包中:

You can, in your package Service Provider:

<?php namespace App;

use Illuminate\Support\ServiceProvider;
use App\Artisan\MyCommand;

class MyServiceProvider extends ServiceProvider {

    public function register()
    {
        $this->registerMyCommand();

        $this->commands('mycommand');
    }

    private function registerMyCommand()
    {
        $this->app['mycommand'] = $this->app->share(function($app)
        {
            return new MyCommand;
        });
    }

}

窍门在行

$this->commands('mycommand');

告诉Laravel将您的命令添加到可用的工匠命令列表中.

Which tells Laravel to add your command to the artisan list of commands available.

这篇关于Laravel 4:在软件包中部署自定义artisan命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆