Hi,

this e-mail is a follow-up to a discussion I had on Twitter with @lsmith. It 
started with my simple question, whether somebody had implemented console 
commands as services before. At that time I was starting to work on some 
console commands by first adding unit tests and refactor them in the second 
step. Trying to make them testable, I immediately wanted to define them as 
services. After some research I found this article 
(http://avalanche123.com/blog/2010/10/15/symfony2-console-commands-and-dic/) 
from October 2010, but I never found the feature's implementation.
Yesterday night, I published the console-extra-bundle 
(https://packagist.org/packages/seiffert/console-extra-bundle) which allows 
developers to define their commands as services. Each service that is tagged 
with "console.command" is considered a console command and registered at the 
console application.

If you have a look at the code/docs, you might find the following disturbing: 
Every bundle that wants to use command services, has to override 
Bundle::registerCommands() with an empty implementation. This is required 
because Symfony's default implementation of reigsterCommands() iterates over 
all command classes from <bundle-path>/Command/ and registers object created 
from these classes as commands. If you don't override this default 
implementation, commands that reside in <bundle-path>/Command/ and are defined 
as services, would be registered twice… 
In my opinion, registering commands from a certain directory automatically is a 
pretty strict convention. However, we could weaken this convention by adding a 
method Bundle::autoRegisterCommands(), which returns true by default and can be 
overridden in order to specify whether or not commands should be loaded from 
<bundle-path>/Command/ ? 

Another issue regarding this feature is whether it should be part of one of the 
better known bundles like FrameworkBundle and FrameworkExtraBundle. 

What do you guys think? Do you like this feature? How can we integrate it 
seamlessly? 

Kind regards,
  Paul

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to symfony-devs@googlegroups.com
To unsubscribe from this group, send email to
symfony-devs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to