upgrade to laravel 7 and set branch to v2

This commit is contained in:
2020-12-25 11:22:15 +00:00
parent 516105c492
commit 0ddd298350
4638 changed files with 132501 additions and 190226 deletions

View File

@@ -42,26 +42,19 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
}
/**
* @param string $sessionId
*
* @return string
*/
abstract protected function doRead($sessionId);
abstract protected function doRead(string $sessionId);
/**
* @param string $sessionId
* @param string $data
*
* @return bool
*/
abstract protected function doWrite($sessionId, $data);
abstract protected function doWrite(string $sessionId, string $data);
/**
* @param string $sessionId
*
* @return bool
*/
abstract protected function doDestroy($sessionId);
abstract protected function doDestroy(string $sessionId);
/**
* @return bool

View File

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
/**
* @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
*/
class IdentityMarshaller implements MarshallerInterface
{
/**
* {@inheritdoc}
*/
public function marshall(array $values, ?array &$failed): array
{
foreach ($values as $key => $value) {
if (!\is_string($value)) {
throw new \LogicException(sprintf('%s accepts only string as data.', __METHOD__));
}
}
return $values;
}
/**
* {@inheritdoc}
*/
public function unmarshall(string $value): string
{
return $value;
}
}

View File

@@ -0,0 +1,100 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
/**
* @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
*/
class MarshallingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
{
private $handler;
private $marshaller;
public function __construct(AbstractSessionHandler $handler, MarshallerInterface $marshaller)
{
$this->handler = $handler;
$this->marshaller = $marshaller;
}
/**
* {@inheritdoc}
*/
public function open($savePath, $name)
{
return $this->handler->open($savePath, $name);
}
/**
* {@inheritdoc}
*/
public function close()
{
return $this->handler->close();
}
/**
* {@inheritdoc}
*/
public function destroy($sessionId)
{
return $this->handler->destroy($sessionId);
}
/**
* {@inheritdoc}
*/
public function gc($maxlifetime)
{
return $this->handler->gc($maxlifetime);
}
/**
* {@inheritdoc}
*/
public function read($sessionId)
{
return $this->marshaller->unmarshall($this->handler->read($sessionId));
}
/**
* {@inheritdoc}
*/
public function write($sessionId, $data)
{
$failed = [];
$marshalledData = $this->marshaller->marshall(['data' => $data], $failed);
if (isset($failed['data'])) {
return false;
}
return $this->handler->write($sessionId, $marshalledData['data']);
}
/**
* {@inheritdoc}
*/
public function validateId($sessionId)
{
return $this->handler->validateId($sessionId);
}
/**
* {@inheritdoc}
*/
public function updateTimestamp($sessionId, $data)
{
return $this->handler->updateTimestamp($sessionId, $data);
}
}

View File

