Invoker icon indicating copy to clipboard operation
Invoker copied to clipboard

[feature] Allow to call via magic methods

Open defaultpage opened this issue 3 years ago • 4 comments

Hi! Are there any plans to support magic methods? I didn't find an answer in the docs.

Example:

class TransportFactory {
    public static function __callStatic(string $method, array $arguments): string {
        return $method;
    }
}

echo $invoker->call([TransportFactory::class, 'some.transport.example']);
// Output:
// some.transport.example

P.S.: Thank you for the development and support of the library.

defaultpage avatar Jul 29 '21 21:07 defaultpage

Is this duplicating #36?

mnapoli avatar Jul 30 '21 12:07 mnapoli

Are there any plans to support magic methods?

FYI they are not supported at the moment.

mnapoli avatar Jul 30 '21 12:07 mnapoli

Is this duplicating #36?

No, this is not a duplicate. Here I decided to leave the question of plans to implement support for magical methods. #36 and #37 describe and resolve unexpected exception if __callStatic magic method is used.

defaultpage avatar Jul 30 '21 14:07 defaultpage

Currently, we can use Closure::fromCallable as an explicit workaround, but the $arguments always will be empty array. Example:

class TransportFactory {
    public static function __callStatic(string $method, array $arguments): string {
        return $method;
    }
}

echo $invoker->call(Closure::fromCallable([TransportFactory::class, 'some.transport.example']));

defaultpage avatar Aug 08 '21 19:08 defaultpage