mirror of
https://github.com/flarum/core.git
synced 2025-10-24 05:06:05 +02:00
Finalize Flarum\Foundation namespace
This commit is contained in:
38
src/Foundation/DispatchEventsTrait.php
Normal file
38
src/Foundation/DispatchEventsTrait.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Foundation;
|
||||
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
trait DispatchEventsTrait
|
||||
{
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* Dispatch all events for an entity.
|
||||
*
|
||||
* @param object $entity
|
||||
* @param User $actor
|
||||
*/
|
||||
public function dispatchEventsFor($entity, User $actor = null)
|
||||
{
|
||||
foreach ($entity->releaseEvents() as $event) {
|
||||
$event->actor = $actor;
|
||||
|
||||
$this->events->fire($event);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user