Skip to content

Commit

Permalink
Remove remaining priorities. (#17245)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored and taylorotwell committed Jan 10, 2017
1 parent 76e30db commit 19fcecf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
3 changes: 1 addition & 2 deletions src/Illuminate/Contracts/View/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ public function share($key, $value = null);
*
* @param array|string $views
* @param \Closure|string $callback
* @param int|null $priority
* @return array
*/
public function composer($views, $callback, $priority = null);
public function composer($views, $callback);

/**
* Register a view creator event.
Expand Down
26 changes: 9 additions & 17 deletions src/Illuminate/View/Concerns/ManagesEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ public function composers(array $composers)
*
* @param array|string $views
* @param \Closure|string $callback
* @param int|null $priority
* @return array
*/
public function composer($views, $callback, $priority = null)
public function composer($views, $callback)
{
$composers = [];

foreach ((array) $views as $view) {
$composers[] = $this->addViewEvent($view, $callback, 'composing: ', $priority);
$composers[] = $this->addViewEvent($view, $callback, 'composing: ');
}

return $composers;
Expand All @@ -70,19 +69,18 @@ public function composer($views, $callback, $priority = null)
* @param string $view
* @param \Closure|string $callback
* @param string $prefix
* @param int|null $priority
* @return \Closure|null
*/
protected function addViewEvent($view, $callback, $prefix = 'composing: ', $priority = null)
protected function addViewEvent($view, $callback, $prefix = 'composing: ')
{
$view = $this->normalizeName($view);

if ($callback instanceof Closure) {
$this->addEventListener($prefix.$view, $callback, $priority);
$this->addEventListener($prefix.$view, $callback);

return $callback;
} elseif (is_string($callback)) {
return $this->addClassEvent($view, $callback, $prefix, $priority);
return $this->addClassEvent($view, $callback, $prefix);
}
}

Expand All @@ -92,10 +90,9 @@ protected function addViewEvent($view, $callback, $prefix = 'composing: ', $prio
* @param string $view
* @param string $class
* @param string $prefix
* @param int|null $priority
* @return \Closure
*/
protected function addClassEvent($view, $class, $prefix, $priority = null)
protected function addClassEvent($view, $class, $prefix)
{
$name = $prefix.$view;

Expand All @@ -106,7 +103,7 @@ protected function addClassEvent($view, $class, $prefix, $priority = null)
$class, $prefix
);

$this->addEventListener($name, $callback, $priority);
$this->addEventListener($name, $callback);

return $callback;
}
Expand Down Expand Up @@ -164,16 +161,11 @@ protected function classEventMethodForPrefix($prefix)
*
* @param string $name
* @param \Closure $callback
* @param int|null $priority
* @return void
*/
protected function addEventListener($name, $callback, $priority = null)
protected function addEventListener($name, $callback)
{
if (is_null($priority)) {
$this->events->listen($name, $callback);
} else {
$this->events->listen($name, $callback, $priority);
}
$this->events->listen($name, $callback);
}

/**
Expand Down
12 changes: 0 additions & 12 deletions tests/View/ViewFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,6 @@ public function testComposersAreProperlyRegistered()
$this->assertEquals('bar', $callback());
}

public function testComposersAreProperlyRegisteredWithPriority()
{
$factory = $this->getFactory();
$factory->getDispatcher()->shouldReceive('listen')->once()->with('composing: foo', m::type('Closure'), 1);
$callback = $factory->composer('foo', function () {
return 'bar';
}, 1);
$callback = $callback[0];

$this->assertEquals('bar', $callback());
}

public function testComposersCanBeMassRegistered()
{
$factory = $this->getFactory();
Expand Down

0 comments on commit 19fcecf

Please sign in to comment.