By default Symfony tries to scan every bundle directory for a folder called 'Command' and searches for Console\Command classes in there.
But when you want to use the DIC and DI in you console commands there is another approach to make this happen. According to this article it should be possible to load your console commands with the dependency injection container, so I tried.
I made a service.xml:
<services>
<service id="atlas_cli.helper.anonymize" class="AtlasCliBundle\Services\AnonymizerHelperService" public="false" />
<service id="atlas_cli.helper.dbconfiguration" class="AtlasCliBundle\Services\ConfigurationHelperService" public="false" />
<service id="atlas_cli.helper.schemadump" class="AtlasCliBundle\Services\SchemaDumpHelperService" public="false" />
<service id="atlas_cli.helperset" class="Symfony\Component\Console\Helper\HelperSet" />
<service id="atlas_cli.command.anonymize" class="AtlasCliBundle\Command\AnonymizeCommand" public="true">
<tag name="console.command" />
<call method="setHelperSet">
<argument type="service" id="atlas_cli.helperset" />
</call>
<call method="setAnonymizeHelper">
<argument type="service" id="atlas_cli.helper.anonymize" />
<argument type="string">dbanonymizer</argument>
</call>
<call method="setDbConfigurationHelper">
<argument type="service" id="atlas_cli.helper.dbconfiguration" />
<argument type="string">dbconfiguration</argument>
</call>
</service>
<service id="atlas_cli.command.schema" class="AtlasCliBundle\Command\SchemaCommand" public="true">
<tag name="console.command" />
<call method="setHelperSet">
<argument type="service" id="atlas_cli.helperset" />
</call>
<call method="setDbConfigurationHelper">
<argument type="service" id="atlas_cli.helper.dbconfiguration" />
<argument type="string">dbconfiguration</argument>
</call>
<call method="setSchemadumpHelper">
<argument type="service" id="atlas_cli.helper.schemadump" />
<argument type="string">schemadump</argument>
</call>
</service>
</services>
As you can see I have configured 2 commands anonymize and schema. The commands are available when running app/console but the set methods (setDbConfigurationHelper for example) are never being called.
I use Symfony 2.1 but I searched the complete Symfony framework code on grep -ris "console\.command" *
but that doesn't give any usefull result, either for Symfony 2.3.
Is the tag console.command not supported anymore? And if the answer is yes, what do you recommend to use for handling dependencies in my command classes?
Thanks!!