-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRememberAllServiceProvider.php
49 lines (37 loc) · 1.45 KB
/
RememberAllServiceProvider.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
<?php
namespace Barchart\Laravel\RememberAll;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider;
class RememberAllServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
Auth::extend('rememberall', function ($app, $name, $config) {
$provider = $app['auth']->createUserProvider($config['provider'] ?? null);
$guard = new SessionGuard($name, $provider, $app['session.store'], request(), $config['expire'] ?? null);
if (method_exists($guard, 'setCookieJar')) {
$guard->setCookieJar($app['cookie']);
}
if (method_exists($guard, 'setDispatcher')) {
$guard->setDispatcher($app['events']);
}
if (method_exists($guard, 'setRequest')) {
$guard->setRequest($app->refresh('request', $guard, 'setRequest'));
}
return $guard;
});
Auth::provider('database', function ($app, array $config) {
$connection = $app['db']->connection();
return new DatabaseUserProvider($connection, $app['hash'], $config['table']);
});
Auth::provider('eloquent', function ($app, array $config) {
return new EloquentUserProvider($app['hash'], $config['model']);
});
}
}