Completed
Push — master ( bf255a...3609d1 )
by Marceau
02:21
created

ImpersonateServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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`
0 ignored issues
show
Documentation introduced by
The doc-type void` could not be parsed: Unknown type name "void`" at position 0. (view supported doc-types)

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.

Loading history...
77
     */
78
    protected function registerBladeDirectives()
79
    {
80
        Blade::directive('impersonating', function($expression) {
0 ignored issues
show
Unused Code introduced by
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
            return '<?php if (app()["auth"]->check() && app()["auth"]->user()->isImpersonated()): ?>';
82
        });
83
84
        Blade::directive('endImpersonating', function($expression) {
0 ignored issues
show
Unused Code introduced by
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
            return '<?php endif; ?>';
86
        });
87
88
        Blade::directive('canImpersonate', function($expression) {
0 ignored issues
show
Unused Code introduced by
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
            return '<?php if (app()["auth"]->check() && app()["auth"]->user()->canImpersonate()): ?>';
90
        });
91
92
        Blade::directive('endCanImpersonate', function($expression) {
0 ignored issues
show
Unused Code introduced by
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
            return '<?php endif; ?>';
94
        });
95
    }
96
}