Tim*_*lvy 3 php laravel laravel-5
试图创建一个基本命令,然后扩展它。提供给扩展命令的输入不会使其沿树向下。
BaseApiClassBuilder.php
use Illuminate\Console\Command;
class BaseApiClassBuilder extends Command
{
// rest of class follows...
}
Run Code Online (Sandbox Code Playgroud)
MakeApiCollection.php
class MakeApiCollection extends BaseApiClassBuilder
{
protected $signature = 'make:apicollection {name} {--namespace=}';
protected $description = 'Make an API Collection/Resource';
// guts of class...
}
Run Code Online (Sandbox Code Playgroud)
我正在运行的控制台命令
artisan make:apicollection testApiCollection
Run Code Online (Sandbox Code Playgroud)
收到控制台错误:
“App\Console\Commands\BaseApiClassMaker”中定义的命令不能为空名称。
与Can you extend Command classes in Laravel类似的问题,但这个问题有点过时且不太具体,而且也没有答案。
该错误仅在我扩展基本命令而不是“命令”时发生。
我已经确定没有在构造函数中调用验证,实际上很难弄清楚输入在哪里被验证,以及为什么它没有一路向下。
毫无疑问,我正在做一些愚蠢的事情,并且有一个简单的解决方案......但我找不到它!
我任何人都可以帮助我更好地理解这一点,非常感谢收到评论/答案/反馈。如果我完全以错误的方式处理这个问题,也请告诉我。我确实注意到我可以扩展GeneratorCommand而不是它有许多我需要的助手,但似乎并没有解决这个问题。
通过使父类抽象,您不需要定义 signature
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
abstract class BaseCommand extends Command
{
...
}
Run Code Online (Sandbox Code Playgroud)
稍后在子类中,您signature根据需要
设置
class ChildCommand extends BaseCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:apicollection {specific-name} {--namespace=}';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
833 次 |
| 最近记录: |