Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. <?php namespace Zizaco\Entrust;
  2.  
  3. /**
  4. * This file is part of Entrust,
  5. * a role & permission management solution for Laravel.
  6. *
  7. * @license MIT
  8. * @package Zizaco\Entrust
  9. */
  10.  
  11. use Illuminate\Support\ServiceProvider;
  12.  
  13. class EntrustServiceProvider extends ServiceProvider
  14. {
  15. /**
  16. * Indicates if loading of the provider is deferred.
  17. *
  18. * @var bool
  19. */
  20. protected $defer = false;
  21.  
  22. /**
  23. * Bootstrap the application events.
  24. *
  25. * @return void
  26. */
  27. public function boot()
  28. {
  29. // Publish config files
  30. $this->publishes([
  31. __DIR__.'/../config/config.php' => config_path('entrust.php'),
  32. ]);
  33.  
  34. // Register commands
  35. $this->commands('command.entrust.migration');
  36.  
  37. // Register blade directives
  38. $this->bladeDirectives();
  39. }
  40.  
  41. /**
  42. * Register the service provider.
  43. *
  44. * @return void
  45. */
  46. public function register()
  47. {
  48. $this->registerEntrust();
  49.  
  50. $this->registerCommands();
  51.  
  52. $this->mergeConfig();
  53. }
  54.  
  55. /**
  56. * Register the blade directives
  57. *
  58. * @return void
  59. */
  60. private function bladeDirectives()
  61. {
  62. // Call to Entrust::hasRole
  63. \Blade::directive('role', function($expression) {
  64. return "<?php if (\\Entrust::hasRole({$expression})) : ?>";
  65. });
  66.  
  67. \Blade::directive('endrole', function($expression) {
  68. return "<?php endif; // Entrust::hasRole ?>";
  69. });
  70.  
  71. // Call to Entrust::can
  72. \Blade::directive('permission', function($expression) {
  73. return "<?php if (\\Entrust::can({$expression})) : ?>";
  74. });
  75.  
  76. \Blade::directive('endpermission', function($expression) {
  77. return "<?php endif; // Entrust::can ?>";
  78. });
  79.  
  80. // Call to Entrust::ability
  81. \Blade::directive('ability', function($expression) {
  82. return "<?php if (\\Entrust::ability({$expression})) : ?>";
  83. });
  84.  
  85. \Blade::directive('endability', function($expression) {
  86. return "<?php endif; // Entrust::ability ?>";
  87. });
  88. }
  89.  
  90. /**
  91. * Register the application bindings.
  92. *
  93. * @return void
  94. */
  95. private function registerEntrust()
  96. {
  97. $this->app->bind('entrust', function ($app) {
  98. return new Entrust($app);
  99. });
  100.  
  101. $this->app->alias('entrust', 'Zizaco\Entrust\Entrust');
  102. }
  103.  
  104. /**
  105. * Register the artisan commands.
  106. *
  107. * @return void
  108. */
  109. private function registerCommands()
  110. {
  111. $this->app->singleton('command.entrust.migration', function ($app) {
  112. return new MigrationCommand();
  113. });
  114. }
  115.  
  116. /**
  117. * Merges user's and entrust's configs.
  118. *
  119. * @return void
  120. */
  121. private function mergeConfig()
  122. {
  123. $this->mergeConfigFrom(
  124. __DIR__.'/../config/config.php', 'entrust'
  125. );
  126. }
  127.  
  128. /**
  129. * Get the services provided.
  130. *
  131. * @return array
  132. */
  133. public function provides()
  134. {
  135. return [
  136. 'command.entrust.migration'
  137. ];
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement