Blogpost about console-skeleton-app for your console application https://t.co/WuVq0GZlxE #PHP #ZF #console #develop
— Gianluca Arbezzano (@GianArb) June 23, 2015
I’m writing a skeleton app to build console/bash application in PHP. This project is very easy and it depends on ZF\Console a zfcampus project and Zend\Console builds by ZF community. I have a todo list for the future but for the time being it’s just a blog post about these two modules.
- Integration with container system to manage dependency injection
- Docs to test your command
- Use cases and different implementations
ZF\Console and other components
- ZF\Console is maintained by zfcampus and it is used by Apigility
- zendframework\zend-console is maintained by zendframework, all the info are in the documantation
Tree
This is my folders structure proposal, there are three entrypoint in the bin
directory, one for bash, one for php and a bat for Window.
I use composer to manage my dependencies and I included .lock file because this project is an APPLICATION not a library..
/config
directory contains only routing definitions but in the future we can add services and other configurations.
src/Command/
contains my commands.
Bootstrap
The Application’s entrypoints are just example and they require few changes.
First we have to change the version in the parameters.php configuration file and also change the application name 'app'
to what fits.
To load configurations from different sources I will use the well known Zend\Config
component.
Routes
config/routes.php
contains router configurations. This is just an example but you can see all options here.
Command
Basic command to wish you a good day! I decided that a command doesn’t extends any class because in my opinion is a good way to impart readability and simplicity.
Troubleshooting and tricks
- OSx return an error because zf-console use a function blocked into the mac os php installation. Have a look at PR#22
- See this article to package your application in a phar archive..