Skip to content

Commit

Permalink
Segregate interfaces for event dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Jan 23, 2017
1 parent e9f5a66 commit 4a34518
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"phpunit/phpunit": "^5.7"
},
"require": {
"php": ">=5.4",
"league/tactician": "^1.0"
}
}
25 changes: 25 additions & 0 deletions src/EventDispatcher/ContainsListenersInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace BornFree\TacticianDomainEvent\EventDispatcher;

interface ContainsListenersInterface
{
/**
* @param $eventName
* @param callable $listener
* @return mixed
*/
public function addListener($eventName, callable $listener);

/**
* @param string $eventName
* @return callable[]
*/
public function getListeners($eventName);

/**
* @param string $eventName
* @return bool
*/
public function hasListeners($eventName);
}
12 changes: 4 additions & 8 deletions src/EventDispatcher/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace BornFree\TacticianDomainEvent\EventDispatcher;


class EventDispatcher implements EventDispatcherInterface
class EventDispatcher implements EventDispatcherInterface, ContainsListenersInterface
{
/**
* @var callable[][]
Expand All @@ -23,17 +22,15 @@ public function dispatch($event)
}

/**
* @param string $eventName
* @param callable $listener
* @inheritdoc
*/
public function addListener($eventName, callable $listener)
{
$this->listeners[$eventName][] = $listener;
}

/**
* @param string $eventName
* @return callable[]
* @inheritdoc
*/
public function getListeners($eventName)
{
Expand All @@ -45,8 +42,7 @@ public function getListeners($eventName)
}

/**
* @param string $eventName
* @return bool
* @inheritdoc
*/
public function hasListeners($eventName)
{
Expand Down

0 comments on commit 4a34518

Please sign in to comment.