Skip to content

Commit

Permalink
Remove priority. (#17303)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored and taylorotwell committed Jan 15, 2017
1 parent 3a06b5a commit 8f1798e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 deletions.
52 changes: 21 additions & 31 deletions src/Illuminate/Database/Eloquent/Concerns/HasEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait HasEvents
/**
* User exposed observable events.
*
* These are extra user-defind events observers may subscribe to.
* These are extra user-defined events observers may subscribe to.
*
* @var array
*/
Expand All @@ -28,10 +28,9 @@ trait HasEvents
* Register an observer with the Model.
*
* @param object|string $class
* @param int $priority
* @return void
*/
public static function observe($class, $priority = 0)
public static function observe($class)
{
$instance = new static;

Expand All @@ -42,7 +41,7 @@ public static function observe($class, $priority = 0)
// it into the model's event system, making it convenient to watch these.
foreach ($instance->getObservableEvents() as $event) {
if (method_exists($class, $event)) {
static::registerModelEvent($event, $className.'@'.$event, $priority);
static::registerModelEvent($event, $className.'@'.$event);
}
}
}
Expand Down Expand Up @@ -108,15 +107,14 @@ public function removeObservableEvents($observables)
*
* @param string $event
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
protected static function registerModelEvent($event, $callback, $priority = 0)
protected static function registerModelEvent($event, $callback)
{
if (isset(static::$dispatcher)) {
$name = static::class;

static::$dispatcher->listen("eloquent.{$event}: {$name}", $callback, $priority);
static::$dispatcher->listen("eloquent.{$event}: {$name}", $callback);
}
}

Expand Down Expand Up @@ -169,96 +167,88 @@ protected function fireCustomModelEvent($event, $method)
* Register a saving model event with the dispatcher.
*
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function saving($callback, $priority = 0)
public static function saving($callback)
{
static::registerModelEvent('saving', $callback, $priority);
static::registerModelEvent('saving', $callback);
}

/**
* Register a saved model event with the dispatcher.
*
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function saved($callback, $priority = 0)
public static function saved($callback)
{
static::registerModelEvent('saved', $callback, $priority);
static::registerModelEvent('saved', $callback);
}

/**
* Register an updating model event with the dispatcher.
*
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function updating($callback, $priority = 0)
public static function updating($callback)
{
static::registerModelEvent('updating', $callback, $priority);
static::registerModelEvent('updating', $callback);
}

/**
* Register an updated model event with the dispatcher.
*
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function updated($callback, $priority = 0)
public static function updated($callback)
{
static::registerModelEvent('updated', $callback, $priority);
static::registerModelEvent('updated', $callback);
}

/**
* Register a creating model event with the dispatcher.
*
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function creating($callback, $priority = 0)
public static function creating($callback)
{
static::registerModelEvent('creating', $callback, $priority);
static::registerModelEvent('creating', $callback);
}

/**
* Register a created model event with the dispatcher.
*
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function created($callback, $priority = 0)
public static function created($callback)
{
static::registerModelEvent('created', $callback, $priority);
static::registerModelEvent('created', $callback);
}

/**
* Register a deleting model event with the dispatcher.
*
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function deleting($callback, $priority = 0)
public static function deleting($callback)
{
static::registerModelEvent('deleting', $callback, $priority);
static::registerModelEvent('deleting', $callback);
}

/**
* Register a deleted model event with the dispatcher.
*
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function deleted($callback, $priority = 0)
public static function deleted($callback)
{
static::registerModelEvent('deleted', $callback, $priority);
static::registerModelEvent('deleted', $callback);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,8 @@ public function testCloneModelMakesAFreshCopyOfTheModel()
public function testModelObserversCanBeAttachedToModels()
{
EloquentModelStub::setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('listen')->once()->with('eloquent.creating: EloquentModelStub', 'EloquentTestObserverStub@creating', 0);
$events->shouldReceive('listen')->once()->with('eloquent.saved: EloquentModelStub', 'EloquentTestObserverStub@saved', 0);
$events->shouldReceive('listen')->once()->with('eloquent.creating: EloquentModelStub', 'EloquentTestObserverStub@creating');
$events->shouldReceive('listen')->once()->with('eloquent.saved: EloquentModelStub', 'EloquentTestObserverStub@saved');
$events->shouldReceive('forget');
EloquentModelStub::observe(new EloquentTestObserverStub);
EloquentModelStub::flushEventListeners();
Expand All @@ -1184,8 +1184,8 @@ public function testModelObserversCanBeAttachedToModels()
public function testModelObserversCanBeAttachedToModelsWithString()
{
EloquentModelStub::setEventDispatcher($events = m::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('listen')->once()->with('eloquent.creating: EloquentModelStub', 'EloquentTestObserverStub@creating', 0);
$events->shouldReceive('listen')->once()->with('eloquent.saved: EloquentModelStub', 'EloquentTestObserverStub@saved', 0);
$events->shouldReceive('listen')->once()->with('eloquent.creating: EloquentModelStub', 'EloquentTestObserverStub@creating');
$events->shouldReceive('listen')->once()->with('eloquent.saved: EloquentModelStub', 'EloquentTestObserverStub@saved');
$events->shouldReceive('forget');
EloquentModelStub::observe('EloquentTestObserverStub');
EloquentModelStub::flushEventListeners();
Expand Down

0 comments on commit 8f1798e

Please sign in to comment.