Created
November 25, 2017 15:46
-
-
Save sveneisenschmidt/74e162d642c6ac0096067af7cdfae14f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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