forked from iinaveedahmed/gapp-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IpaasServiceProvider.php
executable file
·82 lines (71 loc) · 1.97 KB
/
IpaasServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Ipaas\Gapp;
use Exception;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
use Ipaas\Gapp\Command\CreatePartnerApp;
use Ipaas\Gapp\Exception\GException;
use Ipaas\Gapp\Exception\JsonExceptionRender;
use Ipaas\Gapp\Logger\Client;
use Ipaas\Gapp\Middleware\AuthAndLog;
use ReflectionException;
class IpaasServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$this->loadMigrationsFrom(__DIR__ . '/Database/Migration');
if ($this->app->runningInConsole()) {
$this->commands([
CreatePartnerApp::class,
]);
}
$this->publishes([
__DIR__.'/config.php' => config_path('gapp.php'),
], 'gapp');
}
/**
* Register services.
*
* @return void
*/
public function register()
{
/*
* Add logging channel 'stack-driver'
*/
$this->mergeConfigFrom(__DIR__ . '/Logger/config.php', 'logging.channels');
/*
* Init singleton ipaas-info with Ipaas/Info/Client
*/
$this->app->singleton('logger-context', function () {
return new Client();
});
/*
* Take over exception handler
*/
$this->app->singleton(
'Illuminate\Contracts\Debug\ExceptionHandler',
GException::class
);
/**
* Register dingo handlers
*/
if (class_exists('Dingo\Api\Exception\Handler')) {
app('Dingo\Api\Exception\Handler')->register(function (Exception $exception) {
return JsonExceptionRender::render($exception);
});
}
/** @var Router $router */
$router = app('router');
/**
* Append middleware
*/
$router->aliasMiddleware('partner', AuthAndLog::class);
$router->pushMiddlewareToGroup('api', AuthAndLog::class);
}
}