Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Session/CookieSessionHandler.php
Строк: 126
<?php

namespace IlluminateSession;

use 
IlluminateContractsCookieQueueingFactory as CookieJar;
use 
IlluminateSupportInteractsWithTime;
use 
SessionHandlerInterface;
use 
SymfonyComponentHttpFoundationRequest;

class 
CookieSessionHandler implements SessionHandlerInterface
{
    use 
InteractsWithTime;

    
/**
     * The cookie jar instance.
     *
     * @var IlluminateContractsCookieFactory
     */
    
protected $cookie;

    
/**
     * The request instance.
     *
     * @var SymfonyComponentHttpFoundationRequest
     */
    
protected $request;

    
/**
     * The number of minutes the session should be valid.
     *
     * @var int
     */
    
protected $minutes;

    
/**
     * Indicates whether the session should be expired when the browser closes.
     *
     * @var bool
     */
    
protected $expireOnClose;

    
/**
     * Create a new cookie driven handler instance.
     *
     * @param  IlluminateContractsCookieQueueingFactory  $cookie
     * @param  int  $minutes
     * @param  bool  $expireOnClose
     * @return void
     */
    
public function __construct(CookieJar $cookie$minutes$expireOnClose false)
    {
        
$this->cookie $cookie;
        
$this->minutes $minutes;
        
$this->expireOnClose $expireOnClose;
    }

    
/**
     * {@inheritdoc}
     *
     * @return bool
     */
    
public function open($savePath$sessionName): bool
    
{
        return 
true;
    }

    
/**
     * {@inheritdoc}
     *
     * @return bool
     */
    
public function close(): bool
    
{
        return 
true;
    }

    
/**
     * {@inheritdoc}
     *
     * @return string|false
     */
    
public function read($sessionId): string|false
    
{
        
$value $this->request->cookies->get($sessionId) ?: '';

        if (! 
is_null($decoded json_decode($valuetrue)) && is_array($decoded) &&
            isset(
$decoded['expires']) && $this->currentTime() <= $decoded['expires']) {
            return 
$decoded['data'];
        }

        return 
'';
    }

    
/**
     * {@inheritdoc}
     *
     * @return bool
     */
    
public function write($sessionId$data): bool
    
{
        
$this->cookie->queue($sessionIdjson_encode([
            
'data' => $data,
            
'expires' => $this->availableAt($this->minutes 60),
        ]), 
$this->expireOnClose $this->minutes);

        return 
true;
    }

    
/**
     * {@inheritdoc}
     *
     * @return bool
     */
    
public function destroy($sessionId): bool
    
{
        
$this->cookie->queue($this->cookie->forget($sessionId));

        return 
true;
    }

    
/**
     * {@inheritdoc}
     *
     * @return int
     */
    
public function gc($lifetime): int
    
{
        return 
0;
    }

    
/**
     * Set the request instance.
     *
     * @param  SymfonyComponentHttpFoundationRequest  $request
     * @return void
     */
    
public function setRequest(Request $request)
    {
        
$this->request $request;
    }
}
Онлайн: 0
Реклама