2017-04-26 91 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

相關問題