Thank you both guys! I managed to fix the problem with a mix of your
solutions :) but some questions arised while I was implementing this.
First I've tried to tag my module services and then tried to access them
from my ModuleManagerExtension with the method "findTaggedServiceIds", but
they were not found. So it seems that there's no way to access a service
from another service in the way I needed.
So, then I've tried using the compiler pass in the following way. My module
service:
<service id="module_manager.module.country" class="%module_country.class%">
<tag name="module_manager.module" />
</service>
I added this method to my ModuleManagerBundle class:
public function registerExtensions( ContainerBuilder $container )
{
parent::registerExtensions( $container );
$container->addCompilerPass( new addModulesPass() );
}
And finally my AddModulesPass:
public function process( ContainerBuilder $container )
{
if ( $container->hasDefinition( 'module_manager' ) )
{
// Get modules
$moduleServices = $container->findTaggedServiceIds( 'module_manager.module'
);
$moduleServicesIDs = array_keys( $moduleServices );
$definition = $container->getDefinition( 'module_manager' );
foreach ( $moduleServicesIDs as $moduleServiceID )
{
$definition->addMethodCall( 'addModule', array( new Reference(
$moduleServiceID ) ) );
}
}
}
And now it works. My questions regarding this are:
1) Tags are just a way to group services that have common functionalities
under a name (tag), so then you can access them like a collection, without
having to know their IDs. Right?
2) I saw in the thread you mentioned Venzon. But what I still don't know is:
if you override a service from a bundle (being just a parameter or the whole
service definition), in which order does the final override occurs? is the
order defined with the order in which you instantiante bundles in the method
"registerBundles" of the AppKernel class?
3) If a bundle has a parent bundle (defined with the getParent method added
some days ago) can it access the services from the parent?
Thanks a lot for your help guys.
On Thu, Jan 27, 2011 at 1:26 PM, Venzon <[email protected]> wrote:
> Maybe you can create Compiler Pass, execute it from Bundle class (for
> example HelloBundle.php) like that:
>
> public function registerExtensions(ContainerBuilder $container)
> {
> parent::registerExtensions($container);
> $container->addCompilerPass(new addModulesPass());
> }
>
> then you define /DependencyInjection/Compiler/addModulesPass.php class
>
> <?php
> namespace Application\HelloBundle\DependencyInjection\Compiler;
>
> use Symfony\Component\DependencyInjection\Reference;
> use Symfony\Component\DependencyInjection\ContainerBuilder;
> use Symfony\Component\DependencyInjection\Compiler
> \CompilerPassInterface;
>
> class addModulesPass implements CompilerPassInterface
> {
> public function process(ContainerBuilder $container)
> {
> if ($container->hasDefinition('module_manager') && $container-
> >hasDefinition('module_user'))
> {
> $container->getDefinition('module_manager')-
> >addMethodCall('addModule', array(new Reference('module_user')));
> }
> }
> }
>
> I am just starting to experiment with Compiler Pass tho
> A lot of examples can be found in core libs
> Here in this topic I get advice to use Compiler Pass to solve my
> problem:
>
> http://groups.google.com/group/symfony-devs/browse_thread/thread/e031e678a4a5eaef#
>
> --
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]<symfony-devs%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en
>
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en