setGate() public static method

public static setGate ( Flarum\Core\Access\Gate $gate )
$gate Flarum\Core\Access\Gate
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     $this->loadViewsFrom(__DIR__ . '/../../views', 'flarum');
     $this->app->make('Illuminate\\Contracts\\Bus\\Dispatcher')->mapUsing(function ($command) {
         return get_class($command) . 'Handler@handle';
     });
     $this->app->make('flarum.gate')->before(function (User $actor, $ability, $model = null) {
         if ($actor->isAdmin() || !$model && $actor->hasPermission($ability)) {
             return true;
         }
         return $this->app->make('events')->until(new GetPermission($actor, $ability, [$model]));
     });
     $this->registerPostTypes();
     CommentPost::setFormatter($this->app->make('flarum.formatter'));
     User::setHasher($this->app->make('hash'));
     User::setGate($this->app->make('flarum.gate'));
     $events = $this->app->make('events');
     $events->subscribe('Flarum\\Core\\Listener\\DiscussionMetadataUpdater');
     $events->subscribe('Flarum\\Core\\Listener\\UserMetadataUpdater');
     $events->subscribe('Flarum\\Core\\Listener\\EmailConfirmationMailer');
     $events->subscribe('Flarum\\Core\\Listener\\DiscussionRenamedNotifier');
     $events->subscribe('Flarum\\Core\\Listener\\FloodController');
     $events->subscribe('Flarum\\Core\\Access\\DiscussionPolicy');
     $events->subscribe('Flarum\\Core\\Access\\GroupPolicy');
     $events->subscribe('Flarum\\Core\\Access\\PostPolicy');
     $events->subscribe('Flarum\\Core\\Access\\UserPolicy');
     $events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     $this->loadViewsFrom(__DIR__ . '/../../views', 'flarum');
     $this->app->make('Illuminate\\Contracts\\Bus\\Dispatcher')->mapUsing(function ($command) {
         return get_class($command) . 'Handler@handle';
     });
     $this->app->make('flarum.gate')->before(function (User $actor, $ability, $model = null) {
         // Fire an event so that core and extension policies can hook into
         // this permission query and explicitly grant or deny the
         // permission.
         $allowed = $this->app->make('events')->until(new GetPermission($actor, $ability, $model));
         if (!is_null($allowed)) {
             return $allowed;
         }
         // If no policy covered this permission query, we will only grant
         // the permission if the actor's groups have it. Otherwise, we will
         // not allow the user to perform this action.
         if ($actor->isAdmin() || !$model && $actor->hasPermission($ability)) {
             return true;
         }
         return false;
     });
     $this->registerPostTypes();
     CommentPost::setFormatter($this->app->make('flarum.formatter'));
     User::setHasher($this->app->make('hash'));
     User::setGate($this->app->make('flarum.gate'));
     $events = $this->app->make('events');
     $events->subscribe('Flarum\\Core\\Listener\\DiscussionMetadataUpdater');
     $events->subscribe('Flarum\\Core\\Listener\\UserMetadataUpdater');
     $events->subscribe('Flarum\\Core\\Listener\\EmailConfirmationMailer');
     $events->subscribe('Flarum\\Core\\Listener\\DiscussionRenamedNotifier');
     $events->subscribe('Flarum\\Core\\Access\\DiscussionPolicy');
     $events->subscribe('Flarum\\Core\\Access\\GroupPolicy');
     $events->subscribe('Flarum\\Core\\Access\\PostPolicy');
     $events->subscribe('Flarum\\Core\\Access\\UserPolicy');
     $events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']);
 }