Detect if request service is accessible in Symfony 2?
You could simply check whether current container instance has request
service/scope using ContainerInterface::has()
/ContainerInterface::hasScope()
.
EDIT:
My mistake. You have to use ContainerInterface::isScopeActive()
, to determine whether request
service is fully functional:
public function __construct(ContainerInterface $container, RouterInterface $router) { if ($container->isScopeActive('request')) { $this->request = $container->get('request'); $this->router = $router; }}
This code snipped is from my own project, where I've experienced a very similar issue.