47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
namespace App\Domains\Log\Providers;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
use App\Domains\Log\Providers\MiddlewareProvider;
|
|
use App\Domains\Log\Providers\RouteServiceProvider;
|
|
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
|
|
use App\Domains\Log\Http\Middleware\RequestsMonitorMiddleware;
|
|
|
|
class LogServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* 引导启动任何应用程序服务
|
|
*
|
|
* php artisan make:migration --path=app/Domains/Log/Database/migrations
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
$this->loadMigrationsFrom([realpath(__DIR__ . '/../Database/migrations')]);
|
|
$this->mergeConfigFrom(__DIR__ . '/../config.php', 'domain.log');
|
|
|
|
app('events')->listen(\App\Events\NewRequestEvent::class, \App\Domains\Log\Listeners\LogCreateListener::class);
|
|
}
|
|
|
|
/**
|
|
* 注册一个服务提供者
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
$this->app->singleton('geoip', function ($app) {
|
|
$config = $app->config['log'];
|
|
return new \GeoIp2\Database\Reader($config['mmdb_path']);
|
|
});
|
|
|
|
$this->app->withAliases([
|
|
\App\Domains\Log\Facades\GeoIp::class => 'GeoIp',
|
|
]);
|
|
|
|
$this->app->middleware([RequestsMonitorMiddleware::class]);
|
|
$this->app->register(RouteServiceProvider::class);
|
|
}
|
|
}
|