Lumen-framework: Typehinting AuthManager for Injection throws `<required> $app` Exception

Created on 16 Jun 2020  Â·  1Comment  Â·  Source: laravel/lumen-framework


  • Lumen Version: "version": "v7.1.2",
  • PHP Version: 7.3.7
  • Database Driver & Version: N/A
  • Windows 10, Cygwin

Description:

When I try to inject AuthManager into a class it throws an Exception.

Steps To Reproduce:

image

Try to use code like this.

It seems Lumen _half_ registers the component:

Unresolvable dependency resolving [Parameter #0 [ <required> $app ]] in class Illuminate\\Auth\\AuthManager

The only way I can solve this is by adding:

        $this->app->singleton(AuthManager::class, function () {
            return $this->app->loadComponent('auth', 'Illuminate\Auth\AuthServiceProvider', 'auth');
        });

to my AuthServiceProvider.php.

For some reason the class is half loaded such that it's not throwing that the class isn't registered but also can't return the correct singleton instance without me registering it.

I say half register because it appears in app():

/c/src/project (master) [0] $ php artisan tinker
Psy Shell v0.10.4 (PHP 7.3.7 — cli) by Justin Hileman
>>> app()
=> Laravel\Lumen\Application {#11
     +router: Laravel\Lumen\Routing\Router {#12
       +app: Laravel\Lumen\Application {#11},
       +namedRoutes: [
         "graphql" => "/graphql",
         "graphql-playground" => "/graphql-playground",
       ],
     },
     +availableBindings: [
       "auth" => "registerAuthBindings",
       "auth.driver" => "registerAuthBindings",
       "Illuminate\Auth\AuthManager" => "registerAuthBindings",
       "Illuminate\Contracts\Auth\Guard" => "registerAuthBindings",
       "Illuminate\Contracts\Auth\Access\Gate" => "registerAuthBindings",
       "Illuminate\Contracts\Broadcasting\Broadcaster" => "registerBroadcastingBindings",
       "Illuminate\Contracts\Broadcasting\Factory" => "registerBroadcastingBindings",
       "Illuminate\Contracts\Bus\Dispatcher" => "registerBusBindings",
       "cache" => "registerCacheBindings",
       "cache.store" => "registerCacheBindings",
       "Illuminate\Contracts\Cache\Factory" => "registerCacheBindings",
       "Illuminate\Contracts\Cache\Repository" => "registerCacheBindings",
       "composer" => "registerComposerBindings",
       "config" => "registerConfigBindings",
       "db" => "registerDatabaseBindings",
       "Illuminate\Database\Eloquent\Factory" => "registerDatabaseBindings",
       "filesystem" => "registerFilesystemBindings",
       "filesystem.cloud" => "registerFilesystemBindings",
       "filesystem.disk" => "registerFilesystemBindings",
       "Illuminate\Contracts\Filesystem\Cloud" => "registerFilesystemBindings",
       "Illuminate\Contracts\Filesystem\Filesystem" => "registerFilesystemBindings",
       "Illuminate\Contracts\Filesystem\Factory" => "registerFilesystemBindings",
       "encrypter" => "registerEncrypterBindings",
       "Illuminate\Contracts\Encryption\Encrypter" => "registerEncrypterBindings",
       "events" => "registerEventBindings",
       "Illuminate\Contracts\Events\Dispatcher" => "registerEventBindings",
       "files" => "registerFilesBindings",
       "hash" => "registerHashBindings",
       "Illuminate\Contracts\Hashing\Hasher" => "registerHashBindings",
       "log" => "registerLogBindings",
       "Psr\Log\LoggerInterface" => "registerLogBindings",
       "queue" => "registerQueueBindings",
       "queue.connection" => "registerQueueBindings",
       "Illuminate\Contracts\Queue\Factory" => "registerQueueBindings",
       "Illuminate\Contracts\Queue\Queue" => "registerQueueBindings",
       "router" => "registerRouterBindings",
       "Psr\Http\Message\ServerRequestInterface" => "registerPsrRequestBindings",
       "Psr\Http\Message\ResponseInterface" => "registerPsrResponseBindings",
       "translator" => "registerTranslationBindings",
       "url" => "registerUrlGeneratorBindings",
       "validator" => "registerValidatorBindings",
       "Illuminate\Contracts\Validation\Factory" => "registerValidatorBindings",
       "view" => "registerViewBindings",
       "Illuminate\Contracts\View\Factory" => "registerViewBindings",
     ],
     +contextual: [],
   }
bug

Most helpful comment

Thanks for reporting. I sent in a PR here: https://github.com/laravel/lumen-framework/pull/1091

>All comments

Thanks for reporting. I sent in a PR here: https://github.com/laravel/lumen-framework/pull/1091

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Andrei-Vakulski picture Andrei-Vakulski  Â·  3Comments

maglor picture maglor  Â·  3Comments

jampack picture jampack  Â·  3Comments

codercms picture codercms  Â·  4Comments

matthewsuan picture matthewsuan  Â·  3Comments