From 7c441f80d4953ebc9868f7deb83e26384e493b30 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 6 May 2015 11:23:12 +0930 Subject: [PATCH] Add shortcut API to serialize attributes --- framework/core/src/Support/ServiceProvider.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/framework/core/src/Support/ServiceProvider.php b/framework/core/src/Support/ServiceProvider.php index 715d59fbb..6de27220d 100644 --- a/framework/core/src/Support/ServiceProvider.php +++ b/framework/core/src/Support/ServiceProvider.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Events\Dispatcher; use Flarum\Core\Models\Notification; use Flarum\Core\Models\User; use Flarum\Core\Models\Post; +use Closure; class ServiceProvider extends IlluminateServiceProvider { @@ -75,4 +76,13 @@ class ServiceProvider extends IlluminateServiceProvider } }); } + + protected function serializeAttributes($serializer, Closure $callback) + { + $this->app['events']->listen('Flarum\Api\Events\SerializeAttributes', function ($event) use ($serializer, $callback) { + if ($event->serializer instanceof $serializer) { + $callback($event->attributes, $event->model); + } + }); + } }