first commit

This commit is contained in:
Sampanna Rimal
2024-08-27 17:48:06 +05:45
commit 53c0140f58
10839 changed files with 1125847 additions and 0 deletions

View File

@ -0,0 +1,139 @@
<?php
namespace Illuminate\Session;
use Illuminate\Support\InteractsWithTime;
use SessionHandlerInterface;
class ArraySessionHandler implements SessionHandlerInterface
{
use InteractsWithTime;
/**
* The array of stored values.
*
* @var array
*/
protected $storage = [];
/**
* The number of minutes the session should be valid.
*
* @var int
*/
protected $minutes;
/**
* Create a new array driven handler instance.
*
* @param int $minutes
* @return void
*/
public function __construct($minutes)
{
$this->minutes = $minutes;
}
/**
* {@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
{
if (! isset($this->storage[$sessionId])) {
return '';
}
$session = $this->storage[$sessionId];
$expiration = $this->calculateExpiration($this->minutes * 60);
if (isset($session['time']) && $session['time'] >= $expiration) {
return $session['data'];
}
return '';
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function write($sessionId, $data): bool
{
$this->storage[$sessionId] = [
'data' => $data,
'time' => $this->currentTime(),
];
return true;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function destroy($sessionId): bool
{
if (isset($this->storage[$sessionId])) {
unset($this->storage[$sessionId]);
}
return true;
}
/**
* {@inheritdoc}
*
* @return int
*/
public function gc($lifetime): int
{
$expiration = $this->calculateExpiration($lifetime);
$deletedSessions = 0;
foreach ($this->storage as $sessionId => $session) {
if ($session['time'] < $expiration) {
unset($this->storage[$sessionId]);
$deletedSessions++;
}
}
return $deletedSessions;
}
/**
* Get the expiration time of the session.
*
* @param int $seconds
* @return int
*/
protected function calculateExpiration($seconds)
{
return $this->currentTime() - $seconds;
}
}

View File

