5

I want to develop an interactive command based php application, so I did some research and bumped into the Symfony\Console component. This is great, because it lets met run

php script.php command --option

However, the script then runs the command and closes, and I want to be able to run another command. So basically, something like

php script.php

Which then listens on php://stdin for commands, structured as

command --option

then runs the command and starts listening for new commands. When a specific "exit" command is run, the script should terminate.

I'm relatively new to Symfony and the Console component, so any thoughts on how to implement this, using Symfony\Console? Because I really like the way how Symfony\Console abstracts all the command-stuff away.

1 Answer 1

4

Well, you have to enclose your script.php in a cycle like that:

while true {
   <reading stdin>
   <executing command via Symfony2 component>
}

You will be able to terminate the cycle by pressing Ctrl-C

Sign up to request clarification or add additional context in comments.

2 Comments

That sounds logical. However, is it possible to do something like Command::parse($rawInput)? I can't find something like that at first sight...
Allright, thanks I found something, however I had to search for a while. I have to use: $app->run(new StringInput('command --option')); and then wrap it within a while(true)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.