I recently took the Symfony2 plunge and started working on a little fun side project (more on that later).
Anyway, this particular project involves sending out daily text messages using the rather awesome Twilio API so I decided to use a Symfony2 task for this. The documentation on how to actually add your own task is a bit sparse so I figured I’d share.
The process is actually pretty straight forward:
- In your bundle create a directory named “Command” (without the quotes).
- Create a file that extends ContainerAwareCommand
- Create a protected function configure – “protected function configure()” to allow you to configure the name of your task and add any options or arguments you might need.
- Create a protected function execute – “protected function execute(InputInterface $input, OutputInterface $output)” to actually do whatever needs to be done.
- Thats it! Now you can run app/console and you’ll see your task.
Here is the code for mine: