Skip to content

Commit 754bb4d

Browse files
standanielsbarryvdh
authored andcommitted
Add support for invokable classes as macro function (#765)
Macros can be used with invokable classes, like so. ``` <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Response; class ResponseMacroServiceProvider extends ServiceProvider { public function boot() { Response::macro('foo', new Foo()); } } class Foo { public function __invoke() { return 'foobar'; } } ``` When running `ide-helper:generate` the following fatal error was thrown. ``` Symfony\Component\Debug\Exception\FatalThrowableError : ReflectionFunction::__construct() expects parameter 1 to be string, object given``` This commit fixes this error.
1 parent bcb881b commit 754bb4d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Alias.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ protected function getMacroFunction($macro_func)
395395
return new \ReflectionMethod($macro_func[0], $macro_func[1]);
396396
}
397397

398+
if (is_object($macro_func) && is_callable($macro_func)) {
399+
return new \ReflectionMethod($macro_func, '__invoke');
400+
}
401+
398402
return new \ReflectionFunction($macro_func);
399403
}
400404

0 commit comments

Comments
 (0)