Reputation: 1421
I am trying to inject a Manager class into toe Service Container of Lumen. My goal is to have a single instance of LogManager
which is available in the whole application via app(LogManager::class)
.
Everytime i try to access this shortcut i get the following exeption:
[2017-03-23 16:42:51] lumen.ERROR: ReflectionException: Class LogManager does not
exist in /vendor/illuminate/container/Container.php:681
LogManager.php (i placed that class in the same location where my models are (app/LogManager.php))
<?php
namespace App;
use App\LogEntry;
class LogManager
{
...
}
AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\LogManager;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->singleton(LogManager::class, function ($app) {
return new LogManager();
});
}
}
I uncommented the line $app->register(App\Providers\AppServiceProvider::class);
in bootstrap/app.php
I think that i missed something with the correct namespacing or placement of the classes espaccially LogManager. Maybe some one is willing to give me a hint?
If you need some more informations just give me a hint!
Upvotes: 1
Views: 3470
Reputation: 62228
Your class and your service provider look fine. However, wherever you're calling app(LogManager::class)
also needs to know the fully qualified name of the class.
Either make sure you have use App\LogManager
at the top of the file, or change your call to app(\App\LogManager::class)
.
Upvotes: 2