8000 [Console] Way to access arguments/options before command is ran · Issue #11912 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Way to access arguments/options before command is ran #11912

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

Closed
konradpodgorski opened this issue Sep 12, 2014 · 1 comment
Closed

Comments

@konradpodgorski
Copy link

Console Event ConsoleEvents::COMMAND doesn't provide any way to read/modify input arguments/options before command is ran. It's because binding code (argument string to command arguments/options) is within $command->run($input, $output); method itself.

    public function onCommandExecution(ConsoleCommandEvent $event)
    {
        $command = $event->getCommand();

        if ($command instanceof GameAwareCommand) { // this apply only to certain commands implementing interface
            /** @var \Symfony\Bundle\FrameworkBundle\Console\Application $application */
            $application = $command->getApplication();

            /** @var ArgvInput $input */
            $input = $event->getInput();

            /** @var Command $command */
            $command->getDefinition();

            $input->getArguments(); // empty array
            $input->getOptions(); // empty array
        }
    }

Input instance returned by $event->getInput() is pretty much useless because it's empty (at least through public methods).

The best would be to dispatch additional event after parsing and binding but before running, this was already discussed few times e.g. here #11384 and it's not something we could do before 3.0

Do you have opinion about this? I need this feature to read input value before command execution so I'm willing to make proper contribution once I get some feedback about the best approach. Thanks

@konradpodgorski
Copy link
Author

After adding this I noticed there is an issue for this here #10695 I will continue discussion there

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

1 participant
0