Where to register Facades & Service Providers in Lumen

给你一囗甜甜゛ 提交于 2019-12-31 08:44:16

问题


I Am looking for where to add the facade below in Lumen.

'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth'

EDITED

Also where to register service provider in bootstrap\app.php

$app->register('Tymon\JWTAuth\Providers\JWTAuthServiceProvider');

Please assist.


回答1:


In your bootstrap/app.php, make sure you've un-commented:

$app->withFacades();

Then, register you class alias and check if it already exists (else your tests will break):

if (!class_exists('JWTAuth')) {
    class_alias('Tymon\JWTAuth\Facades\JWTAuth', 'JWTAuth');
}

To register your ServiceProvider, check your bootstrap/app.php:

/*
|--------------------------------------------------------------------------
| 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');

// Add your service provider here
$app->register('Tymon\JWTAuth\Providers\JWTAuthServiceProvider');

Update #1

I made a simpel boilerplate here to integrate Lumen with JWT and Dingo.




回答2:


To register a facade with an alias, go to bootstrap/app.php and uncomment:

$app->withFacades();

... it instructs the framework to load default facades. If you need to load additional facades, just put them in array and pass the array as a second argument, while setting the first argument to true, as follows:

$app->withFacades(true, ['Tymon\JWTAuth\Facades\JWTAuth' => 'JWTAuth']);

To register a service provider, in the same file, scroll down to a relevant comment section and add the following line:

$app->register(Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class);



回答3:


In your bootstrap\app.php

Example for Provider

// XML parser service provider
$app->register(\Nathanmac\Utilities\Parser\ParserServiceProvider::class);
// GeoIP
$app->register(\Torann\GeoIP\GeoIPServiceProvider::class);
$app->withEloquent();

Example for Alias

// SERVICE ALIASES
class_alias(\Nathanmac\Utilities\Parser\Facades\Parser::class, 'Parser');
class_alias(\Torann\GeoIP\Facades\GeoIP::class, 'GeoIP');
$app->withFacades();
...
...
...

Good luck



来源:https://stackoverflow.com/questions/30399766/where-to-register-facades-service-providers-in-lumen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!