在laravel 5.2内核控制台中通过新的artisan命令删除旧的artisan命令

naf*_*4me 6 php laravel artisan laravel-5.2

我在内核命令中工作,我需要更改旧命令:

旧命令是:

php artisan crawl:author
Run Code Online (Sandbox Code Playgroud)

现在我需要重命名它:

php artisan crawl-bq:author
Run Code Online (Sandbox Code Playgroud)

在我的命令文件签名更改为:

protected $ signature ='crawl-bq:author';

我使用以下命令清理了工匠缓存:

php artisan cache:clear
php artisan config:cache
Run Code Online (Sandbox Code Playgroud)

我的旧命令仍在工作,新命令也在工作.但是当我看到工匠名单"php artisan list"时,那里也没有看到旧的命令.

有人在那帮助我吗?

naf*_*4me 1

经过很长一段时间,我发现 Laravel 5.2 artisan 控制台命令有一个错误,或者它不是错误,因为至少有一个命令将根据初始模式匹配执行。

假设您在两个不同的命令文件中有两个签名,如下 4 种情况:

案例一:

protected $signature = 'crawl:author-usa';
protected $signature = 'crawl:author-uk';
Run Code Online (Sandbox Code Playgroud)

或者情况二:

protected $signature = 'crawl:authorusa';
protected $signature = 'crawl:authoruk';
Run Code Online (Sandbox Code Playgroud)

或情况三:

protected $signature = 'crawl-bq:author-usa';
protected $signature = 'crawl-bq:author-uk';
Run Code Online (Sandbox Code Playgroud)

或情况四:

protected $signature = 'crawl-bq:authorusa';
protected $signature = 'crawl-bq:authoruk';
Run Code Online (Sandbox Code Playgroud)

对于任何一种情况,如果您运行命令php artisan crawl:auther,那么对于情况 I,它将显示不明确的错误,例如:

[Symfony\Component\Console\Exception\CommandNotFoundException] Command "crawl:author" is ambiguous (crawl:author-usa, crawl:author-uk).

对于其余 3 种情况,它将显示相同的模糊消息,但签名明智的文本会有所不同。

现在针对 4 种不同情况假设以下签名:

案例一:

protected $signature = 'crawl:author-usa';
Run Code Online (Sandbox Code Playgroud)

或者情况二:

protected $signature = 'crawl:authorusa';
Run Code Online (Sandbox Code Playgroud)

或情况三:

protected $signature = 'crawl-bq:author-usa';
Run Code Online (Sandbox Code Playgroud)

或情况四:

protected $signature = 'crawl-bq:authorusa';
Run Code Online (Sandbox Code Playgroud)

无论哪种情况,如果您运行该php artisan crawl:auther命令,它将执行该命令。

对于这两种情况,这是由于 Symfony/Cconsole find() 函数而发生的。这里通过这个表达式搜索确切的命令:crawl[^:]*[^:]*:author[^:]*[^:]*。这意味着,如果有任何签名crawl<anything>:author<anything>将与 php artisan crawl:author

现在,如果我要解决这个问题,主要需要更改symfony/conslepublic function find($name)文件中的 509 行附近。或者是否有可能覆盖此函数(我不确定如何完成此覆盖)。

我受到 @Nadeem0035 的启发,他在symfony/conslepublic function find($name)文件中提到了近 509 行。如果我能在赏金期限内授予赏金,我会很高兴,因为至少他向我展示了一种找到控制台命令的确切场景的方法。这就是为什么要投赞成票的原因:)