Ok I've managed to solve this in an ugly way, but it works for now. In case anyone has the same problem, here's what I did. First I defined a service for a fake request like this:
<parameter key="fake_request.class">Symfony\Component\HttpFoundation\Request</parameter> <service id="fake_request" class="%fake_request.class%" /> And then I added a compiler pass detecting if it's a call from the CLI. If that's so, I simply change the scope and the argument of the original service, which has this definition: <service id="application_service_abstract.request" class="%application_service_abstract.request.class%" scope="request"> <argument type="service" id="request" /> </service> The compiler pass would look like this: // We detect if we're in the CLI if (defined('STDIN')) { // Here we change the scope and the original argument (the "request") for our fake request $requestDefinition = $container->getDefinition('application_service_abstract.request'); $requestDefinition->setScope('container'); $requestDefinition->setArgument(0, new Reference('fake_request')); } I know, it's really ugly. Looking at the Definition class of the DIC I see a factory option. Maybe this could be solved better with a factory, but I still don't know how it works with the DIC, so I'll use this solution in the meantime and then I'll look for another way. Thanks. 2011/4/8 Gustavo Adrian <comfortablynum...@gmail.com> > Hi Tim, thanks for answering. > > Yes, I've tried that before but, on CLI I get: > > [Symfony\Component\DependencyInjection\Exception\InactiveScopeException] > You cannot create a service ("application_service_abstract.request") of an > inactive scope ("request"). > > I need to use that service on a CLI command but as there's no request it > keeps throwing exceptions. > > This exception is for the wrapper service I've got for the request. I've > configured this service now like this, following Tim's advice: > > <service id="application_service_abstract.request" > class="%application_service_abstract.request.class%" scope="request"> > <argument type="service" id="request" /> > </service> > > And I removed the declaration of the "request" service as synthetic, as > I've shown in the first post. So far, everything is working as expected as > before. Except for the CLI command problem. > > > > Thanks. > -- 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 users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en