Attach a session cookie with the given sesison id to the given response.

@param \Psr\Http\Message\ResponseInterface   $response
@param string                                $session_id
@return \Psr\Http\Message\ResponseInterface
348928
private function withSessionCookie(ResponseInterface $response, string $session_id): ResponseInterface
    {
        // Merge session cookie options.
        $default = session_get_cookie_params();

        $default = array_change_key_case($default, CASE_LOWER);
        $options = array_change_key_case($this->options, CASE_LOWER);

        $options = array_merge($default, $options);

        if ($options['lifetime'] < 0) $options['lifetime'] = 0;

        // Create a session cookie and attach it to the response.
        $cookie = SetCookie::create($this->name, $session_id)
            ->withMaxAge($options['lifetime'])
            ->withPath($options['path'])
            ->withDomain($options['domain'])
            ->withSecure($options['secure'])
            ->withHttpOnly($options['httponly']);

        if ($options['lifetime'] > 0) {

            $cookie = $cookie->withExpires(time() + $options['lifetime']);

        }

        return FigResponseCookies::set($response, $cookie);
    }
1192804
private function makeSession($response, $method)
    {
        if ($method === 'pagseguro_credit_card') {
            $this->session()->setData([
                'pagseguro_payment' => [
                    'payment_type'  => $method,
                    'order_id'      => $this->orderId,
                ]
            ]);
        } else {
            $this->session()->setData([
                'pagseguro_payment' => ['payment_link' => $response->getPaymentLink(),
                    'payment_type'  => $method,
                    'order_id'      => $this->orderId,
                ]
            ]);
        }
    }
857517
public function serve(ResponseInterface $response, $cookies = [])
    {
        if (headers_sent($file, $line)) {
            throw new HeadersSentException(
                'Headers already sent in ' . $file . ' on line ' . $line
            );
        }
        $this->triggerEvent('serve', new \Jivoo\Event($this, [
            'response' => $response,
            'cookies' => $cookies
        ]));
        $this->serveStatus($response);
        $this->serveCookies($cookies);
        $this->serveHeaders($response);
        $this->serveBody($response, $this->compression);
        $this->triggerEvent('served', new \Jivoo\Event($this, [
            'response' => $response,
            'cookies' => $cookies
        ]));
    }
585534
private function sessionCookie(UriInterface $uri, string $id = null): Cookie
    {
        return Cookie::create(
            $this->config->getCookie(),
            $id,
            $this->config->getLifetime(),
            $this->httpConfig->basePath(),
            $this->httpConfig->cookieDomain($uri),
            $this->config->isSecure(),
            true
        );
    }
1238126
public function setSessionId($session_id=null)
    {
        $this->session_id= ($session_id!== null) ? $session_id : null;

        return $this;
    }
204556
public function expireCookie(ResponseInterface $response, $name)
    {
        $cookie = SetCookie::createExpired($name)
            ->withMaxAge($this->configuration['maxAge'])
            ->withPath($this->configuration['path'])
            ->withDomain($this->configuration['domain'])
            ->withSecure($this->configuration['secure'])
            ->withHttpOnly($this->configuration['httpOnly']);

        return $response->withAddedHeader(static::RESPONSE_COOKIE_NAME, $cookie);
    }
1162783
public function addToResponse(\Psr\Http\Message\ResponseInterface $p_response)
    {
        foreach ($this->cookies as $idx => $cookie) {
            $p_response = $p_response->withAddedHeader('Set-Cookie', (string)$cookie);
        }
        return $p_response;
    }
828871
protected function writeSessionTo(Response $response)
    {
        // TODO: Take these values from config
        $lifetime = Carbon::now()->addMinutes(120);
        $path = '/';
        $domain = null;
        $secure = false;

        $response->headers->setCookie(new Cookie(
            $this->session->getName(),
            $this->session->getId(),
            $lifetime,
            $path,
            $domain,
            $secure
        ));
    }
636315
protected function setCookieForResponse(Response $response, ResponseAuthenticationModel $responseModel)
    {
        $response->headers->setCookie(
            new Cookie(
                self::AUTH_COOKIE,
                $responseModel->getAuthToken(),
                $responseModel->getTokenExpirationTimeStamp(),
                null,
                false,
                false
            )
        );

        return $response;
    }
863634
public function write($session_id, $session_data)
    {
        return $this->memcached->set($session_id, $session_data, $this->expire);
    }