@@ -65,7 +65,7 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead($sessionId)
protected function doRead(string $sessionId)
{
return $this->memcached->get($this->prefix.$sessionId) ?: '';
}
@@ -83,7 +83,7 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite($sessionId, $data)
protected function doWrite(string $sessionId, string $data)
{
return $this->memcached->set($this->prefix.$sessionId, $data, time() + $this->ttl);
}
@@ -91,7 +91,7 @@ class MemcachedSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId)
protected function doDestroy(string $sessionId)
{
$result = $this->memcached->delete($this->prefix.$sessionId);

View File

@@ -90,7 +90,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId)
protected function doDestroy(string $sessionId)
{
$this->getCollection()->deleteOne([
$this->options['id_field'] => $sessionId,
@@ -114,7 +114,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite($sessionId, $data)
protected function doWrite(string $sessionId, string $data)
{
$expiry = new \MongoDB\BSON\UTCDateTime((time() + (int) ini_get('session.gc_maxlifetime')) * 1000);
@@ -154,7 +154,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead($sessionId)
protected function doRead(string $sessionId)
{
$dbData = $this->getCollection()->findOne([
$this->options['id_field'] => $sessionId,

View File

@@ -37,7 +37,7 @@ class NullSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead($sessionId)
protected function doRead(string $sessionId)
{
return '';
}
@@ -53,7 +53,7 @@ class NullSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite($sessionId, $data)
protected function doWrite(string $sessionId, string $data)
{
return true;
}
@@ -61,7 +61,7 @@ class NullSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId)
protected function doDestroy(string $sessionId)
{
return true;
}

View File

@@ -302,7 +302,7 @@ class PdoSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId)
protected function doDestroy(string $sessionId)
{
// delete the record associated with this id
$sql = "DELETE FROM $this->table WHERE $this->idCol = :id";
@@ -323,7 +323,7 @@ class PdoSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite($sessionId, $data)
protected function doWrite(string $sessionId, string $data)
{
$maxlifetime = (int) ini_get('session.gc_maxlifetime');
@@ -606,11 +606,9 @@ class PdoSessionHandler extends AbstractSessionHandler
* We need to make sure we do not return session data that is already considered garbage according
* to the session.gc_maxlifetime setting because gc() is called after read() and only sometimes.
*
* @param string $sessionId Session ID
*
* @return string The session data
* @return string
*/
protected function doRead($sessionId)
protected function doRead(string $sessionId)
{
if (self::LOCK_ADVISORY === $this->lockMode) {
$this->unlockStatements[] = $this->doAdvisoryLock($sessionId);

View File

@@ -54,7 +54,7 @@ class RedisSessionHandler extends AbstractSessionHandler
!$redis instanceof RedisProxy &&
!$redis instanceof RedisClusterProxy
) {
throw new \InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis)));
throw new \InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($redis)));
}
if ($diff = array_diff(array_keys($options), ['prefix', 'ttl'])) {
@@ -69,7 +69,7 @@ class RedisSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead($sessionId): string
protected function doRead(string $sessionId): string
{
return $this->redis->get($this->prefix.$sessionId) ?: '';
}
@@ -77,7 +77,7 @@ class RedisSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite($sessionId, $data): bool
protected function doWrite(string $sessionId, string $data): bool
{
$result = $this->redis->setEx($this->prefix.$sessionId, (int) ($this->ttl ?? ini_get('session.gc_maxlifetime')), $data);
@@ -87,9 +87,21 @@ class RedisSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId): bool
protected function doDestroy(string $sessionId): bool
{
$this->redis->del($this->prefix.$sessionId);
static $unlink = true;
if ($unlink) {
try {
$unlink = false !== $this->redis->unlink($this->prefix.$sessionId);
} catch (\Throwable $e) {
$unlink = false;
}
}
if (!$unlink) {
$this->redis->del($this->prefix.$sessionId);
}
return true;
}

View File

@@ -27,7 +27,7 @@ class SessionHandlerFactory
public static function createHandler($connection): AbstractSessionHandler
{
if (!\is_string($connection) && !\is_object($connection)) {
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a string or a connection object, "%s" given.', __METHOD__, \gettype($connection)));
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a string or a connection object, "%s" given.', __METHOD__, get_debug_type($connection)));
}
switch (true) {
@@ -46,7 +46,7 @@ class SessionHandlerFactory
return new PdoSessionHandler($connection);
case !\is_string($connection):
throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', \get_class($connection)));
throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', get_debug_type($connection)));
case 0 === strpos($connection, 'file://'):
return new StrictSessionHandler(new NativeFileSessionHandler(substr($connection, 7)));

View File

@@ -24,7 +24,7 @@ class StrictSessionHandler extends AbstractSessionHandler
public function __construct(\SessionHandlerInterface $handler)
{
if ($handler instanceof \SessionUpdateTimestampHandlerInterface) {
throw new \LogicException(sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".', \get_class($handler), self::class));
throw new \LogicException(sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".', get_debug_type($handler), self::class));
}
$this->handler = $handler;
@@ -43,7 +43,7 @@ class StrictSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doRead($sessionId)
protected function doRead(string $sessionId)
{
return $this->handler->read($sessionId);
}
@@ -59,7 +59,7 @@ class StrictSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doWrite($sessionId, $data)
protected function doWrite(string $sessionId, string $data)
{
return $this->handler->write($sessionId, $data);
}
@@ -78,7 +78,7 @@ class StrictSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId)
protected function doDestroy(string $sessionId)
{
$this->doDestroy = false;