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

[feature] Allow to call via magic methods #39

Open
defaultpage opened this issue Jul 29, 2021 · 4 comments
Open

[feature] Allow to call via magic methods #39

defaultpage opened this issue Jul 29, 2021 · 4 comments

Comments

@defaultpage
Copy link
Contributor

defaultpage commented Jul 29, 2021

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 defaultpage changed the title Calling via magic methods [feature] Allow to call via magic methods Jul 29, 2021
@mnapoli
Copy link
Member

mnapoli commented Jul 30, 2021

Is this duplicating #36?

@mnapoli
Copy link
Member

mnapoli commented Jul 30, 2021

Are there any plans to support magic methods?

FYI they are not supported at the moment.

@defaultpage
Copy link
Contributor Author

defaultpage commented Jul 30, 2021

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
Copy link
Contributor Author

defaultpage commented Aug 8, 2021

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']));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants