Skip to content

Commit

Permalink
Unify wording.
Browse files Browse the repository at this point in the history
This tweaks the dispatcher contract to use the method dispatch since A)
the class is named dispatcher and B) it unifies the terminology with
“dispatching” jobs…
  • Loading branch information
taylorotwell committed Jan 2, 2017
1 parent a00a201 commit 2dcde69
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/Contracts/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ public function until($event, $payload = []);
public function flush($event);

/**
* Fire an event and call the listeners.
* Dispatch an event and call the listeners.
*
* @param string|object $event
* @param mixed $payload
* @param bool $halt
* @return array|null
*/
public function fire($event, $payload = [], $halt = false);
public function dispatch($event, $payload = [], $halt = false);

/**
* Get the event that is currently firing.
*
* @return string
*/
public function firing();
public function dispatching();

/**
* Remove a set of listeners from the dispatcher.
Expand Down
23 changes: 23 additions & 0 deletions src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ public function flush($event)
$this->fire($event.'_pushed');
}

/**
* Get the event that is currently firing.
*
* @return string
*/
public function dispatching()
{
return $this->firing();
}

/**
* Get the event that is currently firing.
*
Expand All @@ -185,6 +195,19 @@ public function firing()
return last($this->firing);
}

/**
* Fire an event and call the listeners.
*
* @param string|object $event
* @param mixed $payload
* @param bool $halt
* @return array|null
*/
public function dispatch($event, $payload = [], $halt = false)
{
return $this->fire($event, $payload, $halt);
}

/**
* Fire an event and call the listeners.
*
Expand Down
16 changes: 16 additions & 0 deletions src/Illuminate/Foundation/Bus/Dispatchable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Illuminate\Foundation\Bus;

trait Dispatchable
{
/**
* Dispatch the job with the given arguments.
*
* @return void
*/
public static function dispatch()
{
return dispatch(new static(...func_get_args()));
}
}
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/Console/stubs/event.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class DummyClass
{
use InteractsWithSockets, SerializesModels;
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/Console/stubs/job-queued.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class DummyClass implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/Console/stubs/job.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace DummyNamespace;

use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;

class DummyClass
{
use Queueable;
use Dispatchable, Queueable;

/**
* Create a new job instance.
Expand Down
16 changes: 16 additions & 0 deletions src/Illuminate/Foundation/Events/Dispatchable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Illuminate\Foundation\Events;

trait Dispatchable
{
/**
* Dispatch the event with the given arguments.
*
* @return void
*/
public static function dispatch()
{
return event(new static(...func_get_args()));
}
}
36 changes: 18 additions & 18 deletions src/Illuminate/Support/Testing/Fakes/EventFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@
class EventFake implements Dispatcher
{
/**
* All of the events that have been fired keyed by type.
* All of the events that have been dispatched keyed by type.
*
* @var array
*/
protected $events = [];

/**
* Assert if an event was fired based on a truth-test callback.
* Assert if an event was dispatched based on a truth-test callback.
*
* @param string $event
* @param callable|null $callback
* @return void
*/
public function assertFired($event, $callback = null)
public function assertDispatched($event, $callback = null)
{
PHPUnit::assertTrue(
$this->fired($event, $callback)->count() > 0,
"The expected [{$event}] event was not fired."
$this->dispatched($event, $callback)->count() > 0,
"The expected [{$event}] event was not dispatched."
);
}

/**
* Determine if an event was fired based on a truth-test callback.
* Determine if an event was dispatched based on a truth-test callback.
*
* @param string $event
* @param callable|null $callback
* @return void
*/
public function assertNotFired($event, $callback = null)
public function assertNotDispatched($event, $callback = null)
{
PHPUnit::assertTrue(
$this->fired($event, $callback)->count() === 0,
"The unexpected [{$event}] event was fired."
$this->dispatched($event, $callback)->count() === 0,
"The unexpected [{$event}] event was dispatched."
);
}

Expand All @@ -51,9 +51,9 @@ public function assertNotFired($event, $callback = null)
* @param callable|null $callback
* @return \Illuminate\Support\Collection
*/
public function fired($event, $callback = null)
public function dispatched($event, $callback = null)
{
if (! $this->hasFired($event)) {
if (! $this->hasDispatched($event)) {
return collect();
}

Expand All @@ -69,12 +69,12 @@ public function fired($event, $callback = null)
}

/**
* Determine if the given event has been fired.
* Determine if the given event has been dispatched.
*
* @param string $event
* @return bool
*/
public function hasFired($event)
public function hasDispatched($event)
{
return isset($this->events[$event]) && ! empty($this->events[$event]);
}
Expand Down Expand Up @@ -122,7 +122,7 @@ public function hasListeners($eventName)
}

/**
* Register an event and payload to be fired later.
* Register an event and payload to be dispatched later.
*
* @param string $event
* @param array $payload
Expand Down Expand Up @@ -153,7 +153,7 @@ public function subscribe($subscriber)
*/
public function until($event, $payload = [])
{
return $this->fire($event, $payload, true);
return $this->dispatch($event, $payload, true);
}

/**
Expand All @@ -175,19 +175,19 @@ public function flush($event)
* @param bool $halt
* @return array|null
*/
public function fire($event, $payload = [], $halt = false)
public function dispatch($event, $payload = [], $halt = false)
{
$name = is_object($event) ? get_class($event) : (string) $event;

$this->events[$name][] = func_get_args();
}

/**
* Get the event that is currently firing.
* Get the event that is currently dispatching.
*
* @return string
*/
public function firing()
public function dispatching()
{
//
}
Expand Down

0 comments on commit 2dcde69

Please sign in to comment.