2017-04-26 105 views
5

目前我正在为我的终端应用程序使用Symfony控制台,但我发现Laravel artisan控制台有很多功能可以使用。有没有其他命令用于开发Web应用程序的Laravel版本?或者至少要删除安装Laravel时注册的默认可用命令?仅有控制台应用程序的laravel版本吗?

+3

你或许可以得到'照亮/ console'并自行运行。 – ceejayoz

+0

@ceejayoz我一定会尝试这个。谢谢! – doyevaristo

+0

签出[此链接](https://laravel.com/docs/5.4/artisan),您可以在** routes/console.php中以* Laravel Routes *的形式定义控制台命令** –

回答

5

我刚刚得到这个使用illuminate/console工作:

composer.json

{ 
    "require": { 
     "illuminate/console": "^5.4", 
     "illuminate/container": "^5.4", 
     "illuminate/events": "^5.4" 
    }, 
    "autoload": { 
     "psr-4": {"Yourvendor\\Yourproject\\": "src/"} 
    } 
} 

your-console-app(更换artisan):

#!/usr/bin/env php 
<?php 

use Illuminate\Console\Application; 
use Illuminate\Container\Container; 
use Illuminate\Events\Dispatcher; 

use Yourvendor\Yourproject\Console\Commands\Yourcommand; 

if (file_exists($a = __DIR__.'/../../autoload.php')) { 
    require_once $a; 
} else { 
    require_once __DIR__.'/vendor/autoload.php'; 
} 

$container = new Container; 
$dispatcher = new Dispatcher; 
$version = "5.4"; // Laravel version 

$app = new Application($container, $dispatcher, $version); 

$app->add(new Yourcommand); 

$app->run(); 

src/Console/Commands/Yourcommand.php

<?php 

namespace Yourvendor\Yourproject\Console\Commands; 

use Illuminate\Console\Command; 

class Yourcommand extends Command 
{ 
    /** 
    * The name and signature of the console command. 
    * 
    * @var string 
    */ 
    protected $signature = 'yourcommand:test {test}'; 

    /** 
    * The console command description. 
    * 
    * @var string 
    */ 
    protected $description = 'Yourcommand test'; 

    /** 
    * Execute the console command. 
    * 
    * @return mixed 
    */ 
    public function handle() 
    { 
     $this->info('Hello world!'); 
    } 
} 

使用运行控制台命令:

php your-console-app yourcommand:test

+0

真棒!即使我使用python,我一定会尝试一下。 :) – doyevaristo

+0

我刚刚发现的一件事是,它似乎不可能加载服务提供商,所以我只是从'Illuminate \ Console \ Application'切换到'Illuminate \ Foundation \ Application',它具有所需的寄存器( )'方法。 – ilumos

相关问题