質問

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.

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top