Update v1.0.6
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use SessionHandlerInterface;
|
||||
use Illuminate\Contracts\Cache\Repository as CacheContract;
|
||||
|
||||
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}
|
||||
*/
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function read($sessionId)
|
||||
{
|
||||
return $this->cache->get($sessionId, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
{
|
||||
return $this->cache->put($sessionId, $data, $this->minutes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
{
|
||||
return $this->cache->forget($sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function gc($lifetime)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying cache repository.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
public function getCache()
|
||||
{
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class CommandsServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = true;
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('command.session.database', function($app)
|
||||
{
|
||||
return new Console\SessionTableCommand($app['files'], $app['composer']);
|
||||
});
|
||||
|
||||
$this->commands('command.session.database');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('command.session.database');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
<?php namespace Illuminate\Session\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Composer;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class SessionTableCommand extends Command {
|
||||
|
||||
/**
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Foundation\Composer
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* Create a new session table command instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @param \Illuminate\Foundation\Composer $composer
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Filesystem $files, Composer $composer)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->files = $files;
|
||||
$this->composer = $composer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$fullPath = $this->createBaseMigration();
|
||||
|
||||
$this->files->put($fullPath, $this->files->get(__DIR__.'/stubs/database.stub'));
|
||||
|
||||
$this->info('Migration created successfully!');
|
||||
|
||||
$this->composer->dumpAutoloads();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a base migration file for the session.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function createBaseMigration()
|
||||
{
|
||||
$name = 'create_session_table';
|
||||
|
||||
$path = $this->laravel->databasePath().'/migrations';
|
||||
|
||||
return $this->laravel['migration.creator']->create($name, $path);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateSessionTable extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('sessions', function($t)
|
||||
{
|
||||
$t->string('id')->unique();
|
||||
$t->text('payload');
|
||||
$t->integer('last_activity');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('sessions');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use SessionHandlerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Illuminate\Contracts\Cookie\QueueingFactory as CookieJar;
|
||||
|
||||
class CookieSessionHandler implements SessionHandlerInterface {
|
||||
|
||||
/**
|
||||
* The cookie jar instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cookie\Factory
|
||||
*/
|
||||
protected $cookie;
|
||||
|
||||
/**
|
||||
* The request instance.
|
||||
*
|
||||
* @var \Symfony\Component\HttpFoundation\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new cookie driven handler instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cookie\QueueingFactory $cookie
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(CookieJar $cookie, $minutes)
|
||||
{
|
||||
$this->cookie = $cookie;
|
||||
$this->minutes = $minutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function read($sessionId)
|
||||
{
|
||||
return $this->request->cookies->get($sessionId) ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
{
|
||||
$this->cookie->queue($sessionId, $data, $this->minutes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
{
|
||||
$this->cookie->queue($this->cookie->forget($sessionId));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function gc($lifetime)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request instance.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function setRequest(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use SessionHandlerInterface;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
||||
class DatabaseSessionHandler implements SessionHandlerInterface, ExistenceAwareInterface {
|
||||
|
||||
/**
|
||||
* The database connection instance.
|
||||
*
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The name of the session table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ConnectionInterface $connection, $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function read($sessionId)
|
||||
{
|
||||
$session = (object) $this->getQuery()->find($sessionId);
|
||||
|
||||
if (isset($session->payload))
|
||||
{
|
||||
$this->exists = true;
|
||||
|
||||
return base64_decode($session->payload);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
{
|
||||
if ($this->exists)
|
||||
{
|
||||
$this->getQuery()->where('id', $sessionId)->update([
|
||||
'payload' => base64_encode($data), 'last_activity' => time(),
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->getQuery()->insert([
|
||||
'id' => $sessionId, 'payload' => base64_encode($data), 'last_activity' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->exists = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
{
|
||||
$this->getQuery()->where('id', $sessionId)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function gc($lifetime)
|
||||
{
|
||||
$this->getQuery()->where('last_activity', '<=', time() - $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 existence state for the session.
|
||||
*
|
||||
* @param bool $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setExists($value)
|
||||
{
|
||||
$this->exists = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use SessionHandlerInterface;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Contracts\Encryption\Encrypter as EncrypterContract;
|
||||
|
||||
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
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($name, SessionHandlerInterface $handler, EncrypterContract $encrypter, $id = null)
|
||||
{
|
||||
$this->encrypter = $encrypter;
|
||||
|
||||
parent::__construct($name, $handler, $id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $e)
|
||||
{
|
||||
return 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
interface ExistenceAwareInterface {
|
||||
|
||||
/**
|
||||
* Set the existence state for the session.
|
||||
*
|
||||
* @param bool $value
|
||||
* @return \SessionHandlerInterface
|
||||
*/
|
||||
public function setExists($value);
|
||||
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use SessionHandlerInterface;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class FileSessionHandler implements SessionHandlerInterface {
|
||||
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* The path where sessions should be stored.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* Create a new file driven handler instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Filesystem $files, $path)
|
||||
{
|
||||
$this->path = $path;
|
||||
$this->files = $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function open($savePath, $sessionName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function read($sessionId)
|
||||
{
|
||||
if ($this->files->exists($path = $this->path.'/'.$sessionId))
|
||||
{
|
||||
return $this->files->get($path);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
{
|
||||
$this->files->put($this->path.'/'.$sessionId, $data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
{
|
||||
$this->files->delete($this->path.'/'.$sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function gc($lifetime)
|
||||
{
|
||||
$files = Finder::create()
|
||||
->in($this->path)
|
||||
->files()
|
||||
->ignoreDotFiles(true)
|
||||
->date('<= now - '.$lifetime.' seconds');
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$this->files->delete($file->getRealPath());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
<?php namespace Illuminate\Session\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Session\SessionInterface;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Illuminate\Session\CookieSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Illuminate\Contracts\Routing\TerminableMiddleware;
|
||||
|
||||
class StartSession implements TerminableMiddleware {
|
||||
|
||||
/**
|
||||
* The session manager.
|
||||
*
|
||||
* @var \Illuminate\Session\SessionManager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* Indicates if the session was handled for the current request.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $sessionHandled = false;
|
||||
|
||||
/**
|
||||
* Create a new session middleware.
|
||||
*
|
||||
* @param \Illuminate\Session\SessionManager $manager
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(SessionManager $manager)
|
||||
{
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$this->sessionHandled = true;
|
||||
|
||||
// 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.
|
||||
if ($this->sessionConfigured())
|
||||
{
|
||||
$session = $this->startSession($request);
|
||||
|
||||
$request->setSession($session);
|
||||
}
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
// 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.
|
||||
if ($this->sessionConfigured())
|
||||
{
|
||||
$this->storeCurrentUrl($request, $session);
|
||||
|
||||
$this->collectGarbage($session);
|
||||
|
||||
$this->addCookieToResponse($response, $session);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform any final actions for the request lifecycle.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Symfony\Component\HttpFoundation\Response $response
|
||||
* @return void
|
||||
*/
|
||||
public function terminate($request, $response)
|
||||
{
|
||||
if ($this->sessionHandled && $this->sessionConfigured() && ! $this->usingCookieSessions())
|
||||
{
|
||||
$this->manager->driver()->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the session for the given request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Session\SessionInterface
|
||||
*/
|
||||
protected function startSession(Request $request)
|
||||
{
|
||||
with($session = $this->getSession($request))->setRequestOnHandler($request);
|
||||
|
||||
$session->start();
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session implementation from the manager.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Session\SessionInterface
|
||||
*/
|
||||
public function getSession(Request $request)
|
||||
{
|
||||
$session = $this->manager->driver();
|
||||
|
||||
$session->setId($request->cookies->get($session->getName()));
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the current URL for the request if necessary.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Session\SessionInterface $session
|
||||
* @return void
|
||||
*/
|
||||
protected function storeCurrentUrl(Request $request, $session)
|
||||
{
|
||||
if ($request->method() === 'GET' && $request->route() && ! $request->ajax())
|
||||
{
|
||||
$session->setPreviousUrl($request->fullUrl());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the garbage from the session if necessary.
|
||||
*
|
||||
* @param \Illuminate\Session\SessionInterface $session
|
||||
* @return void
|
||||
*/
|
||||
protected function collectGarbage(SessionInterface $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 mt_rand(1, $config['lottery'][1]) <= $config['lottery'][0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the session cookie to the application response.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Response $response
|
||||
* @param \Illuminate\Session\SessionInterface $session
|
||||
* @return void
|
||||
*/
|
||||
protected function addCookieToResponse(Response $response, SessionInterface $session)
|
||||
{
|
||||
if ($this->usingCookieSessions())
|
||||
{
|
||||
$this->manager->driver()->save();
|
||||
}
|
||||
|
||||
if ($this->sessionIsPersistent($config = $this->manager->getSessionConfig()))
|
||||
{
|
||||
$response->headers->setCookie(new Cookie(
|
||||
$session->getName(), $session->getId(), $this->getCookieExpirationDate(),
|
||||
$config['path'], $config['domain'], array_get($config, 'secure', false)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session lifetime in seconds.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getSessionLifetimeInSeconds()
|
||||
{
|
||||
return array_get($this->manager->getSessionConfig(), 'lifetime') * 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cookie lifetime in seconds.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getCookieExpirationDate()
|
||||
{
|
||||
$config = $this->manager->getSessionConfig();
|
||||
|
||||
return $config['expire_on_close'] ? 0 : Carbon::now()->addMinutes($config['lifetime']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a session driver has been configured.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function sessionConfigured()
|
||||
{
|
||||
return ! is_null(array_get($this->manager->getSessionConfig(), 'driver'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ! in_array($config['driver'], array(null, 'array'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the session is using cookie sessions.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function usingCookieSessions()
|
||||
{
|
||||
if ( ! $this->sessionConfigured()) return false;
|
||||
|
||||
return $this->manager->driver()->getHandler() instanceof CookieSessionHandler;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface as BaseSessionInterface;
|
||||
|
||||
interface SessionInterface extends BaseSessionInterface {
|
||||
|
||||
/**
|
||||
* Get the session handler instance.
|
||||
*
|
||||
* @return \SessionHandlerInterface
|
||||
*/
|
||||
public function getHandler();
|
||||
|
||||
/**
|
||||
* Determine if the session handler needs a request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function handlerNeedsRequest();
|
||||
|
||||
/**
|
||||
* Set the request on the handler instance.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function setRequestOnHandler(Request $request);
|
||||
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use Illuminate\Support\Manager;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
|
||||
|
||||
class SessionManager extends Manager {
|
||||
|
||||
/**
|
||||
* Call a custom driver creator.
|
||||
*
|
||||
* @param string $driver
|
||||
* @return mixed
|
||||
*/
|
||||
protected function callCustomCreator($driver)
|
||||
{
|
||||
return $this->buildSession(parent::callCustomCreator($driver));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the "array" session driver.
|
||||
*
|
||||
* @return \Illuminate\Session\Store
|
||||
*/
|
||||
protected function createArrayDriver()
|
||||
{
|
||||
return $this->buildSession(new NullSessionHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the "cookie" session driver.
|
||||
*
|
||||
* @return \Illuminate\Session\Store
|
||||
*/
|
||||
protected function createCookieDriver()
|
||||
{
|
||||
$lifetime = $this->app['config']['session.lifetime'];
|
||||
|
||||
return $this->buildSession(new CookieSessionHandler($this->app['cookie'], $lifetime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$path = $this->app['config']['session.files'];
|
||||
|
||||
return $this->buildSession(new FileSessionHandler($this->app['files'], $path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the database session driver.
|
||||
*
|
||||
* @return \Illuminate\Session\Store
|
||||
*/
|
||||
protected function createDatabaseDriver()
|
||||
{
|
||||
$connection = $this->getDatabaseConnection();
|
||||
|
||||
$table = $this->app['config']['session.table'];
|
||||
|
||||
return $this->buildSession(new DatabaseSessionHandler($connection, $table));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database connection for the database driver.
|
||||
*
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
protected function getDatabaseConnection()
|
||||
{
|
||||
$connection = $this->app['config']['session.connection'];
|
||||
|
||||
return $this->app['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 Wincache session driver.
|
||||
*
|
||||
* @return \Illuminate\Session\Store
|
||||
*/
|
||||
protected function createWincacheDriver()
|
||||
{
|
||||
return $this->createCacheBased('wincache');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the Redis session driver.
|
||||
*
|
||||
* @return \Illuminate\Session\Store
|
||||
*/
|
||||
protected function createRedisDriver()
|
||||
{
|
||||
$handler = $this->createCacheHandler('redis');
|
||||
|
||||
$handler->getCache()->getStore()->setConnection($this->app['config']['session.connection']);
|
||||
|
||||
return $this->buildSession($handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$minutes = $this->app['config']['session.lifetime'];
|
||||
|
||||
return new CacheBasedSessionHandler($this->app['cache']->driver($driver), $minutes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the session instance.
|
||||
*
|
||||
* @param \SessionHandlerInterface $handler
|
||||
* @return \Illuminate\Session\Store
|
||||
*/
|
||||
protected function buildSession($handler)
|
||||
{
|
||||
if ($this->app['config']['session.encrypt'])
|
||||
{
|
||||
return new EncryptedStore(
|
||||
$this->app['config']['session.cookie'], $handler, $this->app['encrypter']
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Store($this->app['config']['session.cookie'], $handler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session configuration.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSessionConfig()
|
||||
{
|
||||
return $this->app['config']['session'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default session driver name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultDriver()
|
||||
{
|
||||
return $this->app['config']['session.driver'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default session driver name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultDriver($name)
|
||||
{
|
||||
$this->app['config']['session.driver'] = $name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class SessionServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerSessionManager();
|
||||
|
||||
$this->registerSessionDriver();
|
||||
|
||||
$this->app->singleton('Illuminate\Session\Middleware\StartSession');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
$manager = $app['session'];
|
||||
|
||||
return $manager->driver();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,678 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use SessionHandlerInterface;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
|
||||
|
||||
class Store implements SessionInterface {
|
||||
|
||||
/**
|
||||
* The session ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The session name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The session attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = array();
|
||||
|
||||
/**
|
||||
* The session bags.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $bags = array();
|
||||
|
||||
/**
|
||||
* The meta-data bag instance.
|
||||
*
|
||||
* @var \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag
|
||||
*/
|
||||
protected $metaBag;
|
||||
|
||||
/**
|
||||
* Local copies of the session bag data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $bagData = array();
|
||||
|
||||
/**
|
||||
* The session handler implementation.
|
||||
*
|
||||
* @var \SessionHandlerInterface
|
||||
*/
|
||||
protected $handler;
|
||||
|
||||
/**
|
||||
* Session store started status.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $started = false;
|
||||
|
||||
/**
|
||||
* Create a new session instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param \SessionHandlerInterface $handler
|
||||
* @param string|null $id
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($name, SessionHandlerInterface $handler, $id = null)
|
||||
{
|
||||
$this->setId($id);
|
||||
$this->name = $name;
|
||||
$this->handler = $handler;
|
||||
$this->metaBag = new MetadataBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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());
|
||||
|
||||
foreach (array_merge($this->bags, array($this->metaBag)) as $bag)
|
||||
{
|
||||
$this->initializeLocalBag($bag);
|
||||
|
||||
$bag->initialize($this->bagData[$bag->getStorageKey()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the session data from the handler.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function readFromHandler()
|
||||
{
|
||||
$data = $this->handler->read($this->getId());
|
||||
|
||||
if ($data)
|
||||
{
|
||||
$data = @unserialize($this->prepareForUnserialize($data));
|
||||
|
||||
if ($data !== false) return $data;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the raw string data from the session for unserialization.
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
protected function prepareForUnserialize($data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a bag in storage if it doesn't exist.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Session\SessionBagInterface $bag
|
||||
* @return void
|
||||
*/
|
||||
protected function initializeLocalBag($bag)
|
||||
{
|
||||
$this->bagData[$bag->getStorageKey()] = $this->pull($bag->getStorageKey(), []);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
if ( ! $this->isValidId($id))
|
||||
{
|
||||
$id = $this->generateSessionId();
|
||||
}
|
||||
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this is a valid session ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidId($id)
|
||||
{
|
||||
return is_string($id) && preg_match('/^[a-f0-9]{40}$/', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new, random session ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateSessionId()
|
||||
{
|
||||
return sha1(uniqid('', true).str_random(25).microtime(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidate($lifetime = null)
|
||||
{
|
||||
$this->clear();
|
||||
|
||||
return $this->migrate(true, $lifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function migrate($destroy = false, $lifetime = null)
|
||||
{
|
||||
if ($destroy) $this->handler->destroy($this->getId());
|
||||
|
||||
$this->setExists(false);
|
||||
|
||||
$this->id = $this->generateSessionId();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new session identifier.
|
||||
*
|
||||
* @param bool $destroy
|
||||
* @return bool
|
||||
*/
|
||||
public function regenerate($destroy = false)
|
||||
{
|
||||
return $this->migrate($destroy);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->addBagDataToSession();
|
||||
|
||||
$this->ageFlashData();
|
||||
|
||||
$this->handler->write($this->getId(), $this->prepareForStorage(serialize($this->attributes)));
|
||||
|
||||
$this->started = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the serialized session data for storage.
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
protected function prepareForStorage($data)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge all of the bag data into the session.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addBagDataToSession()
|
||||
{
|
||||
foreach (array_merge($this->bags, array($this->metaBag)) as $bag)
|
||||
{
|
||||
$this->put($bag->getStorageKey(), $this->bagData[$bag->getStorageKey()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Age the flash data for the session.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ageFlashData()
|
||||
{
|
||||
foreach ($this->get('flash.old', array()) as $old) { $this->forget($old); }
|
||||
|
||||
$this->put('flash.old', $this->get('flash.new', array()));
|
||||
|
||||
$this->put('flash.new', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
return ! is_null($this->get($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
return array_get($this->attributes, $name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a given key and then forget it.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function pull($key, $default = null)
|
||||
{
|
||||
return array_pull($this->attributes, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the session contains old input.
|
||||
*
|
||||
* @param string $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 $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOldInput($key = null, $default = null)
|
||||
{
|
||||
$input = $this->get('_old_input', array());
|
||||
|
||||
// Input that is flashed to the session can be easily retrieved by the
|
||||
// developer, making repopulating old forms and the like much more
|
||||
// convenient, since the request's previous input is available.
|
||||
return array_get($input, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
array_set($this->attributes, $name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a key / value pair or array of key / value pairs in the session.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @param mixed|null $value
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value = null)
|
||||
{
|
||||
if ( ! is_array($key)) $key = array($key => $value);
|
||||
|
||||
foreach ($key as $arrayKey => $arrayValue)
|
||||
{
|
||||
$this->set($arrayKey, $arrayValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
|
||||
$array[] = $value;
|
||||
|
||||
$this->put($key, $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash a key / value pair to the session.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function flash($key, $value)
|
||||
{
|
||||
$this->put($key, $value);
|
||||
|
||||
$this->push('flash.new', $key);
|
||||
|
||||
$this->removeFromOldFlashData(array($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash an input array to the session.
|
||||
*
|
||||
* @param array $value
|
||||
* @return void
|
||||
*/
|
||||
public function flashInput(array $value)
|
||||
{
|
||||
$this->flash('_old_input', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflash all of the session flash data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reflash()
|
||||
{
|
||||
$this->mergeNewFlashes($this->get('flash.old', array()));
|
||||
|
||||
$this->put('flash.old', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflash a subset of the current flash data.
|
||||
*
|
||||
* @param array|mixed $keys
|
||||
* @return void
|
||||
*/
|
||||
public function keep($keys = null)
|
||||
{
|
||||
$keys = is_array($keys) ? $keys : func_get_args();
|
||||
|
||||
$this->mergeNewFlashes($keys);
|
||||
|
||||
$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', array()), $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', array()), $keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function replace(array $attributes)
|
||||
{
|
||||
$this->put($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function remove($name)
|
||||
{
|
||||
return array_pull($this->attributes, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the session.
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
array_forget($this->attributes, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->attributes = array();
|
||||
|
||||
foreach ($this->bags as $bag)
|
||||
{
|
||||
$bag->clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all of the items from the session.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isStarted()
|
||||
{
|
||||
return $this->started;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function registerBag(SessionBagInterface $bag)
|
||||
{
|
||||
$this->bags[$bag->getStorageKey()] = $bag;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBag($name)
|
||||
{
|
||||
return array_get($this->bags, $name, function()
|
||||
{
|
||||
throw new InvalidArgumentException("Bag not registered.");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadataBag()
|
||||
{
|
||||
return $this->metaBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw bag data array for a given bag.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function getBagData($name)
|
||||
{
|
||||
return array_get($this->bagData, $name, array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the CSRF token value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function token()
|
||||
{
|
||||
return $this->get('_token');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the CSRF token value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return $this->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)
|
||||
{
|
||||
return $this->put('_previous.url', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 underlying session handler implementation.
|
||||
*
|
||||
* @return \SessionHandlerInterface
|
||||
*/
|
||||
public function getHandler()
|
||||
{
|
||||
return $this->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 \Symfony\Component\HttpFoundation\Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function setRequestOnHandler(Request $request)
|
||||
{
|
||||
if ($this->handlerNeedsRequest())
|
||||
{
|
||||
$this->handler->setRequest($request);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php namespace Illuminate\Session;
|
||||
|
||||
use Exception;
|
||||
|
||||
class TokenMismatchException extends Exception {}
|
||||
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"name": "illuminate/session",
|
||||
"description": "The Illuminate Session package.",
|
||||
"license": "MIT",
|
||||
"homepage": "http://laravel.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"illuminate/contracts": "5.0.*",
|
||||
"illuminate/support": "5.0.*",
|
||||
"nesbot/carbon": "~1.0",
|
||||
"symfony/finder": "2.6.*",
|
||||
"symfony/http-foundation": "2.6.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Session\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.0-dev"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"illuminate/console": "Required to use the session:table command (5.0.*)."
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
Reference in New Issue
Block a user