gremo
gremo

Reputation: 48909

Symfony 2 removes factory services?

Does Symfony automatically remove factory services?

Don't know what's going on, but my bundle is correctly loading service.xml file:

<services>
    <service id="gremo_subscription_factory"
        class="%gremo_subscription_factory.class%" public="false">
        <argument>%gremo_subscription.interval%</argument>
    </service>
    <service id="gremo_subscription" class="%gremo_subscription.class%"
        factory-service="gremo_subscription_factory"
        factory-method="getSubscription">
    </service>
</services>

This is done by the extension class:

public function load(array $configs, ContainerBuilder $container)
{
    $processor = new Processor();
    $configuration = new Configuration();

    $config = $processor->processConfiguration($configuration, $configs);
    $loader = new XmlFileLoader($container,
        new FileLocator(__DIR__.'/../Resources/config'));

    $loader->load('services.xml');
}

The definition for services gremo_subscription_factory exists (var_dump the container shows the service definition) in the bundle. However when I try to access gremo_subscription service (from a controller, for example) from another bundle:

$subscription = $this->get('gremo_subscription');

I get the exception:

You have requested a non-existent service "gremo_subscription_factory".

Why this is happening?

Upvotes: 0

Views: 184

Answers (1)

AdrienBrault
AdrienBrault

Reputation: 7745

You shouldn't set the gremo_subscription_factory as private.

Remove the public="false" flag on the service.

Upvotes: 1

Related Questions