mirror of
https://github.com/flarum/framework.git
synced 2025-05-13 01:32:39 +08:00

This helps us in decoupling from Laravel, as we only need any implementation of the container contract now.
26 lines
710 B
PHP
26 lines
710 B
PHP
<?php namespace Flarum\Extend;
|
|
|
|
use Illuminate\Contracts\Container\Container;
|
|
|
|
class SerializeAttributes implements ExtenderInterface
|
|
{
|
|
protected $serializer;
|
|
|
|
protected $callback;
|
|
|
|
public function __construct($serializer, $callback)
|
|
{
|
|
$this->serializer = $serializer;
|
|
$this->callback = $callback;
|
|
}
|
|
|
|
public function extend(Container $container)
|
|
{
|
|
$container->make('events')->listen('Flarum\Api\Events\SerializeAttributes', function ($event) {
|
|
if ($event->serializer instanceof $this->serializer) {
|
|
call_user_func_array($this->callback, [&$event->attributes, $event->model, $event->serializer]);
|
|
}
|
|
});
|
|
}
|
|
}
|