Additional tasks to streamline your workflow
– November 08, 2008
– 9 comments
sfTaskExtraPlugin is a plugin maintained by the symfony core
team. It adds a number of useful tasks
to your symfony command line to help streamline your workflow. This plugin is
relatively young, so I will just be discussing those tasks that we'll be using
for today's Plugin Developers
Day. I should also note this plugin requires symfony 1.2.
We now turn our focus to easing the process of creating, developing and
releasing plugins. The following tasks are included in
Very much like
generate:app task, the
generate:plugin task creates a basic
plugin directory structure:
$ ./symfony generate:plugin myFirstPlugin
After running this command you should see the following plugin structure in your project's
myFirstPlugin/ config/ myFirstPluginConfiguration.class.php lib/ test/ bin/ prove.php bootstrap/ functional.php unit.php fixtures/ project/ functional/ unit/ LICENSE README package.xml.tmpl
As you can see, part of what this task does is setup a proper testing
environment for your plugin, including an isolated symfony project to run your
plugin's functional tests through. Once you've created your test scripts, you can easily execute them all by running the
prove.php script before committing your code:
$ php plugins/myFirstPlugin/test/bin/prove.php
Building a robust unit and functional testing suite is a strongly recommended best practice, but if you would rather not bother you can simply include the
--skip-test-diroption when generating your plugin.
Often times a plugin will require one or more modules to support its
functionality in the project, such as an administrative backend interface. In
order for your module to be easily customizable for its housing project you
will need to provide a "stub" actions class that can be replicated and
customized in an application's
Previously this would have involved either creating the module directory
structure by hand, or running
generate:module in your application and then
copying, modifying and creating new files in your plugin. This process is now
much more streamlined thanks to the
$ ./symfony generate:plugin-module myFirstPlugin myFirstModule
Executing this command will add the following to your plugin's directory structure:
modules/ myFirstModule/ actions/ actions.class.php lib/ BasemyFirstModuleActions.class.php templates/ test/ functional/ myFirstModuleActionsTest.php
As you develop this module, write all your action code in the
/lib/BasemyFirstModuleActions.class.php file. Leaving the
actions.class.php file empty makes it possible to replicate that file in the
project and not lose or have to duplicate code from the plugin; this will be
taken care of by the symfony autoloader and the magic of OOP inheritance.
This task also creates a functional test script for the new module and updates
the embedded test project's
config/settings.yml to enable the module.
Anyone who has released a symfony plugin in the past is familiar with the
tedious task of filling out the necessary values in the requisite
package.xml file. We have added the
plugin:package task in order to speed
up this process.
$ ./symfony plugin:package myFirstPlugin
This task will look for either a
package.xml.tmpl file in
the plugin directory. If neither are found, the task will package the plugin
using a default
package.xml template. In any case, if any field values are
not known the task will take advantage of one of the new symfony 1.2 task
features and ask you for that information.
Once the task knows what it needs to package the plugin, a
myFirstPlugin-0.0.1.tgz file will be created in the plugin directory. Once
you upload this file to the symfony plugins application, your work will become
immediately available to the entire symfony community.
sfTaskExtraPlugin is young, but we have big plans for it. If you have any tasks you'd like to see incorporated, please let us know.