These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Lab404\Impersonate; |
||
4 | |||
5 | use Illuminate\Routing\Router; |
||
6 | use Illuminate\Support\Facades\Blade; |
||
7 | use Lab404\Impersonate\Middleware\ProtectFromImpersonation; |
||
8 | use Lab404\Impersonate\Services\ImpersonateManager; |
||
9 | |||
10 | /** |
||
11 | * Class ServiceProvider |
||
12 | * |
||
13 | * @package Lab404\Impersonate |
||
14 | */ |
||
15 | class ImpersonateServiceProvider extends \Illuminate\Support\ServiceProvider |
||
16 | { |
||
17 | /** |
||
18 | * @var bool |
||
19 | */ |
||
20 | protected $defer = false; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $configName = 'laravel-impersonate'; |
||
26 | |||
27 | /** |
||
28 | * Register the service provider. |
||
29 | * |
||
30 | * @return void |
||
31 | */ |
||
32 | public function register() |
||
33 | { |
||
34 | $configPath = __DIR__ . '/../config/' . $this->configName . '.php'; |
||
35 | |||
36 | $this->mergeConfigFrom($configPath, $this->configName); |
||
37 | |||
38 | $this->app->bind(ImpersonateManager::class, ImpersonateManager::class); |
||
39 | |||
40 | $this->app->singleton(ImpersonateManager::class, function ($app) |
||
41 | { |
||
42 | return new ImpersonateManager($app); |
||
43 | }); |
||
44 | |||
45 | $this->app->alias(ImpersonateManager::class, 'impersonate'); |
||
46 | |||
47 | $router = $this->app['router']; |
||
48 | $router->macro('impersonate', function () use ($router) { |
||
49 | $router->get('/impersonate/take/{id}', '\Lab404\Impersonate\Controllers\ImpersonateController@take')->name('impersonate'); |
||
50 | $router->get('/impersonate/leave', '\Lab404\Impersonate\Controllers\ImpersonateController@leave')->name('impersonate.leave'); |
||
51 | }); |
||
52 | |||
53 | $this->registerBladeDirectives(); |
||
54 | |||
55 | $this->app['router']->aliasMiddleware('impersonate.protect', ProtectFromImpersonation::class); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Bootstrap the application events. |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | public function boot() |
||
64 | { |
||
65 | $configPath = __DIR__ . '/../config/' . $this->configName . '.php'; |
||
66 | |||
67 | $this->publishes([$configPath => config_path($this->configName . '.php')], 'impersonate'); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Register plugin blade directives. |
||
72 | * |
||
73 | * @param void |
||
74 | * @return void` |
||
0 ignored issues
–
show
|
|||
75 | */ |
||
76 | protected function registerBladeDirectives() |
||
77 | { |
||
78 | Blade::directive('impersonating', function() { |
||
79 | return '<?php if (app()["auth"]->check() && app()["auth"]->user()->isImpersonated()): ?>'; |
||
80 | }); |
||
81 | |||
82 | Blade::directive('endImpersonating', function() { |
||
83 | return '<?php endif; ?>'; |
||
84 | }); |
||
85 | |||
86 | Blade::directive('canImpersonate', function() { |
||
87 | return '<?php if (app()["auth"]->check() && app()["auth"]->user()->canImpersonate()): ?>'; |
||
88 | }); |
||
89 | |||
90 | Blade::directive('endCanImpersonate', function() { |
||
91 | return '<?php endif; ?>'; |
||
92 | }); |
||
93 | } |
||
94 | } |
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.