isScopeActive() public method

It does however not check if the scope actually exists.
public isScopeActive ( string $name ) : boolean
$name string
return boolean
 /**
  * @return string
  */
 public function getLocale()
 {
     if ($this->container !== null && $this->container->isScopeActive('request')) {
         return $this->container->get('request')->getLocale();
     }
     return $this->locale;
 }
 /**
  * {@inheritDoc}
  */
 public function convert(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $method, $value, array $attributes = [])
 {
     if (!$this->container->isScopeActive('request') || !$this->container->has('request')) {
         throw new ConverterException('Could not convert Request parameter in not active "request" scope.');
     }
     return $this->container->get('request');
 }
 /**
  * Constructor
  * 
  * @param ContainerInterface $container
  */
 public function __construct($container)
 {
     $this->container = $container;
     if ($this->container->isScopeActive('request')) {
         $this->request = $this->container->get('request');
     }
 }
Example #4
0
 public function getLocale()
 {
     if ($this->container->isScopeActive('request') && $this->container->has('request')) {
         return $this->container->get('request')->getSession()->getLang()->getLocale();
     }
     return $this->locale;
 }
 /**
  * {@inheritDoc}
  */
 public function getGlobals()
 {
     if (!$this->container->isScopeActive('request')) {
         return array();
     }
     return array('require_js' => array('config' => $this->configurationBuilder->getConfiguration()));
 }
 /**
  * Creates and persists a thread with the specified id.
  *
  * @param \FOS\CommentBundle\Event\ThreadEvent $event
  */
 public function onThreadCreate(ThreadEvent $event)
 {
     if (!$this->container->isScopeActive('request')) {
         return;
     }
     $thread = $event->getThread();
     $thread->setPermalink($this->container->get('request')->getUri());
 }
 /**
  * {@inheritdoc}
  */
 public function getLocale()
 {
     if ($this->container->isScopeActive('request')) {
         if ($request = $this->container->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
             return $request->getLocale();
         }
     }
     return $this->defaultLocale;
 }
 /**
  * @return null|Request
  */
 private function getRequest()
 {
     if ($this->container->has('request_stack')) {
         return $this->container->get('request_stack')->getCurrentRequest();
     }
     if ($this->container->isScopeActive('request')) {
         return $this->container->get('request');
     }
     return;
 }
 /**
  * Get the locale, either from the parent or from the container if available
  * or the default locale if one is set.
  *
  * @param array $parameters the request parameters
  *
  * @return string
  */
 protected function getLocale($parameters)
 {
     $locale = parent::getLocale($parameters);
     if ($locale) {
         return $locale;
     }
     if (is_null($this->container) || !$this->container->isScopeActive('request') || !($request = $this->container->get('request'))) {
         return $this->defaultLocale;
     }
     return $request->getLocale();
 }
 public function postUpdate(LifecycleEventArgs $arg)
 {
     if (!$this->container->isScopeActive('request')) {
         return;
     }
     if (!$this->container->get('security.context')->getToken()->isAuthenticated()) {
         return;
     }
     if ($arg->getDocument() instanceof Document\Article) {
         if ($arg->getDocument()->wereTranslationsModified()) {
             $this->notifyModification($arg->getDocument(), $arg->getDocumentManager());
         }
     }
 }
 /**
  * @param Notification $notification
  * @return void
  */
 public function notify(Notification $notification)
 {
     if (!$this->container->isScopeActive('request')) {
         $this->container->enterScope('request');
         $this->container->set('request', new Request(), 'request');
     }
     $ticket = $this->loadTicket($notification);
     $changeList = $this->postProcessChangesList($notification);
     foreach ($this->watchersService->getWatchers($ticket) as $watcher) {
         $userType = $watcher->getUserType();
         $user = User::fromString($userType);
         $isOroUser = $user->isOroUser();
         if ($isOroUser) {
             $loadedUser = $this->oroUserManager->findUserBy(['id' => $user->getId()]);
         } else {
             $loadedUser = $this->diamanteUserRepository->get($user->getId());
         }
         if (!$isOroUser && $notification->isTagUpdated()) {
             continue;
         }
         $message = $this->message($notification, $ticket, $isOroUser, $loadedUser->getEmail(), $changeList);
         $this->mailer->send($message);
         $reference = new MessageReference($message->getId(), $ticket, $this->configManager->get(self::EMAIL_NOTIFIER_CONFIG_PATH));
         $this->messageReferenceRepository->store($reference);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function isolateEnvironment(Environment $uninitializedEnvironment, $testSubject = null)
 {
     if (!$uninitializedEnvironment instanceof UninitializedContextServiceEnvironment) {
         throw new EnvironmentIsolationException(sprintf('ContextServiceEnvironmentHandler does not support isolation of `%s` environment.', get_class($uninitializedEnvironment)), $uninitializedEnvironment);
     }
     if (!$this->container->isScopeActive('scenario')) {
         $this->container->enterScope('scenario');
     }
     $environment = new InitializedContextEnvironment($uninitializedEnvironment->getSuite());
     foreach ($uninitializedEnvironment->getContextsServicesIds() as $serviceId) {
         /** @var Context $context */
         $context = $this->container->get($serviceId);
         $environment->registerContext($context);
     }
     return $environment;
 }
 /**
  * Tries to match a URL with a set of routes.
  *
  * Returns false if no route matches the URL.
  *
  * @param string $url URL to be parsed
  *
  * @return array|false An array of parameters or false if no route matches
  */
 public function match($url)
 {
     $params = $this->getMatcher()->match($url);
     if (false === $params) {
         throw new ResourceNotFoundException();
     }
     // No request. What append ?
     $currentLocale = null;
     if ($this->container->isScopeActive('request')) {
         $currentLocale = $this->localeResolver->resolveLocale($this->container->get('request'));
     }
     // Clean the route name
     if (false !== ($pos = strpos($params['_route'], I18nLoader::ROUTING_PREFIX))) {
         $params['_route'] = substr($params['_route'], $pos + strlen(I18nLoader::ROUTING_PREFIX));
     }
     // Retrieve all authorized locales for the given route
     $routeLocales = array();
     if (isset($params['_locale'])) {
         $routeLocales = array($params['_locale']);
     } elseif (isset($params['_locales'])) {
         $routeLocales = $params['_locales'];
         unset($params['_locales']);
     }
     if (0 === count($routeLocales) || in_array($currentLocale, $routeLocales)) {
         $params['_locale'] = $currentLocale;
         return $params;
     }
     throw new ResourceNotFoundException();
 }
Example #14
0
 /**
  * @param string $path
  */
 public function __construct(RackspaceContainer $container, ContainerInterface $serviceContainer)
 {
     $this->container = $container;
     if ($serviceContainer->hasScope('request') && $serviceContainer->isScopeActive('request') && $serviceContainer->has('request')) {
         $this->request = $serviceContainer->get('request');
     }
 }
 /**
  * @param ContainerInterface $container
  * @param EntityManager $em
  */
 public function __construct(ContainerInterface $container, EntityManager $em)
 {
     if ($container->isScopeActive('request')) {
         $this->em = $em;
         $this->siteRequest = $container->get('sudoux.cms.site');
         $this->site = $this->siteRequest->getSite();
         $this->container = $container;
     }
 }
Example #16
0
 private function preparePagination(Pagerfanta &$paginator)
 {
     if ($this->container->isScopeActive("request")) {
         $req = $this->container->get('request');
     } else {
         $req = null;
     }
     if ($req instanceof Request) {
         $currentPage = $req->query->get('page', 1);
         $perPage = $req->query->getInt('perPage', 20);
     } else {
         $currentPage = 1;
         $perPage = 20;
     }
     if ($perPage <= 0 || $perPage > 1000) {
         $perPage = max(0, min(1000, $perPage));
     }
     $paginator->setMaxPerPage($perPage);
     $paginator->setCurrentPage($currentPage, false, true);
 }
 public function __construct(ContainerInterface $container)
 {
     if ($container->isScopeActive('request')) {
         $controller = $container->get('request')->get('_controller');
         $matches = array();
         preg_match("/Controller\\\\([\\w]*)Controller/i", $controller, $matches);
         $this->name = isset($matches[1]) ? strtolower($matches[1]) : '';
         preg_match("/\\:([\\w]*)Action/i", $controller, $matches);
         $this->action = isset($matches[1]) ? strtolower($matches[1]) : '';
     }
 }
 private function getLocale()
 {
     if (null === $this->locale) {
         if ($this->container->isScopeActive('request') && $this->container->has('request')) {
             $this->locale = $this->container->get('request')->getLocale();
         } else {
             $this->locale = $this->options['default_locale'];
         }
     }
     return $this->locale;
 }
 /**
  * Sets the repository request default locale
  *
  * @param ContainerInterface|null $container
  * 
  * @throws \InvalidArgumentException if repository is not an instance of TranslatableRepository
  */
 public function setRepositoryLocale($container)
 {
     if (null !== $container) {
         if (!$this->repository instanceof TranslatableRepository) {
             throw new \InvalidArgumentException('A TranslatableManager needs to be linked with a TranslatableRepository to sets default locale.');
         }
         if ($container->isScopeActive('request')) {
             $locale = $container->get('request')->getLocale();
             $this->repository->setDefaultLocale($locale);
         }
     }
 }
 /**
  * Returns the name of the current page layout (front end only).
  *
  * @return string The layout name
  */
 private function getLayoutName()
 {
     if (!$this->container->isScopeActive(ContaoCoreBundle::SCOPE_FRONTEND)) {
         return '';
     }
     /** @var PageModel $objPage */
     global $objPage;
     /** @var LayoutModel $layout */
     if (null === $objPage || null === ($layout = $objPage->getRelated('layout'))) {
         return '';
     }
     return sprintf('%s (ID %s)', $layout->name, $layout->id);
 }
 /**
  * Enter request scope if it is not active yet...
  *
  * @param string $lang
  */
 protected function enterRequestScope($lang)
 {
     if (!$this->container->isScopeActive('request')) {
         $this->container->enterScope('request');
         $request = new Request();
         $request->setLocale($lang);
         $major = Kernel::MAJOR_VERSION;
         $minor = Kernel::MINOR_VERSION;
         if ((int) $major > 2 || (int) $major == 2 && (int) $minor >= 4) {
             $requestStack = $this->container->get('request_stack');
             $requestStack->push($request);
         }
         $this->container->set('request', $request, 'request');
     }
 }
 /**
  * @param string|TemplateReferenceInterface $template
  * @return string
  */
 protected function findTemplate($template)
 {
     $logicalName = (string) $template;
     if (isset($this->cache[$logicalName])) {
         return $this->cache[$logicalName];
     }
     if ($this->request === null && $this->container->isScopeActive('request')) {
         $this->request = $this->container->get('request');
     }
     $locale = $this->request ? $this->request->attributes->get('_locale') : 'en';
     if (is_string($template)) {
         if (strpos($template, ':')) {
             try {
                 $template = $this->parser->parse($template);
             } catch (\Exception $e) {
             }
         } else {
             return parent::findTemplate($template);
         }
     }
     if ($locale !== 'en') {
         $params = $template->all();
         $localizedTemplate = new TemplateReference($params['bundle'], $params['controller'], $params['name'], $params['format'], $params['engine']);
         if ($params['controller']) {
             $localizedTemplate->set('controller', $locale . '/' . $params['controller']);
         } else {
             $localizedTemplate->set('name', $locale . '/' . $params['name']);
         }
         try {
             return parent::findTemplate($localizedTemplate);
         } catch (\Twig_Error_Loader $e) {
             return parent::findTemplate($template);
         }
     }
     return parent::findTemplate($template);
 }
 /**
  * Gets the base URL
  *
  * @return string
  */
 protected function getBaseUrl()
 {
     $baseUrl = '';
     if ($this->container->isScopeActive('request')) {
         if ($this->container->getParameter('assetic.use_controller')) {
             $baseUrl = $this->container->get('request')->getBaseUrl();
         } else {
             $baseUrl = $this->container->get('templating.helper.assets')->getUrl('');
             // Remove ?version from the end of the base URL
             if (($pos = strpos($baseUrl, '?')) !== false) {
                 $baseUrl = substr($baseUrl, 0, $pos);
             }
         }
     }
     // Remove trailing slash, if there is one
     return rtrim($baseUrl, '/');
 }
 /**
  * Constructor to set up and configure the Bugsnag_Client
  *
  * @param \Bugsnag_Client                                          $bugsnagClient
  * @param ReleaseStageInterface                                    $releaseStageClass
  * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
  */
 public function __construct(\Bugsnag_Client $bugsnagClient, ReleaseStageInterface $releaseStageClass, ContainerInterface $container)
 {
     $this->bugsnagClient = $bugsnagClient;
     // Report only if the kernel environment matches one of the enabled_stages
     if (in_array($container->getParameter('kernel.environment'), $container->getParameter('bugsnag.enabled_stages'))) {
         $this->enabled = true;
     }
     // Set up the Bugsnag client
     $this->bugsnagClient->setReleaseStage($releaseStageClass->get());
     $this->bugsnagClient->setNotifyReleaseStages($container->getParameter('bugsnag.notify_stages'));
     $this->bugsnagClient->setProjectRoot(realpath($container->getParameter('kernel.root_dir') . '/..'));
     if ($container->hasParameter('bugsnag.user') && $container->has($container->getParameter('bugsnag.user'))) {
         $service = $container->get($container->getParameter('bugsnag.user'));
         if ($service instanceof UserInterface) {
             $this->bugsnagClient->setUser($service->getUserAsArray());
         }
     }
     // If the proxy settings are configured, provide these to the Bugsnag client
     if ($container->hasParameter('bugsnag.proxy')) {
         $this->bugsnagClient->setProxySettings($container->getParameter('bugsnag.proxy'));
     }
     // app version
     if ($container->hasParameter('bugsnag.app_version')) {
         $this->bugsnagClient->setAppVersion($container->getParameter('bugsnag.app_version'));
     }
     // Set up result array
     $metaData = array('Symfony' => array());
     // Get and add controller information, if available
     if ($container->isScopeActive('request')) {
         $request = $container->get('request');
         $controller = $request->attributes->get('_controller');
         if ($controller !== null) {
             $metaData['Symfony'] = array('Controller' => $controller);
         }
         $metaData['Symfony']['Route'] = $request->get('_route');
         // Json types transmit params differently.
         if ($request->getContentType() == 'json') {
             $metaData['request']['params'] = $request->request->all();
         }
         $this->bugsnagClient->setMetaData($metaData);
     }
 }
Example #25
0
 public function leaveScope()
 {
     if ($this->container->isScopeActive('scenario')) {
         $this->container->leaveScope('scenario');
     }
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function isScopeActive($name)
 {
     return $this->container->isScopeActive($name);
 }
 public function __construct(ContainerInterface $container)
 {
     if ($container->isScopeActive('request')) {
         $this->container = $container;
     }
 }
Example #28
0
 /**
  * Check if we have a valid request available.
  * In symfony 2 we don't always have a request. For instance when calling through a Command.
  * @param ContainerInterface $container
  * @return boolean
  */
 private function hasValidRequest(ContainerInterface $container)
 {
     return $container->hasScope('request') && $container->isScopeActive('request');
 }
Example #29
0
 /**
  * @DI\InjectParams({
  *     "container"  = @DI\Inject("service_container"),
  *     "accessor"   = @DI\Inject("claroline.resource.mode_accessor")
  * })
  */
 public function __construct(ContainerInterface $container, ModeAccessor $accessor)
 {
     $this->request = $container->isScopeActive('request') ? $container->get('request') : false;
     $this->modeAccessor = $accessor;
 }
 public function __construct(ContainerInterface $container)
 {
     if ($container->isScopeActive('request')) {
         $this->localizer = $container->get('yoye_localization.localizer');
     }
 }