1
0
mirror of https://github.com/flarum/core.git synced 2025-07-19 07:41:22 +02:00

Rework public API based on events

This commit is contained in:
Toby Zerner
2015-07-18 22:59:47 +09:30
parent 5085c09c30
commit 57650fa648
136 changed files with 1157 additions and 1245 deletions

View File

@@ -3,6 +3,7 @@
use Flarum\Core\Settings\MemoryCacheSettingsRepository;
use Flarum\Core\Settings\DatabaseSettingsRepository;
use Flarum\Core\Users\User;
use Flarum\Events\ModelAllow;
use Flarum\Support\ServiceProvider;
use Flarum\Extend;
@@ -21,8 +22,13 @@ class CoreServiceProvider extends ServiceProvider
return get_class($command).'Handler@handle';
});
Forum::allow('*', function (Forum $forum, User $user, $action) {
return $user->hasPermission('forum.'.$action) ?: null;
$events = $this->app->make('events');
$events->listen(ModelAllow::class, function (ModelAllow $event) {
if ($event->model instanceof Forum &&
$event->actor->hasPermission('forum.'.$event->action)) {
return true;
}
});
}
@@ -33,7 +39,7 @@ class CoreServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->singleton('Flarum\Core\Settings\SettingsRepository', function() {
$this->app->singleton('Flarum\Core\Settings\SettingsRepository', function () {
return new MemoryCacheSettingsRepository(
new DatabaseSettingsRepository(
$this->app->make('Illuminate\Database\ConnectionInterface')