Skip to content

Instantly share code, notes, and snippets.

@sveneisenschmidt
Created November 25, 2017 15:46
Show Gist options
  • Save sveneisenschmidt/74e162d642c6ac0096067af7cdfae14f to your computer and use it in GitHub Desktop.
Save sveneisenschmidt/74e162d642c6ac0096067af7cdfae14f to your computer and use it in GitHub Desktop.
<?php
namespace Component\Engine\Storage;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Component\Engine\Storage\StorageTrait;
use Component\Engine\Events;
use Component\Engine\Event\ObjectEvent;
use Component\Entity\PlayerInterface;
trait EventStorageTrait
{
use StorageTrait {
savePlayer as invokeSavePlayer;
}
/** @var EventDispatcherInterface */
protected $eventDispatcher;
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->eventDispatcher = $eventDispatcher;
}
public function getEventDispatcher(): EventDispatcherInterface
{
return $this->eventDispatcher;
}
public function savePlayer(PlayerInterface $player): void
{
$this->eventDispatcher->dispatch(Events::PRE_SAVE, $event = new ObjectEvent($player));
$this->invokeSavePlayer($player);
$this->eventDispatcher->dispatch(Events::POST_SAVE, $event);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment