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

CommandInterface misses getHandler() method #182

Open
nikic opened this issue Aug 26, 2023 · 3 comments
Open

CommandInterface misses getHandler() method #182

nikic opened this issue Aug 26, 2023 · 3 comments

Comments

@nikic
Copy link

nikic commented Aug 26, 2023

CommandInterface is missing the getHandler() method, which is needed to do anything useful with the getCommand() return value.

Unfortunately, adding the method is technically a breaking change :/

@tflori
Copy link
Member

tflori commented Aug 26, 2023

For library it is not neccessary, that a command has a handler. It is just an object that is returned if the user enters the name as an argument.

What you do with it is up to you. You can define your own CommandInterface that extends the one from getopt-php and defines this get handler or handle method. I for my part like a handle method more than a getHandler method.

@nikic
Copy link
Author

nikic commented Aug 26, 2023

In that case, what is the recommended way of using the getCommand() return value in a type-safe way?

What I'm currently doing is basically this:

$command = $getOpt->getCommand();
if (!$command) {
   // Error
}

$command->getHandler()($getOpt);

But this doesn't type check, because getCommand() returns CommandInterface, which does not have getHandler().

I do agree that requiring getHandler() in particular is maybe not ideal, but I feel like there should be some standardized interface (e.g. a handle() method) for invoking the command. Otherwise using getCommand() would always require a check that the Command is of some more specific type, kind of defeating the point of having an interface for it.

@tflori
Copy link
Member

tflori commented Nov 4, 2023

Personally I have an abstract command class that defines a handle method and I prefer it that way. But it would be a breaking change that a handle method is required by the interface.

But what I'm most afraid is that the actions will not work anymore and I'm very much bored of that crap from github (had to change it first to github actions because travis said pay or leave and now the pipelines don't work anymore because they introduce breaking changes without proper versioning). So at the moment I'm not doing anything. If you want you can create a MR to fix the actions and a MR to introduce a handle method for the next major release.

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