|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Lab404\Impersonate; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Routing\Router; |
|
6
|
|
|
use Illuminate\Support\Facades\Blade; |
|
7
|
|
|
use Lab404\Impersonate\Services\ImpersonateManager; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class ServiceProvider |
|
11
|
|
|
* |
|
12
|
|
|
* @package Lab404\Impersonate |
|
13
|
|
|
*/ |
|
14
|
|
|
class ImpersonateServiceProvider extends \Illuminate\Support\ServiceProvider |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var bool |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $defer = false; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $configName = 'laravel-impersonate'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Register the service provider. |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
|
|
public function register() |
|
32
|
|
|
{ |
|
33
|
|
|
$configPath = __DIR__ . '/../config/' . $this->configName . '.php'; |
|
34
|
|
|
|
|
35
|
|
|
$this->mergeConfigFrom($configPath, $this->configName); |
|
36
|
|
|
|
|
37
|
|
|
$this->app->bind(ImpersonateManager::class, ImpersonateManager::class); |
|
38
|
|
|
|
|
39
|
|
|
$this->app->singleton(ImpersonateManager::class, function ($app) |
|
40
|
|
|
{ |
|
41
|
|
|
return new ImpersonateManager($app); |
|
42
|
|
|
}); |
|
43
|
|
|
|
|
44
|
|
|
$this->app->alias(ImpersonateManager::class, 'impersonate'); |
|
45
|
|
|
|
|
46
|
|
|
$router = $this->app['router']; |
|
47
|
|
|
$router->group([ |
|
48
|
|
|
'prefix' => '/impersonate', |
|
49
|
|
|
'middleware' => ['web'], |
|
50
|
|
|
'namespace' => 'Lab404\\Impersonate\\Controllers' |
|
51
|
|
|
], function (Router $router) |
|
52
|
|
|
{ |
|
53
|
|
|
$router->get('/take/{id}', 'ImpersonateController@take')->name('impersonate'); |
|
54
|
|
|
$router->get('/leave', 'ImpersonateController@leave')->name('impersonate.leave'); |
|
55
|
|
|
}); |
|
56
|
|
|
|
|
57
|
|
|
$this->registerBladeDirectives(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Bootstrap the application events. |
|
62
|
|
|
* |
|
63
|
|
|
* @return void |
|
64
|
|
|
*/ |
|
65
|
|
|
public function boot() |
|
66
|
|
|
{ |
|
67
|
|
|
$configPath = __DIR__ . '/../config/' . $this->configName . '.php'; |
|
68
|
|
|
|
|
69
|
|
|
$this->publishes([$configPath => config_path($this->configName . '.php')], 'impersonate'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Register plugin blade directives. |
|
74
|
|
|
* |
|
75
|
|
|
* @param void |
|
76
|
|
|
* @return void` |
|
|
|
|
|
|
77
|
|
|
*/ |
|
78
|
|
|
protected function registerBladeDirectives() |
|
79
|
|
|
{ |
|
80
|
|
|
Blade::directive('impersonating', function($expression) { |
|
|
|
|
|
|
81
|
|
|
return '<?php if (app()["auth"]->check() && app()["auth"]->user()->isImpersonated()): ?>'; |
|
82
|
|
|
}); |
|
83
|
|
|
|
|
84
|
|
|
Blade::directive('endImpersonating', function($expression) { |
|
|
|
|
|
|
85
|
|
|
return '<?php endif; ?>'; |
|
86
|
|
|
}); |
|
87
|
|
|
|
|
88
|
|
|
Blade::directive('canImpersonate', function($expression) { |
|
|
|
|
|
|
89
|
|
|
return '<?php if (app()["auth"]->check() && app()["auth"]->user()->canImpersonate()): ?>'; |
|
90
|
|
|
}); |
|
91
|
|
|
|
|
92
|
|
|
Blade::directive('endCanImpersonate', function($expression) { |
|
|
|
|
|
|
93
|
|
|
return '<?php endif; ?>'; |
|
94
|
|
|
}); |
|
95
|
|
|
} |
|
96
|
|
|
} |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.