Illuminate\Console\命令在开发 laravel 5.8 软件包时找不到



我正在为 Laravel 5.8 开发一个软件包。当我尝试创建一个扩展 Illuminate\Console\Command 的控制台命令时,"作曲家转储自动加载"失败并显示错误消息:

c:Program Files (x86)Amppswwwptest>composer dump-autoload
Generating optimized autoload files> IlluminateFoundationComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
ReflectionException  : Class TestVendorTestPackageTestCommand does not exist
at C:Program Files (x86)AmppswwwptestvendorlaravelframeworksrcIlluminateContainerContainer.php:790
786|         if ($concrete instanceof Closure) {
787|             return $concrete($this, $this->getLastParameterOverride());
788|         }
789|
> 790|         $reflector = new ReflectionClass($concrete);
791|
792|         // If the type is not instantiable, the developer is attempting to resolve
793|         // an abstract type such as an Interface or Abstract Class and there is
794|         // no binding registered for the abstractions so we need to bail out.
Exception trace:
1   ReflectionClass::__construct("TestVendorTestPackageTestCommand")
C:Program Files (x86)AmppswwwptestvendorlaravelframeworksrcIlluminateContainerContainer.php:790
2   IlluminateContainerContainer::build("TestVendorTestPackageTestCommand")
C:Program Files (x86)AmppswwwptestvendorlaravelframeworksrcIlluminateContainerContainer.php:667

我尝试在 C:\Program Files (x86(\Ampps\www\ptest\packages 文件夹中手动创建包,并尝试使用打包程序 https://github.com/Jeroen-G/laravel-packager 但两种情况下的结果是相同的。

测试命令.php

<?php
namespace TestVendorTestPackage;
use IlluminateConsoleCommand;
class TestCommand extends Command {
protected $signature = 'test:hello';
protected $description = 'say hello';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$this->info("hello!");
}
}

测试服务提供商.php

<?php
namespace TestVendorTestPackage;
use IlluminateSupportServiceProvider;
class TestServiceProvider extends ServiceProvider
{
public function boot()
{
if ($this->app->runningInConsole()) {
$this->bootForConsole();
}
}
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/testpackage.php', 'testpackage');
$this->app->singleton('testpackage', function ($app) {
return new TestPackage;
});
}
public function provides()
{
return ['testpackage'];
}
protected function bootForConsole()
{
// Registering package commands.
$this->commands([TestCommand::class]);
}
}

当我直接从命令行执行TestCommand.php文件时,它失败并显示错误消息

PHP Fatal error:  Class 'IlluminateConsoleCommand' not found

我已经检查了"供应商"文件夹中的其他工作包,并且所有工作包都具有与我的包相同的结构。似乎自动加载无法正常工作。

"console"文件夹位于"src"文件夹之外。因此无法发现。

删除供应商和node_modules文件夹 然后运行以下命令

composer update
npm install

它应该可以正常工作。

最新更新