739253
public function modifyResponse(Request $request, Response $response)
    {
        if ($this->isCollect() === false) {
            return;
        }

        // if ($this -> created) {
        //     return;
        // }

        $app = $this->app;


        if ($app->runningInConsole() || !$this->isEnabled() || $this->isMyselfRequest()) {
            return $response;
        }

        // Show the Http Response Exception, when available
        if (isset($response->exception)) {
            $this->addThrowable($response->exception);
        }

        /**---------------------------------------------------------
         *   Display config settings
         *---------------------------------------------------------*/

        if ($this->shouldCollect('config', false)) {
            try {
                $configCollector = new ConfigCollector();
                $configCollector->setData($app['config']->all());
                $this->addCollector($configCollector);
            } catch (\Exception $e) {
                $this->addThrowable(
                    new Exception(
                        'Cannot add ConfigCollector to SongshenzongLog: ' . $e->getMessage(),
                        $e->getCode(),
                        $e
                    )
                );
            }
        }


        if ($this->app->bound(SessionManager::class)) {

            /** @var \Illuminate\Session\SessionManager $sessionManager */
            $sessionManager = $app->make(SessionManager::class);
            $httpDriver     = new SymfonyHttpDriver($sessionManager, $response);
            $this->setHttpDriver($httpDriver);

            if ($this->shouldCollect('session') && !$this->hasCollector('session')) {
                try {
                    $this->addCollector(new SessionCollector($sessionManager));
                } catch (\Exception $e) {
                    $this->addThrowable(
                        new Exception(
                            'Cannot add SessionCollector to SongshenzongLog: ' . $e->getMessage(),
                            $e->getCode(),
                            $e
                        )
                    );
                }
            }
        } else {
            $sessionManager = null;
        }


        /**---------------------------------------------------------
         *   Only one can be enabled.
         *---------------------------------------------------------*/
        if ($this->shouldCollect('request', true) && !$this->hasCollector('request')) {
            try {
                $this->addCollector(new RequestCollector($request, $response, $sessionManager));
            } catch (\Exception $e) {
                $this->addThrowable(
                    new Exception(
                        'Cannot add RequestCollector to SongshenzongLog: ' . $e->getMessage(),
                        $e->getCode(),
                        $e
                    )
                );
            }
        }


        /**---------------------------------------------------------
         *   Just collect + store data
         *---------------------------------------------------------*/
        try {
            $this->collect();
        } catch (\Exception $e) {
            $app['log']->error('Songshenzong exception: ' . $e->getMessage());
        }


        return $response;
    }
237233
private function fromPsrResponse(ResponseInterface $response)
    {
        return new Response(
            $response->getStatusCode(),
            $response->getHeaders(),
            $response->getBody(),
            $response->getProtocolVersion(),
            $response->getReasonPhrase()
        );
    }
438690
private function makeSession($response)
    {
        $this->session()->setData([
            'pagseguro_payment' => ['payment_link' => $response->getPaymentLink(),
                'payment_type'  => strtolower(Boleto::class),
                'order_id'      => $this->lastRealOrderId(),
            ]
        ]);
    }
250116
public function read($session_id)
	{
		$key = $this->key($session_id);

		$this->expiration($key);

		return $this->engine->get($key);
	}
914224
protected function emitHeaders(ResponseInterface $response){
        foreach($response->getHeaders() as $name => $values){
            if(strtolower($name) === "set-cookie"){
                foreach($values as $value){
                    header(sprintf("Set-Cookie: %s", $value), false);
                }
            }else{
                header(sprintf("%s: %s", $name, implode(", ", $values)));
            }
        }
    }
1280616
private function addCookieToResponse(Request $request, Response $response, SessionInterface $session): Response
    {
        $uri = $request->getUri();
        $path = '/';
        $domain = $uri->getHost();
        $secure = strtolower($uri->getScheme()) === 'https';
        $httpOnly = true;
        return $response->withCookie(new Cookie($session->getName(), $session->getId(), $this->getCookieExpirationDate(), $path, $domain, $secure, $httpOnly));
    }
485733
public function load(Request $request, Response $response) {
        //render the key
        $key = md5(uniqid());
        if($request->hasSession('csrf')) {
            $key = $request->getSession('csrf');
        }

        $request->setSession('csrf', $key);
        $response->setResults('csrf', $key);

        return $this;
    }