diff --git a/composer.json b/composer.json index 338431f..106885e 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ ], "require": { "php": ">=5.3.0", - "psr/log": "*" + "psr/log": "*", + "symfony/event-dispatcher": ">=2.1" }, "require-dev": { "doctrine/common": ">=2.3" diff --git a/src/Phpforce/Common/AbstractHasDispatcher.php b/src/Phpforce/Common/AbstractHasDispatcher.php new file mode 100644 index 0000000..66cc014 --- /dev/null +++ b/src/Phpforce/Common/AbstractHasDispatcher.php @@ -0,0 +1,52 @@ +eventDispatcher = $eventDispatcher; + } + /** + * Get event dispatcher + * + * If no event dispatcher is supplied, a new one is created. This one will + * then be used internally by the Accelerate library. + * + * @return EventDispatcherInterface + */ + public function getEventDispatcher() + { + if (null == $this->eventDispatcher) { + $this->eventDispatcher = new EventDispatcher(); + } + return $this->eventDispatcher; + } + /** + * Dispatch an event + * + * @param string $name Name of event: see Events.php + * @param Event $event Event object + * + * @return Event + */ + protected function dispatch($name, Event $event) + { + return $this->getEventDispatcher()->dispatch($name, $event); + } +}