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.

Wouter J
  • 41,455
  • 15
  • 107
  • 112
Seba
  • 113
  • 8

1 Answers1

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

Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156
  • That sounds logical. However, is it possible to do something like `Command::parse($rawInput)`? I can't find something like that at first sight... – Seba Nov 03 '13 at 17:28
  • 1
    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)` – Seba Nov 03 '13 at 20:50