I am a PHP developer and I used to build web applications with one PHP file per page for a very long time. This resulted in duplicated logic and messy code (even though I didn't know it at the time).
Then one day a co-worker introduced me to the MVC methodology of organising your web application code base. I also learnt about the front controller pattern during this time and I was amazed at how it simplified everything. Whenever I build web applications now I route all web requests to a single PHP file which uses the front controller pattern to create request and response objects, then dispatch the request to the appropriate controller and action. I am very satisfied with the way everything works and I feel as though my code is cleaner for it!
I have recently started writing a couple of command line applications for fun in PHP. Within these I have tried to use the front controller pattern but it doesn't feel quite right. The concept of routing all requests to one file is a little bit redundant because there can only be one entry point (by calling php -f myapp.php -- argumentone argumenttwo
).
It also feels to me as though the concept of routing using controllers and actions is a little bit odd as well. When I have stuck to the MVC pattern with command line applications I almost always end up with one controller with only one or two actions. This seems like a signal that I am not using the front controller (or possibly even the MVC pattern) correctly.
Is there a better way to handle routing and dispatching requests within a command line application? Does the front controller and MVC pattern only apply to web applications? Is there a better design pattern I should be using for command line applications?
Thank you in advance and apologies for my long winded ramble! :D
TLDR - Is there a pattern similar to the front controller pattern for developing command line applications? At the moment the front controller pattern seems like an odd fit.