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.5] Don't bind macro when it is not a Closure #21980

Merged
merged 1 commit into from
Nov 6, 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
10 changes: 5 additions & 5 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1254,12 +1254,12 @@ public function __call($method, $parameters)
return $this->localMacros[$method](...$parameters);
}

if (isset(static::$macros[$method]) and static::$macros[$method] instanceof Closure) {
return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters);
}

if (isset(static::$macros[$method])) {
return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters);
if (static::$macros[$method] instanceof Closure) {
return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters);
}

return call_user_func_array(static::$macros[$method], $parameters);
}

if (method_exists($this->model, $scope = 'scope'.ucfirst($method))) {
Expand Down
7 changes: 6 additions & 1 deletion tests/Database/DatabaseEloquentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,12 @@ public function testGlobalMacrosAreCalledOnBuilder()
return $bar;
});

$this->assertEquals($this->getBuilder()->foo('bar'), 'bar');
Builder::macro('bam', [Builder::class, 'getQuery']);

$builder = $this->getBuilder();

$this->assertEquals($builder->foo('bar'), 'bar');
$this->assertEquals($builder->bam(), $builder->getQuery());
}

public function testGetModelsProperlyHydratesModels()
Expand Down