1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Permission; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Illuminate\View\Compilers\BladeCompiler; |
7
|
|
|
use Spatie\Permission\Contracts\Permission as PermissionContract; |
8
|
|
|
use Spatie\Permission\Contracts\Role as RoleContract; |
9
|
|
|
|
10
|
|
|
class PermissionServiceProvider extends ServiceProvider |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Bootstrap the application services. |
14
|
|
|
* |
15
|
|
|
* @param PermissionRegistrar $permissionLoader |
|
|
|
|
16
|
|
|
*/ |
17
|
|
|
public function boot() |
18
|
|
|
{ |
19
|
|
|
$this->publishes([ |
20
|
|
|
__DIR__.'/../resources/config/laravel-permission.php' => $this->app->configPath().'/'.'laravel-permission.php', |
21
|
|
|
], 'config'); |
22
|
|
|
|
23
|
|
|
if (!class_exists('CreatePermissionTables')) { |
24
|
|
|
// Publish the migration |
25
|
|
|
$timestamp = date('Y_m_d_His', time()); |
26
|
|
|
$this->publishes([ |
27
|
|
|
__DIR__.'/../resources/migrations/create_permission_tables.php.stub' => $this->app->databasePath().'/migrations/'.$timestamp.'_create_permission_tables.php', |
|
|
|
|
28
|
|
|
], 'migrations'); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Finish configuring the application. |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
public function booted(PermissionRegistrar $permissionLoader) |
38
|
|
|
{ |
39
|
|
|
$permissionLoader->registerPermissions(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Register the application services. |
44
|
|
|
*/ |
45
|
|
|
public function register() |
46
|
|
|
{ |
47
|
|
|
$this->mergeConfigFrom(__DIR__.'/../resources/config/laravel-permission.php', 'laravel-permission'); |
48
|
|
|
|
49
|
|
|
$this->registerModelBindings(); |
50
|
|
|
|
51
|
|
|
$this->registerBladeExtensions(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Bind the Permission and Role model into the IoC. |
56
|
|
|
*/ |
57
|
|
|
protected function registerModelBindings() |
58
|
|
|
{ |
59
|
|
|
$config = $this->app->config['laravel-permission.models']; |
|
|
|
|
60
|
|
|
|
61
|
|
|
$this->app->bind(PermissionContract::class, $config['permission']); |
62
|
|
|
$this->app->bind(RoleContract::class, $config['role']); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Register the blade extensions. |
67
|
|
|
*/ |
68
|
|
|
protected function registerBladeExtensions() |
69
|
|
|
{ |
70
|
|
|
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) { |
71
|
|
|
$bladeCompiler->directive('role', function ($role) { |
72
|
|
|
return "<?php if(auth()->check() && auth()->user()->hasRole({$role})): ?>"; |
73
|
|
|
}); |
74
|
|
|
$bladeCompiler->directive('endrole', function () { |
75
|
|
|
return '<?php endif; ?>'; |
76
|
|
|
}); |
77
|
|
|
|
78
|
|
|
$bladeCompiler->directive('hasrole', function ($role) { |
79
|
|
|
return "<?php if(auth()->check() && auth()->user()->hasRole({$role})): ?>"; |
80
|
|
|
}); |
81
|
|
|
$bladeCompiler->directive('endhasrole', function () { |
82
|
|
|
return '<?php endif; ?>'; |
83
|
|
|
}); |
84
|
|
|
|
85
|
|
|
$bladeCompiler->directive('hasanyrole', function ($roles) { |
86
|
|
|
return "<?php if(auth()->check() && auth()->user()->hasAnyRole({$roles})): ?>"; |
87
|
|
|
}); |
88
|
|
|
$bladeCompiler->directive('endhasanyrole', function () { |
89
|
|
|
return '<?php endif; ?>'; |
90
|
|
|
}); |
91
|
|
|
|
92
|
|
|
$bladeCompiler->directive('hasallroles', function ($roles) { |
93
|
|
|
return "<?php if(auth()->check() && auth()->user()->hasAllRoles({$roles})): ?>"; |
94
|
|
|
}); |
95
|
|
|
$bladeCompiler->directive('endhasallroles', function () { |
96
|
|
|
return '<?php endif; ?>'; |
97
|
|
|
}); |
98
|
|
|
}); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.