Symfony Console Additions v0.6.0
I released [efrane/console-additions](https://packagist.org/packages/efrane/console-additions)
v0.6.0 today. More than a year after the last bigger release this probably could have been a v1.0. However, I still feel like there’s some fundamentals I do with Symfony’s Console component in my everyday work which I would like to extract into a reusable form in this library.
So, what’s changed?
For one, this development episode was focused on reorganising the code. There’s still very few files in the repository but that doesn’t mean that there wasn’t room for optimisation. The result of this is, that the tests
folder now resemble the folder structure of the src
folder, thus making it easier to find the corresponding test file.
The bigger change is a partial rewrite of command batches. Before, the Batch class internally managed every possible action as a combination of strings and weird arrays. This type-conglomerate lead to a quite a few ugly places in the code which felt like they might break at a moment’s notice. Since this version, Batch internally relies on Action classes which know how to handle themselves. This also means, that Batch just became that much more powerful since all Batch wants to know about them is how to represent them as a string and a way to start their execution:
|
|
Usable actions are now:
StringCommandAction
- This handles executing console commands given a full command signatureInstanceCommandAction
- No need to do string parsing of a signature? Pass a command instance to this one!MessageAction
- This is your basicecho
action. Especially when PHP-izing former shell scripts, this can come in quite handyProcessAction
- Pass a configured Process from the Symfony Process component to this oneShellAction
- Just want to execute a shell command and don’t feel like configuring the process yourself? This one is there for your convenience!
All of the built-in actions have convenience methods on Batch, e.g. $batch->addProcess()
or $batch->addMessage()
.
Along with these internal updates came the jump to PHP 7.0 or newer as a language dependency and Symfony Components 3.4 or newer are required to work with this library now. The latter also means that string parsing for commands in $batch->addShell()
has been deprecated and will be removed in the next release. I highly encourage any user of this library to switch to the array-Syntax.