我遇到了一个无法进一步解决的问题。
重新启动我们的网络服务器后,我从我们的其中一个页面收到错误 500。内部 Lumen (Laravel) 日志输出以下内容:
[2024-11-22 11:13:14] local.ERROR: ErrorException: Cannot declare class Event, because the name is already in use in /var/www/vhosts/domainname/subdomain/vendor/laravel/lumen-framework/src/Application.php:744
Stack trace:
#0 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}()
#1 /var/www/vhosts/domainname/subdomain/vendor/laravel/lumen-framework/src/Application.php(744): class_alias()
#2 /var/www/vhosts/domainname/subdomain/vendor/laravel/lumen-framework/src/Application.php(711): Laravel\Lumen\Application->withAliases()
#3 /var/www/vhosts/domainname/subdomain/bootstrap/app.php(29): Laravel\Lumen\Application->withFacades()
#4 /var/www/vhosts/domainname/subdomain/public/index.php(14): require_once('/var/www/vhosts...')
#5 {main} {"exception":"[object] (ErrorException(code: 0): Cannot declare class Event, because the name is already in use at /var/www/vhosts/domainname/subdomain/vendor/laravel/lumen-framework/src/Application.php:744)
[stacktrace]
#0 [internal function]: Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}()
#1 /var/www/vhosts/domainname/subdomain/vendor/laravel/lumen-framework/src/Application.php(744): class_alias()
#2 /var/www/vhosts/domainname/subdomain/vendor/laravel/lumen-framework/src/Application.php(711): Laravel\\Lumen\\Application->withAliases()
#3 /var/www/vhosts/domainname/subdomain/bootstrap/app.php(29): Laravel\\Lumen\\Application->withFacades()
#4 /var/www/vhosts/domainname/subdomain/public/index.php(14): require_once('/var/www/vhosts...')
#5 {main}
"}
我在 App\Http\Events 中发现了一个未使用的带有类事件声明的文件并将其删除,不幸的是这不起作用。后来我运行了 Composer 更新,不幸的是也没有带来任何成功。在文件中搜索关键字“Event”也没有显示任何进一步的声明。
一方面,我很惊讶这个错误只在重新启动后发生,另一方面,我只是不知道它可能是什么......我从未编辑过Application.php,它处于“原始状态”。
附上我的 \Bootstrap pp.php。自定义 EventServiceProvider 只是基本示例构造,没有任何“事件”声明。
<?php
require_once __DIR__.'/../vendor/autoload.php';
if (!defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
//PHP < 7.2 Define it as 0 so it does nothing
define('JSON_INVALID_UTF8_SUBSTITUTE', 0);
}
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
))->bootstrap();
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new Laravel\Lumen\Application(
dirname(__DIR__)
);
//$app->withFacades();
$app->withEloquent();
$app->configure('database');
$app->configure('session');
$app->configure('filesystems');
$app->configure('flysystem');
$app->configure('mail');
$app->configure('enums');
/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/
$app->alias('mailer', Illuminate\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\MailQueue::class);
/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$app->singleton(Illuminate\Session\SessionManager::class, function () use ($app) {
return $app->loadComponent('session', Illuminate\Session\SessionServiceProvider::class, 'session');
});
$app->singleton('session.store', function () use ($app) {
return $app->loadComponent('session', Illuminate\Session\SessionServiceProvider::class, 'session.store');
});
$app->singleton('cookie', function () use ($app) {
return $app->loadComponent('session', 'Illuminate\Cookie\CookieServiceProvider', 'cookie');
});
$app->bind('Illuminate\Contracts\Cookie\QueueingFactory', 'cookie');
/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/
$app->middleware([
Illuminate\Cookie\Middleware\EncryptCookies::class,
Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
Illuminate\Session\Middleware\StartSession::class,
Illuminate\View\Middleware\ShareErrorsFromSession::class,
App\Http\Middleware\VerifyCsrfToken::class,
]);
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
'monday' => App\Http\Middleware\MondayWebhookLog::class,
'fullLog' => App\Http\Middleware\Log::class,
'customerLog' => App\Http\Middleware\CustomerLog::class,
'cookiecheck' => App\Http\Middleware\CookieCheck::class,
]);
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(Illuminate\Session\SessionServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);
$app->register(GrahamCampbell\Flysystem\FlysystemServiceProvider::class);
$app->register(App\Providers\DropboxProvider::class);
$app->register(Illuminate\Mail\MailServiceProvider::class);
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/
$app->router->group([
'namespace' => 'App\Http\Controllers',
], function ($router) {
require __DIR__.'/../routes/web.php';
});
return $app;
我希望你能帮助我解决这个错误。
好吧,看来我发现了错误...
错误出现在 app.php 中的“$app->withFacades();”调用中。
这会导致 lumen ‘Application.php’ 中的类被声明两次。如果您使用参数“false”调用“withFacades”,则不会再次声明类,并且整个事情会再次起作用。
然后我再次使用参数“true”调用 withFacades 并删除了标准别名 Application.php 中的‘‘Illuminate\Support\Facades\Event’ => ‘Event’,’ 和 “”Illuminate\Support\Facades\URL’ => ‘URL’,’。我还必须删除别名“URL”,因为这导致了同样的问题。
不幸的是,我目前不知道这是否是 Lumenframework 中的错误,或者我自己的代码中是否存在错误。至少目前它又可以工作了:)