admin管理员组文章数量:1122832
I have a problem that I just can't get any further with.
After restarting our web server, I get an Error 500 from one of our pages. The internal Lumen (Laravel) log spits out the following:
[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}
"}
I found an unused file with a class event declaration in App\Http\Events and removed it, unfortunately this did not work. Afterwards I ran a Composer update, which unfortunately also did not bring any success. A search of the files for the keyword ‘Event’ did not reveal any further declarations either.
On the one hand, I'm surprised that this error only occurred after a restart and on the other hand, I'm simply at a loss as to what else it could be... I have never edited the Application.php, it is in its ‘original state’.
Enclosed is my \Bootstrap\app.php. The custom EventServiceProvider is only the base example construct without any "Event" declaration.
<?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;
I hope you can maybe help me to solve the error.
I have a problem that I just can't get any further with.
After restarting our web server, I get an Error 500 from one of our pages. The internal Lumen (Laravel) log spits out the following:
[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}
"}
I found an unused file with a class event declaration in App\Http\Events and removed it, unfortunately this did not work. Afterwards I ran a Composer update, which unfortunately also did not bring any success. A search of the files for the keyword ‘Event’ did not reveal any further declarations either.
On the one hand, I'm surprised that this error only occurred after a restart and on the other hand, I'm simply at a loss as to what else it could be... I have never edited the Application.php, it is in its ‘original state’.
Enclosed is my \Bootstrap\app.php. The custom EventServiceProvider is only the base example construct without any "Event" declaration.
<?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;
I hope you can maybe help me to solve the error.
Share Improve this question asked Nov 22, 2024 at 10:37 MaxWebMaxWeb 1251 silver badge8 bronze badges 1- maybe look for an loop on the declaration – oelimoe Commented Nov 22, 2024 at 10:54
1 Answer
Reset to default 0Okay it seems that I have found the error...
The error is in the call $app->withFacades();
within the app.php
.
This causes the classes within the lumen Application.php
to be declared twice. If you call withFacades
with the parameter false
, the classes are not declared again and the whole thing works again.
I then called withFacades
again with the parameter true
and deleted the standard alias
Illuminate\Support\Facades\Event
=> Event
, and Illuminate\Support\Facades\URL
=> URL
within the Application.php
. I had to delete the alias URL
as well, as this caused the same problem.
Unfortunately, I don't currently know whether this is a bug in the Lumenframework or whether there is an error somewhere in my own code. At least it is currently working again. :)
本文标签:
版权声明:本文标题:php - Lumen "Cannot declare class Event, because the name is already in use in..." after reboot Server - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304488a1932252.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论