@ -0,0 +1,106 @@
<?php
namespace Illuminate\Session;
use Illuminate\Contracts\Cache\Repository as CacheContract;
use SessionHandlerInterface;
class CacheBasedSessionHandler implements SessionHandlerInterface
{
/**
* The cache repository instance.
*
* @var \Illuminate\Contracts\Cache\Repository
*/
protected $cache;
/**
* The number of minutes to store the data in the cache.
*
* @var int
*/
protected $minutes;
/**
* Create a new cache driven handler instance.
*
* @param \Illuminate\Contracts\Cache\Repository $cache
* @param int $minutes
* @return void
*/
public function __construct(CacheContract $cache, $minutes)
{
$this->cache = $cache;
$this->minutes = $minutes;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function open($savePath, $sessionName): bool
{
return true;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function close(): bool
{
return true;
}
/**
* {@inheritdoc}
*
* @return string
*/
public function read($sessionId): string
{
return $this->cache->get($sessionId, '');
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function write($sessionId, $data): bool
{
return $this->cache->put($sessionId, $data, $this->minutes * 60);
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function destroy($sessionId): bool
{
return $this->cache->forget($sessionId);
}
/**
* {@inheritdoc}
*
* @return int
*/
public function gc($lifetime): int
{
return 0;
}
/**
* Get the underlying cache repository.
*
* @return \Illuminate\Contracts\Cache\Repository
*/
public function getCache()
{
return $this->cache;
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace Illuminate\Session\Console;
use Illuminate\Console\MigrationGeneratorCommand;
use Symfony\Component\Console\Attribute\AsCommand;
#[AsCommand(name: 'session:table')]
class SessionTableCommand extends MigrationGeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'session:table';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a migration for the session database table';
/**
* Get the migration table name.
*
* @return string
*/
protected function migrationTableName()
{
return 'sessions';
}
/**
* Get the path to the migration stub file.
*
* @return string
*/
protected function migrationStubFile()
{
return __DIR__.'/stubs/database.stub';
}
}

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sessions');
}
};

View File

@ -0,0 +1,141 @@
<?php
namespace Illuminate\Session;
use Illuminate\Contracts\Cookie\QueueingFactory as CookieJar;
use Illuminate\Support\InteractsWithTime;
use SessionHandlerInterface;
use Symfony\Component\HttpFoundation\Request;
class CookieSessionHandler implements SessionHandlerInterface
{
use InteractsWithTime;
/**
* The cookie jar instance.
*
* @var \Illuminate\Contracts\Cookie\Factory
*/
protected $cookie;
/**
* The request instance.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
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 \Illuminate\Contracts\Cookie\QueueingFactory $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($value, true)) && 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($sessionId, json_encode([
'data' => $data,
'expires' => $this->availableAt($this->minutes * 60),
]), $this->expireOnClose ? 0 : $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 \Symfony\Component\HttpFoundation\Request $request
* @return void
*/
public function setRequest(Request $request)
{
$this->request = $request;
}
}

View File

@ -0,0 +1,319 @@
<?php
namespace Illuminate\Session;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\QueryException;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\InteractsWithTime;
use SessionHandlerInterface;
class DatabaseSessionHandler implements ExistenceAwareInterface, SessionHandlerInterface
{
use InteractsWithTime;
/**
* The database connection instance.
*
* @var \Illuminate\Database\ConnectionInterface
*/
protected $connection;
/**
* The name of the session table.
*
* @var string
*/
protected $table;
/**
* The number of minutes the session should be valid.
*
* @var int
*/
protected $minutes;
/**
* The container instance.
*
* @var \Illuminate\Contracts\Container\Container|null
*/
protected $container;
/**
* The existence state of the session.
*
* @var bool
*/
protected $exists;
/**
* Create a new database session handler instance.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param string $table
* @param int $minutes
* @param \Illuminate\Contracts\Container\Container|null $container
* @return void
*/
public function __construct(ConnectionInterface $connection, $table, $minutes, Container $container = null)
{
$this->table = $table;
$this->minutes = $minutes;
$this->container = $container;
$this->connection = $connection;
}
/**
* {@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
{
$session = (object) $this->getQuery()->find($sessionId);
if ($this->expired($session)) {
$this->exists = true;
return '';
}
if (isset($session->payload)) {
$this->exists = true;
return base64_decode($session->payload);
}
return '';
}
/**
* Determine if the session is expired.
*
* @param \stdClass $session
* @return bool
*/
protected function expired($session)
{
return isset($session->last_activity) &&
$session->last_activity < Carbon::now()->subMinutes($this->minutes)->getTimestamp();
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function write($sessionId, $data): bool
{
$payload = $this->getDefaultPayload($data);
if (! $this->exists) {
$this->read($sessionId);
}
if ($this->exists) {
$this->performUpdate($sessionId, $payload);
} else {
$this->performInsert($sessionId, $payload);
}
return $this->exists = true;
}
/**
* Perform an insert operation on the session ID.
*
* @param string $sessionId
* @param array<string, mixed> $payload
* @return bool|null
*/
protected function performInsert($sessionId, $payload)
{
try {
return $this->getQuery()->insert(Arr::set($payload, 'id', $sessionId));
} catch (QueryException) {
$this->performUpdate($sessionId, $payload);
}
}
/**
* Perform an update operation on the session ID.
*
* @param string $sessionId
* @param array<string, mixed> $payload
* @return int
*/
protected function performUpdate($sessionId, $payload)
{
return $this->getQuery()->where('id', $sessionId)->update($payload);
}
/**
* Get the default payload for the session.
*
* @param string $data
* @return array
*/
protected function getDefaultPayload($data)
{
$payload = [
'payload' => base64_encode($data),
'last_activity' => $this->currentTime(),
];
if (! $this->container) {
return $payload;
}
return tap($payload, function (&$payload) {
$this->addUserInformation($payload)
->addRequestInformation($payload);
});
}
/**
* Add the user information to the session payload.
*
* @param array $payload
* @return $this
*/
protected function addUserInformation(&$payload)
{
if ($this->container->bound(Guard::class)) {
$payload['user_id'] = $this->userId();
}
return $this;
}
/**
* Get the currently authenticated user's ID.
*
* @return mixed
*/
protected function userId()
{
return $this->container->make(Guard::class)->id();
}
/**
* Add the request information to the session payload.
*
* @param array $payload
* @return $this
*/
protected function addRequestInformation(&$payload)
{
if ($this->container->bound('request')) {
$payload = array_merge($payload, [
'ip_address' => $this->ipAddress(),
'user_agent' => $this->userAgent(),
]);
}
return $this;
}
/**
* Get the IP address for the current request.
*
* @return string|null
*/
protected function ipAddress()
{
return $this->container->make('request')->ip();
}
/**
* Get the user agent for the current request.
*
* @return string
*/
protected function userAgent()
{
return substr((string) $this->container->make('request')->header('User-Agent'), 0, 500);
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function destroy($sessionId): bool
{
$this->getQuery()->where('id', $sessionId)->delete();
return true;
}
/**
* {@inheritdoc}
*
* @return int
*/
public function gc($lifetime): int
{
return $this->getQuery()->where('last_activity', '<=', $this->currentTime() - $lifetime)->delete();
}
/**
* Get a fresh query builder instance for the table.
*
* @return \Illuminate\Database\Query\Builder
*/
protected function getQuery()
{
return $this->connection->table($this->table);
}
/**
* Set the application instance used by the handler.
*
* @param \Illuminate\Contracts\Foundation\Application $container
* @return $this
*/
public function setContainer($container)
{
$this->container = $container;
return $this;
}
/**
* Set the existence state for the session.
*
* @param bool $value
* @return $this
*/
public function setExists($value)
{
$this->exists = $value;
return $this;
}
}

View File

@ -0,0 +1,70 @@
<?php
namespace Illuminate\Session;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Encryption\Encrypter as EncrypterContract;
use SessionHandlerInterface;
class EncryptedStore extends Store
{
/**
* The encrypter instance.
*
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
protected $encrypter;
/**
* Create a new session instance.
*
* @param string $name
* @param \SessionHandlerInterface $handler
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
* @param string|null $id
* @param string $serialization
* @return void
*/
public function __construct($name, SessionHandlerInterface $handler, EncrypterContract $encrypter, $id = null, $serialization = 'php')
{
$this->encrypter = $encrypter;
parent::__construct($name, $handler, $id, $serialization);
}
/**
* Prepare the raw string data from the session for unserialization.
*
* @param string $data
* @return string
*/
protected function prepareForUnserialize($data)
{
try {
return $this->encrypter->decrypt($data);
} catch (DecryptException) {
return $this->serialization === 'json' ? json_encode([]) : serialize([]);
}
}
/**
* Prepare the serialized session data for storage.
*
* @param string $data
* @return string
*/
protected function prepareForStorage($data)
{
return $this->encrypter->encrypt($data);
}
/**
* Get the encrypter instance.
*
* @return \Illuminate\Contracts\Encryption\Encrypter
*/
public function getEncrypter()
{
return $this->encrypter;
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace Illuminate\Session;
interface ExistenceAwareInterface
{
/**
* Set the existence state for the session.
*
* @param bool $value
* @return \SessionHandlerInterface
*/
public function setExists($value);
}

View File

@ -0,0 +1,129 @@
<?php
namespace Illuminate\Session;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Carbon;
use SessionHandlerInterface;
use Symfony\Component\Finder\Finder;
class FileSessionHandler implements SessionHandlerInterface
{
/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* The path where sessions should be stored.
*
* @var string
*/
protected $path;
/**
* The number of minutes the session should be valid.
*
* @var int
*/
protected $minutes;
/**
* Create a new file driven handler instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param string $path
* @param int $minutes
* @return void
*/
public function __construct(Filesystem $files, $path, $minutes)
{
$this->path = $path;
$this->files = $files;
$this->minutes = $minutes;
}
/**
* {@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
{
if ($this->files->isFile($path = $this->path.'/'.$sessionId) &&
$this->files->lastModified($path) >= Carbon::now()->subMinutes($this->minutes)->getTimestamp()) {
return $this->files->sharedGet($path);
}
return '';
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function write($sessionId, $data): bool
{
$this->files->put($this->path.'/'.$sessionId, $data, true);
return true;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function destroy($sessionId): bool
{
$this->files->delete($this->path.'/'.$sessionId);
return true;
}
/**
* {@inheritdoc}
*
* @return int
*/
public function gc($lifetime): int
{
$files = Finder::create()
->in($this->path)
->files()
->ignoreDotFiles(true)
->date('<= now - '.$lifetime.' seconds');
$deletedSessions = 0;
foreach ($files as $file) {
$this->files->delete($file->getRealPath());
$deletedSessions++;
}
return $deletedSessions;
}
}

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Taylor Otwell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,123 @@
<?php
namespace Illuminate\Session\Middleware;
use Closure;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Auth\Factory as AuthFactory;
use Illuminate\Contracts\Session\Middleware\AuthenticatesSessions;
use Illuminate\Http\Request;
class AuthenticateSession implements AuthenticatesSessions
{
/**
* The authentication factory implementation.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(AuthFactory $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (! $request->hasSession() || ! $request->user()) {
return $next($request);
}
if ($this->guard()->viaRemember()) {
$passwordHash = explode('|', $request->cookies->get($this->guard()->getRecallerName()))[2] ?? null;
if (! $passwordHash || $passwordHash != $request->user()->getAuthPassword()) {
$this->logout($request);
}
}
if (! $request->session()->has('password_hash_'.$this->auth->getDefaultDriver())) {
$this->storePasswordHashInSession($request);
}
if ($request->session()->get('password_hash_'.$this->auth->getDefaultDriver()) !== $request->user()->getAuthPassword()) {
$this->logout($request);
}
return tap($next($request), function () use ($request) {
if (! is_null($this->guard()->user())) {
$this->storePasswordHashInSession($request);
}
});
}
/**
* Store the user's current password hash in the session.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
protected function storePasswordHashInSession($request)
{
if (! $request->user()) {
return;
}
$request->session()->put([
'password_hash_'.$this->auth->getDefaultDriver() => $request->user()->getAuthPassword(),
]);
}
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
*/
protected function logout($request)
{
$this->guard()->logoutCurrentDevice();
$request->session()->flush();
throw new AuthenticationException(
'Unauthenticated.', [$this->auth->getDefaultDriver()], $this->redirectTo($request)
);
}
/**
* Get the guard instance that should be used by the middleware.
*
* @return \Illuminate\Contracts\Auth\Factory|\Illuminate\Contracts\Auth\Guard
*/
protected function guard()
{
return $this->auth;
}
/**
* Get the path the user should be redirected to when their session is not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo(Request $request)
{
//
}
}

View File

@ -0,0 +1,306 @@
<?php
namespace Illuminate\Session\Middleware;
use Closure;
use Illuminate\Contracts\Session\Session;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Session\SessionManager;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Date;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
class StartSession
{
/**
* The session manager.
*
* @var \Illuminate\Session\SessionManager
*/
protected $manager;
/**
* The callback that can resolve an instance of the cache factory.
*
* @var callable|null
*/
protected $cacheFactoryResolver;
/**
* Create a new session middleware.
*
* @param \Illuminate\Session\SessionManager $manager
* @param callable|null $cacheFactoryResolver
* @return void
*/
public function __construct(SessionManager $manager, callable $cacheFactoryResolver = null)
{
$this->manager = $manager;
$this->cacheFactoryResolver = $cacheFactoryResolver;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (! $this->sessionConfigured()) {
return $next($request);
}
$session = $this->getSession($request);
if ($this->manager->shouldBlock() ||
($request->route() instanceof Route && $request->route()->locksFor())) {
return $this->handleRequestWhileBlocking($request, $session, $next);
}
return $this->handleStatefulRequest($request, $session, $next);
}
/**
* Handle the given request within session state.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Session\Session $session
* @param \Closure $next
* @return mixed
*/
protected function handleRequestWhileBlocking(Request $request, $session, Closure $next)
{
if (! $request->route() instanceof Route) {
return;
}
$lockFor = $request->route() && $request->route()->locksFor()
? $request->route()->locksFor()
: $this->manager->defaultRouteBlockLockSeconds();
$lock = $this->cache($this->manager->blockDriver())
->lock('session:'.$session->getId(), $lockFor)
->betweenBlockedAttemptsSleepFor(50);
try {
$lock->block(
! is_null($request->route()->waitsFor())
? $request->route()->waitsFor()
: $this->manager->defaultRouteBlockWaitSeconds()
);
return $this->handleStatefulRequest($request, $session, $next);
} finally {
$lock?->release();
}
}
/**
* Handle the given request within session state.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Session\Session $session
* @param \Closure $next
* @return mixed
*/
protected function handleStatefulRequest(Request $request, $session, Closure $next)
{
// If a session driver has been configured, we will need to start the session here
// so that the data is ready for an application. Note that the Laravel sessions
// do not make use of PHP "native" sessions in any way since they are crappy.
$request->setLaravelSession(
$this->startSession($request, $session)
);
$this->collectGarbage($session);
$response = $next($request);
$this->storeCurrentUrl($request, $session);
$this->addCookieToResponse($response, $session);
// Again, if the session has been configured we will need to close out the session
// so that the attributes may be persisted to some storage medium. We will also
// add the session identifier cookie to the application response headers now.
$this->saveSession($request);
return $response;
}
/**
* Start the session for the given request.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Session\Session $session
* @return \Illuminate\Contracts\Session\Session
*/
protected function startSession(Request $request, $session)
{
return tap($session, function ($session) use ($request) {
$session->setRequestOnHandler($request);
$session->start();
});
}
/**
* Get the session implementation from the manager.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\Session\Session
*/
public function getSession(Request $request)
{
return tap($this->manager->driver(), function ($session) use ($request) {
$session->setId($request->cookies->get($session->getName()));
});
}
/**
* Remove the garbage from the session if necessary.
*
* @param \Illuminate\Contracts\Session\Session $session
* @return void
*/
protected function collectGarbage(Session $session)
{
$config = $this->manager->getSessionConfig();
// Here we will see if this request hits the garbage collection lottery by hitting
// the odds needed to perform garbage collection on any given request. If we do
// hit it, we'll call this handler to let it delete all the expired sessions.
if ($this->configHitsLottery($config)) {
$session->getHandler()->gc($this->getSessionLifetimeInSeconds());
}
}
/**
* Determine if the configuration odds hit the lottery.
*
* @param array $config
* @return bool
*/
protected function configHitsLottery(array $config)
{
return random_int(1, $config['lottery'][1]) <= $config['lottery'][0];
}
/**
* Store the current URL for the request if necessary.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Session\Session $session
* @return void
*/
protected function storeCurrentUrl(Request $request, $session)
{
if ($request->isMethod('GET') &&
$request->route() instanceof Route &&
! $request->ajax() &&
! $request->prefetch() &&
! $request->isPrecognitive()) {
$session->setPreviousUrl($request->fullUrl());
}
}
/**
* Add the session cookie to the application response.
*
* @param \Symfony\Component\HttpFoundation\Response $response
* @param \Illuminate\Contracts\Session\Session $session
* @return void
*/
protected function addCookieToResponse(Response $response, Session $session)
{
if ($this->sessionIsPersistent($config = $this->manager->getSessionConfig())) {
$response->headers->setCookie(new Cookie(
$session->getName(),
$session->getId(),
$this->getCookieExpirationDate(),
$config['path'],
$config['domain'],
$config['secure'] ?? false,
$config['http_only'] ?? true,
false,
$config['same_site'] ?? null,
$config['partitioned'] ?? false
));
}
}
/**
* Save the session data to storage.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
protected function saveSession($request)
{
if (! $request->isPrecognitive()) {
$this->manager->driver()->save();
}
}
/**
* Get the session lifetime in seconds.
*
* @return int
*/
protected function getSessionLifetimeInSeconds()
{
return ($this->manager->getSessionConfig()['lifetime'] ?? null) * 60;
}
/**
* Get the cookie lifetime in seconds.
*
* @return \DateTimeInterface|int
*/
protected function getCookieExpirationDate()
{
$config = $this->manager->getSessionConfig();
return $config['expire_on_close'] ? 0 : Date::instance(
Carbon::now()->addRealMinutes($config['lifetime'])
);
}
/**
* Determine if a session driver has been configured.
*
* @return bool
*/
protected function sessionConfigured()
{
return ! is_null($this->manager->getSessionConfig()['driver'] ?? null);
}
/**
* Determine if the configured session driver is persistent.
*
* @param array|null $config
* @return bool
*/
protected function sessionIsPersistent(array $config = null)
{
$config = $config ?: $this->manager->getSessionConfig();
return ! is_null($config['driver'] ?? null);
}
/**
* Resolve the given cache driver.
*
* @param string $driver
* @return \Illuminate\Cache\Store
*/
protected function cache($driver)
{
return call_user_func($this->cacheFactoryResolver)->driver($driver);
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace Illuminate\Session;
use SessionHandlerInterface;
class NullSessionHandler implements SessionHandlerInterface
{
/**
* {@inheritdoc}
*
* @return bool
*/
public function open($savePath, $sessionName): bool
{
return true;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function close(): bool
{
return true;
}
/**
* {@inheritdoc}
*
* @return string
*/
public function read($sessionId): string
{
return '';
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function write($sessionId, $data): bool
{
return true;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function destroy($sessionId): bool
{
return true;
}
/**
* {@inheritdoc}
*
* @return int
*/
public function gc($lifetime): int
{
return 0;
}
}

View File

@ -0,0 +1,289 @@
<?php
namespace Illuminate\Session;
use Illuminate\Support\Manager;
/**
* @mixin \Illuminate\Session\Store
*/
class SessionManager extends Manager
{
/**
* Call a custom driver creator.
*
* @param string $driver
* @return \Illuminate\Session\Store
*/
protected function callCustomCreator($driver)
{
return $this->buildSession(parent::callCustomCreator($driver));
}
/**
* Create an instance of the "null" session driver.
*
* @return \Illuminate\Session\Store
*/
protected function createNullDriver()
{
return $this->buildSession(new NullSessionHandler);
}
/**
* Create an instance of the "array" session driver.
*
* @return \Illuminate\Session\Store
*/
protected function createArrayDriver()
{
return $this->buildSession(new ArraySessionHandler(
$this->config->get('session.lifetime')
));
}
/**
* Create an instance of the "cookie" session driver.
*
* @return \Illuminate\Session\Store
*/
protected function createCookieDriver()
{
return $this->buildSession(new CookieSessionHandler(
$this->container->make('cookie'),
$this->config->get('session.lifetime'),
$this->config->get('session.expire_on_close')
));
}
/**
* Create an instance of the file session driver.
*
* @return \Illuminate\Session\Store
*/
protected function createFileDriver()
{
return $this->createNativeDriver();
}
/**
* Create an instance of the file session driver.
*
* @return \Illuminate\Session\Store
*/
protected function createNativeDriver()
{
$lifetime = $this->config->get('session.lifetime');
return $this->buildSession(new FileSessionHandler(
$this->container->make('files'), $this->config->get('session.files'), $lifetime
));
}
/**
* Create an instance of the database session driver.
*
* @return \Illuminate\Session\Store
*/
protected function createDatabaseDriver()
{
$table = $this->config->get('session.table');
$lifetime = $this->config->get('session.lifetime');
return $this->buildSession(new DatabaseSessionHandler(
$this->getDatabaseConnection(), $table, $lifetime, $this->container
));
}
/**
* Get the database connection for the database driver.
*
* @return \Illuminate\Database\Connection
*/
protected function getDatabaseConnection()
{
$connection = $this->config->get('session.connection');
return $this->container->make('db')->connection($connection);
}
/**
* Create an instance of the APC session driver.
*
* @return \Illuminate\Session\Store
*/
protected function createApcDriver()
{
return $this->createCacheBased('apc');
}
/**
* Create an instance of the Memcached session driver.
*
* @return \Illuminate\Session\Store
*/
protected function createMemcachedDriver()
{
return $this->createCacheBased('memcached');
}
/**
* Create an instance of the Redis session driver.
*
* @return \Illuminate\Session\Store
*/
protected function createRedisDriver()
{
$handler = $this->createCacheHandler('redis');
$handler->getCache()->getStore()->setConnection(
$this->config->get('session.connection')
);
return $this->buildSession($handler);
}
/**
* Create an instance of the DynamoDB session driver.
*
* @return \Illuminate\Session\Store
*/
protected function createDynamodbDriver()
{
return $this->createCacheBased('dynamodb');
}
/**
* Create an instance of a cache driven driver.
*
* @param string $driver
* @return \Illuminate\Session\Store
*/
protected function createCacheBased($driver)
{
return $this->buildSession($this->createCacheHandler($driver));
}
/**
* Create the cache based session handler instance.
*
* @param string $driver
* @return \Illuminate\Session\CacheBasedSessionHandler
*/
protected function createCacheHandler($driver)
{
$store = $this->config->get('session.store') ?: $driver;
return new CacheBasedSessionHandler(
clone $this->container->make('cache')->store($store),
$this->config->get('session.lifetime')
);
}
/**
* Build the session instance.
*
* @param \SessionHandlerInterface $handler
* @return \Illuminate\Session\Store
*/
protected function buildSession($handler)
{
return $this->config->get('session.encrypt')
? $this->buildEncryptedSession($handler)
: new Store(
$this->config->get('session.cookie'),
$handler,
$id = null,
$this->config->get('session.serialization', 'php')
);
}
/**
* Build the encrypted session instance.
*
* @param \SessionHandlerInterface $handler
* @return \Illuminate\Session\EncryptedStore
*/
protected function buildEncryptedSession($handler)
{
return new EncryptedStore(
$this->config->get('session.cookie'),
$handler,
$this->container['encrypter'],
$id = null,
$this->config->get('session.serialization', 'php'),
);
}
/**
* Determine if requests for the same session should wait for each to finish before executing.
*
* @return bool
*/
public function shouldBlock()
{
return $this->config->get('session.block', false);
}
/**
* Get the name of the cache store / driver that should be used to acquire session locks.
*
* @return string|null
*/
public function blockDriver()
{
return $this->config->get('session.block_store');
}
/**
* Get the maximum number of seconds the session lock should be held for.
*
* @return int
*/
public function defaultRouteBlockLockSeconds()
{
return $this->config->get('session.block_lock_seconds', 10);
}
/**
* Get the maximum number of seconds to wait while attempting to acquire a route block session lock.
*
* @return int
*/
public function defaultRouteBlockWaitSeconds()
{
return $this->config->get('session.block_wait_seconds', 10);
}
/**
* Get the session configuration.
*
* @return array
*/
public function getSessionConfig()
{
return $this->config->get('session');
}
/**
* Get the default session driver name.
*
* @return string
*/
public function getDefaultDriver()
{
return $this->config->get('session.driver');
}
/**
* Set the default session driver name.
*
* @param string $name
* @return void
*/
public function setDefaultDriver($name)
{
$this->config->set('session.driver', $name);
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace Illuminate\Session;
use Illuminate\Contracts\Cache\Factory as CacheFactory;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Support\ServiceProvider;
class SessionServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerSessionManager();
$this->registerSessionDriver();
$this->app->singleton(StartSession::class, function ($app) {
return new StartSession($app->make(SessionManager::class), function () use ($app) {
return $app->make(CacheFactory::class);
});
});
}
/**
* Register the session manager instance.
*
* @return void
*/
protected function registerSessionManager()
{
$this->app->singleton('session', function ($app) {
return new SessionManager($app);
});
}
/**
* Register the session driver instance.
*
* @return void
*/
protected function registerSessionDriver()
{
$this->app->singleton('session.store', function ($app) {
// First, we will create the session manager which is responsible for the
// creation of the various session drivers when they are needed by the
// application instance, and will resolve them on a lazy load basis.
return $app->make('session')->driver();
});
}
}

View File

@ -0,0 +1,782 @@
<?php
namespace Illuminate\Session;
use Closure;
use Illuminate\Contracts\Session\Session;
use Illuminate\Support\Arr;
use Illuminate\Support\MessageBag;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\ViewErrorBag;
use SessionHandlerInterface;
use stdClass;
class Store implements Session
{
use Macroable;
/**
* The session ID.
*
* @var string
*/
protected $id;
/**
* The session name.
*
* @var string
*/
protected $name;
/**
* The session attributes.
*
* @var array
*/
protected $attributes = [];
/**
* The session handler implementation.
*
* @var \SessionHandlerInterface
*/
protected $handler;
/**
* The session store's serialization strategy.
*
* @var string
*/
protected $serialization = 'php';
/**
* Session store started status.
*
* @var bool
*/
protected $started = false;
/**
* Create a new session instance.
*
* @param string $name
* @param \SessionHandlerInterface $handler
* @param string|null $id
* @param string $serialization
* @return void
*/
public function __construct($name, SessionHandlerInterface $handler, $id = null, $serialization = 'php')
{
$this->setId($id);
$this->name = $name;
$this->handler = $handler;
$this->serialization = $serialization;
}
/**
* Start the session, reading the data from a handler.
*
* @return bool
*/
public function start()
{
$this->loadSession();
if (! $this->has('_token')) {
$this->regenerateToken();
}
return $this->started = true;
}
/**
* Load the session data from the handler.
*
* @return void
*/
protected function loadSession()
{
$this->attributes = array_merge($this->attributes, $this->readFromHandler());
$this->marshalErrorBag();
}
/**
* Read the session data from the handler.
*
* @return array
*/
protected function readFromHandler()
{
if ($data = $this->handler->read($this->getId())) {
if ($this->serialization === 'json') {
$data = json_decode($this->prepareForUnserialize($data), true);
} else {
$data = @unserialize($this->prepareForUnserialize($data));
}
if ($data !== false && is_array($data)) {
return $data;
}
}
return [];
}
/**
* Prepare the raw string data from the session for unserialization.
*
* @param string $data
* @return string
*/
protected function prepareForUnserialize($data)
{
return $data;
}
/**
* Marshal the ViewErrorBag when using JSON serialization for sessions.
*
* @return void
*/
protected function marshalErrorBag()
{
if ($this->serialization !== 'json' || $this->missing('errors')) {
return;
}
$errorBag = new ViewErrorBag;
foreach ($this->get('errors') as $key => $value) {
$messageBag = new MessageBag($value['messages']);
$errorBag->put($key, $messageBag->setFormat($value['format']));
}
$this->put('errors', $errorBag);
}
/**
* Save the session data to storage.
*
* @return void
*/
public function save()
{
$this->ageFlashData();
$this->prepareErrorBagForSerialization();
$this->handler->write($this->getId(), $this->prepareForStorage(
$this->serialization === 'json' ? json_encode($this->attributes) : serialize($this->attributes)
));
$this->started = false;
}
/**
* Prepare the ViewErrorBag instance for JSON serialization.
*
* @return void
*/
protected function prepareErrorBagForSerialization()
{
if ($this->serialization !== 'json' || $this->missing('errors')) {
return;
}
$errors = [];
foreach ($this->attributes['errors']->getBags() as $key => $value) {
$errors[$key] = [
'format' => $value->getFormat(),
'messages' => $value->getMessages(),
];
}
$this->attributes['errors'] = $errors;
}
/**
* Prepare the serialized session data for storage.
*
* @param string $data
* @return string
*/
protected function prepareForStorage($data)
{
return $data;
}
/**
* Age the flash data for the session.
*
* @return void
*/
public function ageFlashData()
{
$this->forget($this->get('_flash.old', []));
$this->put('_flash.old', $this->get('_flash.new', []));
$this->put('_flash.new', []);
}
/**
* Get all of the session data.
*
* @return array
*/
public function all()
{
return $this->attributes;
}
/**
* Get a subset of the session data.
*
* @param array $keys
* @return array
*/
public function only(array $keys)
{
return Arr::only($this->attributes, $keys);
}
/**
* Get all the session data except for a specified array of items.
*
* @param array $keys
* @return array
*/
public function except(array $keys)
{
return Arr::except($this->attributes, $keys);
}
/**
* Checks if a key exists.
*
* @param string|array $key
* @return bool
*/
public function exists($key)
{
$placeholder = new stdClass;
return ! collect(is_array($key) ? $key : func_get_args())->contains(function ($key) use ($placeholder) {
return $this->get($key, $placeholder) === $placeholder;
});
}
/**
* Determine if the given key is missing from the session data.
*
* @param string|array $key
* @return bool
*/
public function missing($key)
{
return ! $this->exists($key);
}
/**
* Checks if a key is present and not null.
*
* @param string|array $key
* @return bool
*/
public function has($key)
{
return ! collect(is_array($key) ? $key : func_get_args())->contains(function ($key) {
return is_null($this->get($key));
});
}
/**
* Get an item from the session.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
{
return Arr::get($this->attributes, $key, $default);
}
/**
* Get the value of a given key and then forget it.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function pull($key, $default = null)
{
return Arr::pull($this->attributes, $key, $default);
}
/**
* Determine if the session contains old input.
*
* @param string|null $key
* @return bool
*/
public function hasOldInput($key = null)
{
$old = $this->getOldInput($key);
return is_null($key) ? count($old) > 0 : ! is_null($old);
}
/**
* Get the requested item from the flashed input array.
*
* @param string|null $key
* @param mixed $default
* @return mixed
*/
public function getOldInput($key = null, $default = null)
{
return Arr::get($this->get('_old_input', []), $key, $default);
}
/**
* Replace the given session attributes entirely.
*
* @param array $attributes
* @return void
*/
public function replace(array $attributes)
{
$this->put($attributes);
}
/**
* Put a key / value pair or array of key / value pairs in the session.
*
* @param string|array $key
* @param mixed $value
* @return void
*/
public function put($key, $value = null)
{
if (! is_array($key)) {
$key = [$key => $value];
}
foreach ($key as $arrayKey => $arrayValue) {
Arr::set($this->attributes, $arrayKey, $arrayValue);
}
}
/**
* Get an item from the session, or store the default value.
*
* @param string $key
* @param \Closure $callback
* @return mixed
*/
public function remember($key, Closure $callback)
{
if (! is_null($value = $this->get($key))) {
return $value;
}
return tap($callback(), function ($value) use ($key) {
$this->put($key, $value);
});
}
/**
* Push a value onto a session array.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function push($key, $value)
{
$array = $this->get($key, []);
$array[] = $value;
$this->put($key, $array);
}
/**
* Increment the value of an item in the session.
*
* @param string $key
* @param int $amount
* @return mixed
*/
public function increment($key, $amount = 1)
{
$this->put($key, $value = $this->get($key, 0) + $amount);
return $value;
}
/**
* Decrement the value of an item in the session.
*
* @param string $key
* @param int $amount
* @return int
*/
public function decrement($key, $amount = 1)
{
return $this->increment($key, $amount * -1);
}
/**
* Flash a key / value pair to the session.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function flash(string $key, $value = true)
{
$this->put($key, $value);
$this->push('_flash.new', $key);
$this->removeFromOldFlashData([$key]);
}
/**
* Flash a key / value pair to the session for immediate use.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function now($key, $value)
{
$this->put($key, $value);
$this->push('_flash.old', $key);
}
/**
* Reflash all of the session flash data.
*
* @return void
*/
public function reflash()
{
$this->mergeNewFlashes($this->get('_flash.old', []));
$this->put('_flash.old', []);
}
/**
* Reflash a subset of the current flash data.
*
* @param array|mixed $keys
* @return void
*/
public function keep($keys = null)
{
$this->mergeNewFlashes($keys = is_array($keys) ? $keys : func_get_args());
$this->removeFromOldFlashData($keys);
}
/**
* Merge new flash keys into the new flash array.
*
* @param array $keys
* @return void
*/
protected function mergeNewFlashes(array $keys)
{
$values = array_unique(array_merge($this->get('_flash.new', []), $keys));
$this->put('_flash.new', $values);
}
/**
* Remove the given keys from the old flash data.
*
* @param array $keys
* @return void
*/
protected function removeFromOldFlashData(array $keys)
{
$this->put('_flash.old', array_diff($this->get('_flash.old', []), $keys));
}
/**
* Flash an input array to the session.
*
* @param array $value
* @return void
*/
public function flashInput(array $value)
{
$this->flash('_old_input', $value);
}
/**
* Remove an item from the session, returning its value.
*
* @param string $key
* @return mixed
*/
public function remove($key)
{
return Arr::pull($this->attributes, $key);
}
/**
* Remove one or many items from the session.
*
* @param string|array $keys
* @return void
*/
public function forget($keys)
{
Arr::forget($this->attributes, $keys);
}
/**
* Remove all of the items from the session.
*
* @return void
*/
public function flush()
{
$this->attributes = [];
}
/**
* Flush the session data and regenerate the ID.
*
* @return bool
*/
public function invalidate()
{
$this->flush();
return $this->migrate(true);
}
/**
* Generate a new session identifier.
*
* @param bool $destroy
* @return bool
*/
public function regenerate($destroy = false)
{
return tap($this->migrate($destroy), function () {
$this->regenerateToken();
});
}
/**
* Generate a new session ID for the session.
*
* @param bool $destroy
* @return bool
*/
public function migrate($destroy = false)
{
if ($destroy) {
$this->handler->destroy($this->getId());
}
$this->setExists(false);
$this->setId($this->generateSessionId());
return true;
}
/**
* Determine if the session has been started.
*
* @return bool
*/
public function isStarted()
{
return $this->started;
}
/**
* Get the name of the session.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set the name of the session.
*
* @param string $name
* @return void
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get the current session ID.
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Set the session ID.
*
* @param string|null $id
* @return void
*/
public function setId($id)
{
$this->id = $this->isValidId($id) ? $id : $this->generateSessionId();
}
/**
* Determine if this is a valid session ID.
*
* @param string|null $id
* @return bool
*/
public function isValidId($id)
{
return is_string($id) && ctype_alnum($id) && strlen($id) === 40;
}
/**
* Get a new, random session ID.
*
* @return string
*/
protected function generateSessionId()
{
return Str::random(40);
}
/**
* Set the existence of the session on the handler if applicable.
*
* @param bool $value
* @return void
*/
public function setExists($value)
{
if ($this->handler instanceof ExistenceAwareInterface) {
$this->handler->setExists($value);
}
}
/**
* Get the CSRF token value.
*
* @return string
*/
public function token()
{
return $this->get('_token');
}
/**
* Regenerate the CSRF token value.
*
* @return void
*/
public function regenerateToken()
{
$this->put('_token', Str::random(40));
}
/**
* Get the previous URL from the session.
*
* @return string|null
*/
public function previousUrl()
{
return $this->get('_previous.url');
}
/**
* Set the "previous" URL in the session.
*
* @param string $url
* @return void
*/
public function setPreviousUrl($url)
{
$this->put('_previous.url', $url);
}
/**
* Specify that the user has confirmed their password.
*
* @return void
*/
public function passwordConfirmed()
{
$this->put('auth.password_confirmed_at', time());
}
/**
* Get the underlying session handler implementation.
*
* @return \SessionHandlerInterface
*/
public function getHandler()
{
return $this->handler;
}
/**
* Set the underlying session handler implementation.
*
* @param \SessionHandlerInterface $handler
* @return \SessionHandlerInterface
*/
public function setHandler(SessionHandlerInterface $handler)
{
return $this->handler = $handler;
}
/**
* Determine if the session handler needs a request.
*
* @return bool
*/
public function handlerNeedsRequest()
{
return $this->handler instanceof CookieSessionHandler;
}
/**
* Set the request on the handler instance.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
public function setRequestOnHandler($request)
{
if ($this->handlerNeedsRequest()) {
$this->handler->setRequest($request);
}
}
}

View File

@ -0,0 +1,200 @@
<?php
namespace Illuminate\Session;
use BadMethodCallException;
use Illuminate\Contracts\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
class SymfonySessionDecorator implements SessionInterface
{
/**
* The underlying Laravel session store.
*
* @var \Illuminate\Session\Store
*/
protected $store;
/**
* Create a new session decorator.
*
* @param \Illuminate\Contracts\Session\Session $store
* @return void
*/
public function __construct(Session $store)
{
$this->store = $store;
}
/**
* {@inheritdoc}
*/
public function start(): bool
{
return $this->store->start();
}
/**
* {@inheritdoc}
*/
public function getId(): string
{
return $this->store->getId();
}
/**
* {@inheritdoc}
*
* @return void
*/
public function setId(string $id)
{
$this->store->setId($id);
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return $this->store->getName();
}
/**
* {@inheritdoc}
*
* @return void
*/
public function setName(string $name)
{
$this->store->setName($name);
}
/**
* {@inheritdoc}
*/
public function invalidate(int $lifetime = null): bool
{
$this->store->invalidate();
return true;
}
/**
* {@inheritdoc}
*/
public function migrate(bool $destroy = false, int $lifetime = null): bool
{
$this->store->migrate($destroy);
return true;
}
/**
* {@inheritdoc}
*
* @return void
*/
public function save()
{
$this->store->save();
}
/**
* {@inheritdoc}
*/
public function has(string $name): bool
{
return $this->store->has($name);
}
/**
* {@inheritdoc}
*/
public function get(string $name, mixed $default = null): mixed
{
return $this->store->get($name, $default);
}
/**
* {@inheritdoc}
*
* @return void
*/
public function set(string $name, mixed $value)
{
$this->store->put($name, $value);
}
/**
* {@inheritdoc}
*/
public function all(): array
{
return $this->store->all();
}
/**
* {@inheritdoc}
*
* @return void
*/
public function replace(array $attributes)
{
$this->store->replace($attributes);
}
/**
* {@inheritdoc}
*/
public function remove(string $name): mixed
{
return $this->store->remove($name);
}
/**
* {@inheritdoc}
*
* @return void
*/
public function clear()
{
$this->store->flush();
}
/**
* {@inheritdoc}
*/
public function isStarted(): bool
{
return $this->store->isStarted();
}
/**
* {@inheritdoc}
*
* @return void
*/
public function registerBag(SessionBagInterface $bag)
{
throw new BadMethodCallException('Method not implemented by Laravel.');
}
/**
* {@inheritdoc}
*/
public function getBag(string $name): SessionBagInterface
{
throw new BadMethodCallException('Method not implemented by Laravel.');
}
/**
* {@inheritdoc}
*/
public function getMetadataBag(): MetadataBag
{
throw new BadMethodCallException('Method not implemented by Laravel.');
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace Illuminate\Session;
use Exception;
class TokenMismatchException extends Exception
{
//
}

View File

@ -0,0 +1,44 @@
{
"name": "illuminate/session",
"description": "The Illuminate Session package.",
"license": "MIT",
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"require": {
"php": "^8.1",
"ext-ctype": "*",
"ext-session": "*",
"illuminate/collections": "^10.0",
"illuminate/contracts": "^10.0",
"illuminate/filesystem": "^10.0",
"illuminate/support": "^10.0",
"symfony/finder": "^6.2",
"symfony/http-foundation": "^6.4"
},
"autoload": {
"psr-4": {
"Illuminate\\Session\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "10.x-dev"
}
},
"suggest": {
"illuminate/console": "Required to use the session:table command (^10.0)."
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}