|
1
|
|
|
<?php namespace Arcanedev\LaravelImpersonator; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\Support\PackageServiceProvider; |
|
4
|
|
|
use Illuminate\Contracts\Foundation\Application; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class ImpersonatorServiceProvider |
|
8
|
|
|
* |
|
9
|
|
|
* @package Arcanedev\LaravelImpersonator |
|
10
|
|
|
* @author ARCANEDEV <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class ImpersonatorServiceProvider extends PackageServiceProvider |
|
13
|
|
|
{ |
|
14
|
|
|
/* ----------------------------------------------------------------- |
|
15
|
|
|
| Properties |
|
16
|
|
|
| ----------------------------------------------------------------- |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Package name. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $package = 'impersonator'; |
|
25
|
|
|
|
|
26
|
|
|
/* ----------------------------------------------------------------- |
|
27
|
|
|
| Main Methods |
|
28
|
|
|
| ----------------------------------------------------------------- |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Register the service provider. |
|
33
|
|
|
*/ |
|
34
|
56 |
|
public function register() |
|
35
|
|
|
{ |
|
36
|
56 |
|
parent::register(); |
|
37
|
|
|
|
|
38
|
56 |
|
$this->registerConfig(); |
|
39
|
|
|
|
|
40
|
56 |
|
$this->registerProvider(Providers\AuthorizationServiceProvider::class); |
|
41
|
|
|
|
|
42
|
56 |
|
$this->singleton(Contracts\Impersonator::class, Impersonator::class); |
|
43
|
56 |
|
$this->extendAuthDriver(); |
|
44
|
56 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Boot the service provider. |
|
48
|
|
|
*/ |
|
49
|
56 |
|
public function boot() |
|
50
|
|
|
{ |
|
51
|
56 |
|
parent::boot(); |
|
52
|
|
|
|
|
53
|
56 |
|
$this->publishConfig(); |
|
54
|
56 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get the services provided by the provider. |
|
58
|
|
|
* |
|
59
|
|
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
2 |
|
public function provides() |
|
62
|
|
|
{ |
|
63
|
|
|
return [ |
|
64
|
2 |
|
Contracts\Impersonator::class, |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/* ----------------------------------------------------------------- |
|
69
|
|
|
| Other Methods |
|
70
|
|
|
| ----------------------------------------------------------------- |
|
71
|
|
|
*/ |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Extend the auth session driver. |
|
75
|
|
|
*/ |
|
76
|
56 |
|
private function extendAuthDriver() |
|
77
|
|
|
{ |
|
78
|
|
|
/** @var \Illuminate\Auth\AuthManager $auth */ |
|
79
|
56 |
|
$auth = $this->app['auth']; |
|
80
|
|
|
|
|
81
|
42 |
|
$this->app['auth']->extend('session', function (Application $app, $name, array $config) use ($auth) { |
|
82
|
42 |
|
$provider = $auth->createUserProvider($config['provider']); |
|
83
|
|
|
|
|
84
|
42 |
|
return tap(new Guard\SessionGuard($name, $provider, $app['session.store']), function ($guard) use ($app) { |
|
85
|
42 |
|
if (method_exists($guard, 'setCookieJar')) |
|
86
|
42 |
|
$guard->setCookieJar($app['cookie']); |
|
87
|
|
|
|
|
88
|
42 |
|
if (method_exists($guard, 'setDispatcher')) |
|
89
|
42 |
|
$guard->setDispatcher($app['events']); |
|
90
|
|
|
|
|
91
|
42 |
|
if (method_exists($guard, 'setRequest')) |
|
92
|
42 |
|
$guard->setRequest($app->refresh('request', $guard, 'setRequest')); |
|
|
|
|
|
|
93
|
42 |
|
}); |
|
94
|
|
|
}); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.