laravel 在 Lumen 中注册外墙和服务提供商的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30399766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:02:13  来源:igfitidea点击:

Where to register Facades & Service Providers in Lumen

laravellumen

提问by Emeka Mbah

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

我正在寻找在 Lumen 中添加下面的立面的位置。

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

EDITED

已编辑

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

还有在哪里注册服务提供商 bootstrap\app.php

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

Please assist.

请协助。

回答by krisanalfa

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

在您的 中bootstrap/app.php,确保您已取消注释:

$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:

要注册您的ServiceProvider,请检查您的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

更新 #1

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

我在这里做了一个 simpel 样板来将 Lumen 与 JWT 和 Dingo 集成。

回答by qwaz

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

要使用 alias 注册外观,请转到bootstrap/app.php并取消注释:

$app->withFacades();

... it instructs the framework to start with facades. To add your facades, just put them in an array and pass the array as a second argument, while setting the first argument to true, as follows:

...它指示框架从外观开始。要添加您的外观,只需将它们放入一个数组中并将该数组作为第二个参数传递,同时将第一个参数设置为true,如下所示:

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

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);

回答by llioor

In your bootstrap\app.php

在你的 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

祝你好运