Author: Fabien Potencier (fabien.potencier@symfony-project.com)
Inheritance: implements Serializable
 /**
  * On kernel response event
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     // Only master request and 200 OK are processed
     if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType() && $event->getResponse()->isOk()) {
         $route = $this->router->match($this->request->getPathInfo());
         // Ignore internal route
         if (0 === stripos($route['_route'], '_')) {
             return;
         }
         $this->session->set('_unifik.last_master_request_uri', $this->request->getUri());
         $this->session->set('_unifik.last_master_request_route', $route);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getLocale()
 {
     if ($this->session) {
         return $this->session->getLocale();
     }
     return $this->defaultLocale;
 }
    protected function runSessionOnKernelResponse($newToken, $original = null)
    {
        $session = new Session(new ArraySessionStorage());

        if ($original !== null) {
            $session->set('_security_session', $original);
        }

        $this->securityContext->setToken($newToken);

        $request = new Request();
        $request->setSession($session);

        $event = new FilterResponseEvent(
            $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'),
            $request,
            HttpKernelInterface::MASTER_REQUEST,
            new Response()
        );

        $listener = new ContextListener($this->securityContext, array(), 'session');
        $listener->onKernelResponse($event);

        return $session;
    }
 /**
  * Moves flash messages from the session to a cookie inside a Response Kernel listener
  *
  * @param EventInterface $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if ($event->getRequestType() !== HttpKernel::MASTER_REQUEST) {
         return;
     }
     // Flash messages are stored in the session. If there is none, there
     // can't be any flash messages in it. $session->getFlashBag() would
     // create a session, we need to avoid that.
     if (!$this->session->isStarted()) {
         return;
     }
     $flashBag = $this->session->getFlashBag();
     $flashes = $flashBag->all();
     if (empty($flashes)) {
         return;
     }
     $response = $event->getResponse();
     $cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
     if (isset($cookies[$this->options['host']][$this->options['path']][$this->options['name']])) {
         $rawCookie = $cookies[$this->options['host']][$this->options['path']][$this->options['name']]->getValue();
         $flashes = array_merge($flashes, json_decode($rawCookie));
     }
     $cookie = new Cookie($this->options['name'], json_encode($flashes), 0, $this->options['path'], $this->options['host'], $this->options['secure'], $this->options['httpOnly']);
     $response->headers->setCookie($cookie);
 }
 public function set($state, $value)
 {
     if (!in_array($state, array_keys($this->states))) {
         throw new \RunTimeException("Requested state {$state} does not exist");
     }
     $this->session->set($this->prefix . '.' . $state, $value);
 }
 public function setUp()
 {
     $this->request = new Request();
     $session = new Session(new ArraySessionStorage());
     $session->set('foobar', 'bar');
     $session->setFlash('foo', 'bar');
     $this->request->setSession($session);
 }
 public function testPathWithLocale()
 {
     $matcher = new RequestMatcher();
     $request = Request::create('/en/login');
     $session = new Session(new ArraySessionStorage());
     $session->setLocale('en');
     $request->setSession($session);
     $matcher->matchPath('^/{_locale}/login$');
     $this->assertTrue($matcher->matches($request));
     $session->setLocale('de');
     $this->assertFalse($matcher->matches($request));
 }
Example #8
0
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     $configs = array_merge($options['configs'], array('id' => $view->vars['id'], 'name_id' => $view->getChild('name')->vars['id'], 'original_name_id' => $view->getChild('originalName')->vars['id'], 'size_id' => $view->getChild('size')->vars['id'], 'title_id' => $view->getChild('title')->vars['id'], 'caption_id' => $view->getChild('caption')->vars['id'], 'description_id' => $view->getChild('description')->vars['id'], 'hash_id' => $view->getChild('hash')->vars['id'], 'enabled_id' => $view->getChild('enabled')->vars['id'], 'scheduled_for_deletion_id' => $view->getChild('scheduledForDeletion')->vars['id'], 'enabled_value' => false));
     $file = $form->getData();
     if ($file instanceof FileInterface && null !== $file->getId()) {
         $configs['enabled_value'] = $file->isEnabled();
     }
     $this->session->set($view->vars['id'], $configs);
     $view->vars['configs'] = $configs;
 }
 protected function updateSession($translations)
 {
     foreach ($translations as $locale => $values) {
         // Clear empty domains
         foreach (array('new', 'updated') as $modififactionType) {
             foreach ($values[$modififactionType] as $domain => $trads) {
                 if (count($trads) == 0) {
                     unset($translations[$locale][$modififactionType][$domain]);
                 }
             }
         }
         // Clear empty locales
         if (count($translations[$locale]['new']) == 0 && count($translations[$locale]['updated']) == 0) {
             unset($translations[$locale]);
         }
     }
     $this->session->set(Configuration::SESSION_PREFIX . 'import-list', $translations);
 }
Example #10
0
 /**
  * Get the language name in the used locale
  *
  * @param string $language the iso code of the language
  * @return string
  */
 public function getLanguageName($language)
 {
     return \Locale::getDisplayLanguage($language, $this->session->getLocale());
 }
 /**
  * Returns the ID of the user session
  *
  * Automatically starts the session if necessary.
  *
  * @return string  The session ID
  */
 protected function getSessionId()
 {
     return $this->session->getId();
 }
Example #12
0
 private function generateCaptchaValue()
 {
     if (!$this->keepValue || !$this->session->has($this->key)) {
         $value = '';
         $chars = str_split($this->charset);
         for ($i = 0; $i < $this->length; $i++) {
             $value .= $chars[array_rand($chars)];
         }
         $this->session->set($this->key, $value);
     } else {
         $value = $this->session->get($this->key);
     }
     return $value;
 }
 /**
  * Clear the current filters
  */
 public function resetFilters()
 {
     $this->session->set(Configuration::SESSION_PREFIX . 'filters', null);
 }
 /**
  * Set the translation listener locale from the session.
  *
  * @param Session $session
  * @return void
  */
 public function setTranslatableLocaleFromSession(Session $session = null)
 {
     if ($session !== null) {
         $this->setTranslatableLocale($session->getLocale());
     }
 }
 public function showFlashMessages()
 {
     $return = '<div id="flashmessages"></div>';
     $return .= $this->renderFlashJavascript($this->session->getFlashes());
     return $return;
 }