目前我正在为我的终端应用程序使用Symfony控制台,但我发现Laravel工匠控制台具有很多我可以使用的开箱即用功能。是否有一个版本的Laravel没有其他命令用于开发Web应用程序?或者至少删除安装Laravel时注册的默认可用命令?
答案 0 :(得分:7)
我使用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