Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Remove remaining priorities. #17245

Merged
merged 1 commit into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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