Get Array Of Arguments With Symfony Console

The symfony console component is a great library for brewing your own CLI applications to help you out with development. I'm working on one right now that helps me quickly write well-formatted and tested data transfer objects. It's called DTOx and you can check it out here!

If you have looked at the console documentation, it is not immediately apparent how you might pass an arbitrarily long argument list to your command. Why would you want to do that? Well, I'd argue if used sparingly, it could allow for a cleaner and shorter command. Here is an example that may be familiar to those who know MVC frameworks:

create model User string:name int:age

The string:name and int:age are arguments, but we would not want to define them for this command, but want to allow for any number of arguments to be parsed. To do so, in defining our last argument, we must specify the mode constant IS_ARRAY as in this code sample:

    'Specify your variables!'

That's all there is to it!

If you enjoyed reading this or learned something, please consider sharing via , , or . Thanks!

If you enjoyed this article, you might like others related to the Software interest.