enterScope() public method

Enters the given scope
public enterScope ( string $name ) : void
$name string
return void
 /**
  * Returns the ReflectionMethod for the given controller string.
  *
  * @param string $controller
  * @return \ReflectionMethod|null
  */
 public function getReflectionMethod($controller)
 {
     if (false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
         $controller = $this->controllerNameParser->parse($controller);
     }
     if (preg_match('#(.+)::([\\w]+)#', $controller, $matches)) {
         $class = $matches[1];
         $method = $matches[2];
     } elseif (preg_match('#(.+):([\\w]+)#', $controller, $matches)) {
         $controller = $matches[1];
         $method = $matches[2];
         if ($this->container->has($controller)) {
             $this->container->enterScope('request');
             $this->container->set('request', new Request(), 'request');
             $class = ClassUtils::getRealClass(get_class($this->container->get($controller)));
             $this->container->leaveScope('request');
         }
     }
     if (isset($class) && isset($method)) {
         try {
             return new \ReflectionMethod($class, $method);
         } catch (\ReflectionException $e) {
         }
     }
     return null;
 }
 /**
  * {@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;
 }
 /**
  * @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);
     }
 }
Example #4
0
 /**
  * Retrieves templating service
  *
  * @return \Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine
  */
 public function getTemplating()
 {
     if (defined('IN_MAUTIC_CONSOLE')) {
         //enter the request scope in order to be use the templating.helper.assets service
         $this->container->enterScope('request');
         $this->container->set('request', new Request(), 'request');
     }
     return $this->container->get('templating');
 }
 /**
  * {@inheritDoc}
  *
  * @param InputInterface  $input  input
  * @param OutputInterface $output output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /**
      * somehow as the swagger spec generation digs deep in the utils/router stuff,
      * somewhere Request is needed.. so we need to enter the request scope
      * manually.. maybe there is another possibility for this?
      */
     $this->container->enterScope('request');
     $this->container->set('request', new Request(), 'request');
     $this->filesystem->dumpFile($this->rootDir . '/../web/swagger.json', json_encode($this->apidoc->getSwaggerSpec()));
 }
 /**
  * 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');
     }
 }
 /**
  * Returns the ReflectionMethod for the given controller string.
  *
  * @param string $controller
  * @return \ReflectionMethod|null
  */
 public function getReflectionMethod($controller)
 {
     if (preg_match('#(.+)::([\\w]+)#', $controller, $matches)) {
         $class = $matches[1];
         $method = $matches[2];
     } elseif (preg_match('#(.+):([\\w]+)#', $controller, $matches)) {
         $controller = $matches[1];
         $method = $matches[2];
         if ($this->container->has($controller)) {
             $this->container->enterScope('request');
             $this->container->set('request', new Request(), 'request');
             $class = get_class($this->container->get($controller));
             $this->container->leaveScope('request');
         }
     }
     if (isset($class) && isset($method)) {
         try {
             return new \ReflectionMethod($class, $method);
         } catch (\ReflectionException $e) {
         }
     }
     return null;
 }
 public function enterScope()
 {
     if (!$this->container->isScopeActive('scenario')) {
         $this->container->enterScope('scenario');
     }
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function enterScope($name)
 {
     $this->container->enterScope($name);
 }
 /**
  * Enters the container scope when a route has been found.
  *
  * @param GetResponseEvent $event The event object
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (null !== ($scope = $this->getScopeFromEvent($event))) {
         $this->container->enterScope($scope);
     }
 }