Exemple #1
0
 /**
  * Mount session id or remove session cookie.
  *
  * @param Request  $request
  * @param Response $response
  * @return Response
  */
 protected function commitSession(Request $request, Response $response)
 {
     if (!$this->session->isStarted()) {
         //Nothing to do
         return $response;
     }
     //Incoming sessionID
     $sessionID = $this->fetchSID($request);
     if (empty($sessionID) || $sessionID != $this->session->getID(false)) {
         //Let's mount cookie
         $response = $response->withAddedHeader('Set-Cookie', $this->sessionCookie($request->getUri(), $this->session->getID(false))->createHeader());
     }
     $this->session->commit();
     return $response;
 }
 /**
  * Mount session id or remove session cookie.
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param SessionStore           $store
  * @param array                  $cookies
  * @return ResponseInterface
  */
 protected function setCookie(ServerRequestInterface $request, ResponseInterface $response, SessionStore $store, array $cookies)
 {
     if ($store->isStarted()) {
         $store->commit();
     }
     if (!isset($cookies[self::COOKIE]) || $cookies[self::COOKIE] != $store->getID()) {
         if ($response instanceof ResponseInterface) {
             return $response->withAddedHeader('Set-Cookie', Cookie::create(self::COOKIE, $store->getID(), $store->config()['lifetime'], $request->getAttribute('basePath'), $request->getAttribute('cookieDomain'))->packHeader());
         }
     }
     return $response;
 }