Skip to content

Commit

Permalink
Renamed releaseGeneratorEvents to emitGeneratedEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Nov 25, 2014
1 parent 30af95d commit fe69665
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
6 changes: 3 additions & 3 deletions spec/League/Event/EmitterSpec.php
Expand Up @@ -77,7 +77,7 @@ public function it_should_return_an_empty_array_when_an_event_has_no_listeners()

public function it_should_allow_you_to_emit_plain_events()
{
$callback = function () {};
$callback = CallbackListener::fromCallable(function () {});
$this->addListener('event', $callback)->shouldReturn($this);
$this->emit('event')->shouldReturnAnInstanceOf('League\Event\Event');
}
Expand Down Expand Up @@ -146,13 +146,13 @@ public function it_should_prioritize_listeners(CallbackListener $first, Callback
$this->getListeners('event')->shouldReturn([$second, $first]);
}

public function it_should_release_generator_events(GeneratorInterface $generator, ListenerInterface $listener)
public function it_should_emit_generator_events(GeneratorInterface $generator, ListenerInterface $listener)
{
$event = new Event('name');
$this->addListener($event->getName(), $listener);
$listener->handle($event)->shouldBeCalled();
$generator->releaseEvents()->willReturn([$event]);
$this->releaseGeneratorEvents($generator)->shouldReturn([$event]);
$this->emitGeneratedEvents($generator)->shouldReturn([$event]);
}

public function getMatchers()
Expand Down
11 changes: 11 additions & 0 deletions src/CallbackListener.php
Expand Up @@ -50,4 +50,15 @@ public function isListener($listener)

return $this->callback === $listener;
}

/**
* Named constructor
*
* @param callable $callable
* @return static
*/
public static function fromCallable(callable $callable)
{
return new static($callable);
}
}
10 changes: 5 additions & 5 deletions src/Emitter.php
Expand Up @@ -109,11 +109,11 @@ protected function ensureListener($listener)
return $listener;
}

if (! is_callable($listener)) {
throw new InvalidArgumentException('Listeners should be be ListenerInterface, Closure or callable. Received type: '.gettype($listener));
if (is_callable($listener)) {
return CallbackListener::fromCallable($listener);
}

return new CallbackListener($listener);
throw new InvalidArgumentException('Listeners should be be ListenerInterface, Closure or callable. Received type: '.gettype($listener));
}

/**
Expand Down Expand Up @@ -189,7 +189,7 @@ public function emitBatch(array $events)
/**
* {@inheritdoc}
*/
public function releaseGeneratorEvents(GeneratorInterface $generator)
public function emitGeneratedEvents(GeneratorInterface $generator)
{
$events = $generator->releaseEvents();

Expand Down Expand Up @@ -246,7 +246,7 @@ protected function prepareEvent($event)
protected function ensureEvent($event)
{
if (is_string($event)) {
return new Event($event);
return Event::named($event);
}

if (! $event instanceof EventInterface) {
Expand Down
2 changes: 1 addition & 1 deletion src/EmitterInterface.php
Expand Up @@ -87,5 +87,5 @@ public function emitBatch(array $events);
*
* @return EventInterface[]
*/
public function releaseGeneratorEvents(GeneratorInterface $generator);
public function emitGeneratedEvents(GeneratorInterface $generator);
}

0 comments on commit fe69665

Please sign in to comment.