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.
This commit is contained in:
Stan Daniëls
2019-02-18 20:54:27 +01:00
committed by Barry vd. Heuvel
parent bcb881b20d
commit 754bb4d075
+4
View File
@@ -395,6 +395,10 @@ class Alias
return new \ReflectionMethod($macro_func[0], $macro_func[1]); return new \ReflectionMethod($macro_func[0], $macro_func[1]);
} }
if (is_object($macro_func) && is_callable($macro_func)) {
return new \ReflectionMethod($macro_func, '__invoke');
}
return new \ReflectionFunction($macro_func); return new \ReflectionFunction($macro_func);
} }