mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-12 09:53:49 +09:00
Updates to vendors etc
This commit is contained in:
@@ -18,17 +18,16 @@ namespace Symfony\Component\HttpFoundation\Session\Attribute;
|
||||
*/
|
||||
class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Countable
|
||||
{
|
||||
private string $name = 'attributes';
|
||||
private string $storageKey;
|
||||
protected array $attributes = [];
|
||||
|
||||
protected $attributes = [];
|
||||
private string $name = 'attributes';
|
||||
|
||||
/**
|
||||
* @param string $storageKey The key used to store attributes in the session
|
||||
*/
|
||||
public function __construct(string $storageKey = '_sf2_attributes')
|
||||
{
|
||||
$this->storageKey = $storageKey;
|
||||
public function __construct(
|
||||
private string $storageKey = '_sf2_attributes',
|
||||
) {
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
@@ -36,18 +35,12 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name)
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array &$attributes)
|
||||
public function initialize(array &$attributes): void
|
||||
{
|
||||
$this->attributes = &$attributes;
|
||||
}
|
||||
@@ -67,10 +60,7 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
|
||||
return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function set(string $name, mixed $value)
|
||||
public function set(string $name, mixed $value): void
|
||||
{
|
||||
$this->attributes[$name] = $value;
|
||||
}
|
||||
@@ -80,10 +70,7 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function replace(array $attributes)
|
||||
public function replace(array $attributes): void
|
||||
{
|
||||
$this->attributes = [];
|
||||
foreach ($attributes as $key => $value) {
|
||||
|
||||
@@ -32,10 +32,8 @@ interface AttributeBagInterface extends SessionBagInterface
|
||||
|
||||
/**
|
||||
* Sets an attribute.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set(string $name, mixed $value);
|
||||
public function set(string $name, mixed $value): void;
|
||||
|
||||
/**
|
||||
* Returns attributes.
|
||||
@@ -44,10 +42,7 @@ interface AttributeBagInterface extends SessionBagInterface
|
||||
*/
|
||||
public function all(): array;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function replace(array $attributes);
|
||||
public function replace(array $attributes): void;
|
||||
|
||||
/**
|
||||
* Removes an attribute.
|
||||
|
||||
@@ -20,14 +20,13 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
{
|
||||
private string $name = 'flashes';
|
||||
private array $flashes = ['display' => [], 'new' => []];
|
||||
private string $storageKey;
|
||||
|
||||
/**
|
||||
* @param string $storageKey The key used to store flashes in the session
|
||||
*/
|
||||
public function __construct(string $storageKey = '_symfony_flashes')
|
||||
{
|
||||
$this->storageKey = $storageKey;
|
||||
public function __construct(
|
||||
private string $storageKey = '_symfony_flashes',
|
||||
) {
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
@@ -35,18 +34,12 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name)
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array &$flashes)
|
||||
public function initialize(array &$flashes): void
|
||||
{
|
||||
$this->flashes = &$flashes;
|
||||
|
||||
@@ -57,10 +50,7 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
$this->flashes['new'] = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function add(string $type, mixed $message)
|
||||
public function add(string $type, mixed $message): void
|
||||
{
|
||||
$this->flashes['new'][$type][] = $message;
|
||||
}
|
||||
@@ -99,18 +89,12 @@ class AutoExpireFlashBag implements FlashBagInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setAll(array $messages)
|
||||
public function setAll(array $messages): void
|
||||
{
|
||||
$this->flashes['new'] = $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function set(string $type, string|array $messages)
|
||||
public function set(string $type, string|array $messages): void
|
||||
{
|
||||
$this->flashes['new'][$type] = (array) $messages;
|
||||
}
|
||||
|
||||
@@ -20,14 +20,13 @@ class FlashBag implements FlashBagInterface
|
||||
{
|
||||
private string $name = 'flashes';
|
||||
private array $flashes = [];
|
||||
private string $storageKey;
|
||||
|
||||
/**
|
||||
* @param string $storageKey The key used to store flashes in the session
|
||||
*/
|
||||
public function __construct(string $storageKey = '_symfony_flashes')
|
||||
{
|
||||
$this->storageKey = $storageKey;
|
||||
public function __construct(
|
||||
private string $storageKey = '_symfony_flashes',
|
||||
) {
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
@@ -35,26 +34,17 @@ class FlashBag implements FlashBagInterface
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name)
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array &$flashes)
|
||||
public function initialize(array &$flashes): void
|
||||
{
|
||||
$this->flashes = &$flashes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function add(string $type, mixed $message)
|
||||
public function add(string $type, mixed $message): void
|
||||
{
|
||||
$this->flashes[$type][] = $message;
|
||||
}
|
||||
@@ -90,18 +80,12 @@ class FlashBag implements FlashBagInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function set(string $type, string|array $messages)
|
||||
public function set(string $type, string|array $messages): void
|
||||
{
|
||||
$this->flashes[$type] = (array) $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setAll(array $messages)
|
||||
public function setAll(array $messages): void
|
||||
{
|
||||
$this->flashes = $messages;
|
||||
}
|
||||
|
||||
@@ -22,17 +22,13 @@ interface FlashBagInterface extends SessionBagInterface
|
||||
{
|
||||
/**
|
||||
* Adds a flash message for the given type.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add(string $type, mixed $message);
|
||||
public function add(string $type, mixed $message): void;
|
||||
|
||||
/**
|
||||
* Registers one or more messages for a given type.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set(string $type, string|array $messages);
|
||||
public function set(string $type, string|array $messages): void;
|
||||
|
||||
/**
|
||||
* Gets flash messages for a given type.
|
||||
@@ -61,10 +57,8 @@ interface FlashBagInterface extends SessionBagInterface
|
||||
|
||||
/**
|
||||
* Sets all flash messages.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAll(array $messages);
|
||||
public function setAll(array $messages): void;
|
||||
|
||||
/**
|
||||
* Has flash messages for a given type?
|
||||
|
||||
@@ -32,7 +32,7 @@ class_exists(SessionBagProxy::class);
|
||||
*/
|
||||
class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Countable
|
||||
{
|
||||
protected $storage;
|
||||
protected SessionStorageInterface $storage;
|
||||
|
||||
private string $flashName;
|
||||
private string $attributeName;
|
||||
@@ -69,10 +69,7 @@ class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Cou
|
||||
return $this->getAttributeBag()->get($name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function set(string $name, mixed $value)
|
||||
public function set(string $name, mixed $value): void
|
||||
{
|
||||
$this->getAttributeBag()->set($name, $value);
|
||||
}
|
||||
@@ -82,10 +79,7 @@ class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Cou
|
||||
return $this->getAttributeBag()->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function replace(array $attributes)
|
||||
public function replace(array $attributes): void
|
||||
{
|
||||
$this->getAttributeBag()->replace($attributes);
|
||||
}
|
||||
@@ -95,10 +89,7 @@ class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Cou
|
||||
return $this->getAttributeBag()->remove($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function clear()
|
||||
public function clear(): void
|
||||
{
|
||||
$this->getAttributeBag()->clear();
|
||||
}
|
||||
@@ -143,7 +134,7 @@ class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Cou
|
||||
}
|
||||
}
|
||||
foreach ($this->data as &$data) {
|
||||
if (!empty($data)) {
|
||||
if ($data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -163,10 +154,7 @@ class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Cou
|
||||
return $this->storage->regenerate($destroy, $lifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
$this->storage->save();
|
||||
}
|
||||
@@ -176,10 +164,7 @@ class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Cou
|
||||
return $this->storage->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setId(string $id)
|
||||
public function setId(string $id): void
|
||||
{
|
||||
if ($this->storage->getId() !== $id) {
|
||||
$this->storage->setId($id);
|
||||
@@ -191,10 +176,7 @@ class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Cou
|
||||
return $this->storage->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name)
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->storage->setName($name);
|
||||
}
|
||||
@@ -209,10 +191,7 @@ class Session implements FlashBagAwareSessionInterface, \IteratorAggregate, \Cou
|
||||
return $this->storage->getMetadataBag();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function registerBag(SessionBagInterface $bag)
|
||||
public function registerBag(SessionBagInterface $bag): void
|
||||
{
|
||||
$this->storage->registerBag(new SessionBagProxy($bag, $this->data, $this->usageIndex, $this->usageReporter));
|
||||
}
|
||||
|
||||
@@ -25,10 +25,8 @@ interface SessionBagInterface
|
||||
|
||||
/**
|
||||
* Initializes the Bag.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array &$array);
|
||||
public function initialize(array &$array): void;
|
||||
|
||||
/**
|
||||
* Gets the storage key for this bag.
|
||||
|
||||
@@ -18,13 +18,16 @@ namespace Symfony\Component\HttpFoundation\Session;
|
||||
*/
|
||||
final class SessionBagProxy implements SessionBagInterface
|
||||
{
|
||||
private SessionBagInterface $bag;
|
||||
private array $data;
|
||||
private ?int $usageIndex;
|
||||
private ?\Closure $usageReporter;
|
||||
|
||||
public function __construct(SessionBagInterface $bag, array &$data, ?int &$usageIndex, ?callable $usageReporter)
|
||||
{
|
||||
public function __construct(
|
||||
private SessionBagInterface $bag,
|
||||
array &$data,
|
||||
?int &$usageIndex,
|
||||
?callable $usageReporter,
|
||||
) {
|
||||
$this->bag = $bag;
|
||||
$this->data = &$data;
|
||||
$this->usageIndex = &$usageIndex;
|
||||
|
||||
@@ -22,14 +22,13 @@ class_exists(Session::class);
|
||||
*/
|
||||
class SessionFactory implements SessionFactoryInterface
|
||||
{
|
||||
private RequestStack $requestStack;
|
||||
private SessionStorageFactoryInterface $storageFactory;
|
||||
private ?\Closure $usageReporter;
|
||||
|
||||
public function __construct(RequestStack $requestStack, SessionStorageFactoryInterface $storageFactory, ?callable $usageReporter = null)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
$this->storageFactory = $storageFactory;
|
||||
public function __construct(
|
||||
private RequestStack $requestStack,
|
||||
private SessionStorageFactoryInterface $storageFactory,
|
||||
?callable $usageReporter = null,
|
||||
) {
|
||||
$this->usageReporter = null === $usageReporter ? null : $usageReporter(...);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,10 +34,8 @@ interface SessionInterface
|
||||
|
||||
/**
|
||||
* Sets the session ID.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setId(string $id);
|
||||
public function setId(string $id): void;
|
||||
|
||||
/**
|
||||
* Returns the session name.
|
||||
@@ -46,10 +44,8 @@ interface SessionInterface
|
||||
|
||||
/**
|
||||
* Sets the session name.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name);
|
||||
public function setName(string $name): void;
|
||||
|
||||
/**
|
||||
* Invalidates the current session.
|
||||
@@ -82,10 +78,8 @@ interface SessionInterface
|
||||
* This method is generally not required for real sessions as
|
||||
* the session will be automatically saved at the end of
|
||||
* code execution.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save();
|
||||
public function save(): void;
|
||||
|
||||
/**
|
||||
* Checks if an attribute is defined.
|
||||
@@ -99,10 +93,8 @@ interface SessionInterface
|
||||
|
||||
/**
|
||||
* Sets an attribute.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set(string $name, mixed $value);
|
||||
public function set(string $name, mixed $value): void;
|
||||
|
||||
/**
|
||||
* Returns attributes.
|
||||
@@ -111,10 +103,8 @@ interface SessionInterface
|
||||
|
||||
/**
|
||||
* Sets attributes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function replace(array $attributes);
|
||||
public function replace(array $attributes): void;
|
||||
|
||||
/**
|
||||
* Removes an attribute.
|
||||
@@ -125,10 +115,8 @@ interface SessionInterface
|
||||
|
||||
/**
|
||||
* Clears all attributes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear();
|
||||
public function clear(): void;
|
||||
|
||||
/**
|
||||
* Checks if the session was started.
|
||||
@@ -137,10 +125,8 @@ interface SessionInterface
|
||||
|
||||
/**
|
||||
* Registers a SessionBagInterface with the session.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerBag(SessionBagInterface $bag);
|
||||
public function registerBag(SessionBagInterface $bag): void;
|
||||
|
||||
/**
|
||||
* Gets a bag instance by name.
|
||||
|
||||
@@ -28,8 +28,8 @@ final class SessionUtils
|
||||
public static function popSessionCookie(string $sessionName, #[\SensitiveParameter] string $sessionId): ?string
|
||||
{
|
||||
$sessionCookie = null;
|
||||
$sessionCookiePrefix = sprintf(' %s=', urlencode($sessionName));
|
||||
$sessionCookieWithId = sprintf('%s%s;', $sessionCookiePrefix, urlencode($sessionId));
|
||||
$sessionCookiePrefix = \sprintf(' %s=', urlencode($sessionName));
|
||||
$sessionCookieWithId = \sprintf('%s%s;', $sessionCookiePrefix, urlencode($sessionId));
|
||||
$otherCookies = [];
|
||||
foreach (headers_list() as $h) {
|
||||
if (0 !== stripos($h, 'Set-Cookie:')) {
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
|
||||
{
|
||||
$this->sessionName = $sessionName;
|
||||
if (!headers_sent() && !\ini_get('session.cache_limiter') && '0' !== \ini_get('session.cache_limiter')) {
|
||||
header(sprintf('Cache-Control: max-age=%d, private, must-revalidate', 60 * (int) \ini_get('session.cache_expire')));
|
||||
header(\sprintf('Cache-Control: max-age=%d, private, must-revalidate', 60 * (int) \ini_get('session.cache_expire')));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -88,7 +88,7 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
|
||||
{
|
||||
if (!headers_sent() && filter_var(\ini_get('session.use_cookies'), \FILTER_VALIDATE_BOOL)) {
|
||||
if (!isset($this->sessionName)) {
|
||||
throw new \LogicException(sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', static::class));
|
||||
throw new \LogicException(\sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', static::class));
|
||||
}
|
||||
$cookie = SessionUtils::popSessionCookie($this->sessionName, $sessionId);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class IdentityMarshaller implements MarshallerInterface
|
||||
{
|
||||
foreach ($values as $key => $value) {
|
||||
if (!\is_string($value)) {
|
||||
throw new \LogicException(sprintf('%s accepts only string as data.', __METHOD__));
|
||||
throw new \LogicException(\sprintf('%s accepts only string as data.', __METHOD__));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,10 @@ use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
||||
*/
|
||||
class MarshallingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
|
||||
{
|
||||
private AbstractSessionHandler $handler;
|
||||
private MarshallerInterface $marshaller;
|
||||
|
||||
public function __construct(AbstractSessionHandler $handler, MarshallerInterface $marshaller)
|
||||
{
|
||||
$this->handler = $handler;
|
||||
$this->marshaller = $marshaller;
|
||||
public function __construct(
|
||||
private AbstractSessionHandler $handler,
|
||||
private MarshallerInterface $marshaller,
|
||||
) {
|
||||
}
|
||||
|
||||
public function open(string $savePath, string $name): bool
|
||||
|
||||
@@ -21,8 +21,6 @@ namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
*/
|
||||
class MemcachedSessionHandler extends AbstractSessionHandler
|
||||
{
|
||||
private \Memcached $memcached;
|
||||
|
||||
/**
|
||||
* Time to live in seconds.
|
||||
*/
|
||||
@@ -42,12 +40,12 @@ class MemcachedSessionHandler extends AbstractSessionHandler
|
||||
*
|
||||
* @throws \InvalidArgumentException When unsupported options are passed
|
||||
*/
|
||||
public function __construct(\Memcached $memcached, array $options = [])
|
||||
{
|
||||
$this->memcached = $memcached;
|
||||
|
||||
public function __construct(
|
||||
private \Memcached $memcached,
|
||||
array $options = [],
|
||||
) {
|
||||
if ($diff = array_diff(array_keys($options), ['prefix', 'expiretime', 'ttl'])) {
|
||||
throw new \InvalidArgumentException(sprintf('The following options are not supported "%s".', implode(', ', $diff)));
|
||||
throw new \InvalidArgumentException(\sprintf('The following options are not supported "%s".', implode(', ', $diff)));
|
||||
}
|
||||
|
||||
$this->ttl = $options['expiretime'] ?? $options['ttl'] ?? null;
|
||||
|
||||
@@ -34,7 +34,7 @@ class NativeFileSessionHandler extends \SessionHandler
|
||||
|
||||
if ($count = substr_count($savePath, ';')) {
|
||||
if ($count > 2) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'.', $savePath));
|
||||
throw new \InvalidArgumentException(\sprintf('Invalid argument $savePath \'%s\'.', $savePath));
|
||||
}
|
||||
|
||||
// characters after last ';' are the path
|
||||
@@ -42,7 +42,7 @@ class NativeFileSessionHandler extends \SessionHandler
|
||||
}
|
||||
|
||||
if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) {
|
||||
throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $baseDir));
|
||||
throw new \RuntimeException(\sprintf('Session Storage was not able to create directory "%s".', $baseDir));
|
||||
}
|
||||
|
||||
if ($savePath !== \ini_get('session.save_path')) {
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
use Doctrine\DBAL\Schema\Name\Identifier;
|
||||
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
|
||||
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
|
||||
@@ -155,7 +158,7 @@ class PdoSessionHandler extends AbstractSessionHandler
|
||||
{
|
||||
if ($pdoOrDsn instanceof \PDO) {
|
||||
if (\PDO::ERRMODE_EXCEPTION !== $pdoOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
|
||||
throw new \InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __CLASS__));
|
||||
throw new \InvalidArgumentException(\sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __CLASS__));
|
||||
}
|
||||
|
||||
$this->pdo = $pdoOrDsn;
|
||||
@@ -222,9 +225,15 @@ class PdoSessionHandler extends AbstractSessionHandler
|
||||
$table->addColumn($this->timeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
|
||||
break;
|
||||
default:
|
||||
throw new \DomainException(sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver));
|
||||
throw new \DomainException(\sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver));
|
||||
}
|
||||
$table->setPrimaryKey([$this->idCol]);
|
||||
|
||||
if (class_exists(PrimaryKeyConstraint::class)) {
|
||||
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted($this->idCol))], true));
|
||||
} else {
|
||||
$table->setPrimaryKey([$this->idCol]);
|
||||
}
|
||||
|
||||
$table->addIndex([$this->lifetimeCol], $this->lifetimeCol.'_idx');
|
||||
}
|
||||
|
||||
@@ -236,12 +245,10 @@ class PdoSessionHandler extends AbstractSessionHandler
|
||||
* saved in a BLOB. One could also use a shorter inlined varbinary column
|
||||
* if one was sure the data fits into it.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \PDOException When the table already exists
|
||||
* @throws \DomainException When an unsupported PDO driver is used
|
||||
*/
|
||||
public function createTable()
|
||||
public function createTable(): void
|
||||
{
|
||||
// connect if we are not yet
|
||||
$this->getConnection();
|
||||
@@ -257,7 +264,7 @@ class PdoSessionHandler extends AbstractSessionHandler
|
||||
'pgsql' => "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol BYTEA NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)",
|
||||
'oci' => "CREATE TABLE $this->table ($this->idCol VARCHAR2(128) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)",
|
||||
'sqlsrv' => "CREATE TABLE $this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY, $this->dataCol VARBINARY(MAX) NOT NULL, $this->lifetimeCol INTEGER NOT NULL, $this->timeCol INTEGER NOT NULL)",
|
||||
default => throw new \DomainException(sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver)),
|
||||
default => throw new \DomainException(\sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver)),
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -538,7 +545,7 @@ class PdoSessionHandler extends AbstractSessionHandler
|
||||
return $dsn;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('The scheme "%s" is not supported by the PdoSessionHandler URL configuration. Pass a PDO DSN directly.', $params['scheme']));
|
||||
throw new \InvalidArgumentException(\sprintf('The scheme "%s" is not supported by the PdoSessionHandler URL configuration. Pass a PDO DSN directly.', $params['scheme']));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,7 +741,7 @@ class PdoSessionHandler extends AbstractSessionHandler
|
||||
case 'sqlite':
|
||||
throw new \DomainException('SQLite does not support advisory locks.');
|
||||
default:
|
||||
throw new \DomainException(sprintf('Advisory locks are currently not implemented for PDO driver "%s".', $this->driver));
|
||||
throw new \DomainException(\sprintf('Advisory locks are currently not implemented for PDO driver "%s".', $this->driver));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -776,7 +783,7 @@ class PdoSessionHandler extends AbstractSessionHandler
|
||||
// we already locked when starting transaction
|
||||
break;
|
||||
default:
|
||||
throw new \DomainException(sprintf('Transactional locks are currently not implemented for PDO driver "%s".', $this->driver));
|
||||
throw new \DomainException(\sprintf('Transactional locks are currently not implemented for PDO driver "%s".', $this->driver));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class RedisSessionHandler extends AbstractSessionHandler
|
||||
array $options = [],
|
||||
) {
|
||||
if ($diff = array_diff(array_keys($options), ['prefix', 'ttl'])) {
|
||||
throw new \InvalidArgumentException(sprintf('The following options are not supported "%s".', implode(', ', $diff)));
|
||||
throw new \InvalidArgumentException(\sprintf('The following options are not supported "%s".', implode(', ', $diff)));
|
||||
}
|
||||
|
||||
$this->prefix = $options['prefix'] ?? 'sf_s';
|
||||
|
||||
@@ -49,7 +49,7 @@ class SessionHandlerFactory
|
||||
return new PdoSessionHandler($connection);
|
||||
|
||||
case !\is_string($connection):
|
||||
throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', get_debug_type($connection)));
|
||||
throw new \InvalidArgumentException(\sprintf('Unsupported Connection: "%s".', get_debug_type($connection)));
|
||||
case str_starts_with($connection, 'file://'):
|
||||
$savePath = substr($connection, 7);
|
||||
|
||||
@@ -57,6 +57,8 @@ class SessionHandlerFactory
|
||||
|
||||
case str_starts_with($connection, 'redis:'):
|
||||
case str_starts_with($connection, 'rediss:'):
|
||||
case str_starts_with($connection, 'valkey:'):
|
||||
case str_starts_with($connection, 'valkeys:'):
|
||||
case str_starts_with($connection, 'memcached:'):
|
||||
if (!class_exists(AbstractAdapter::class)) {
|
||||
throw new \InvalidArgumentException('Unsupported Redis or Memcached DSN. Try running "composer require symfony/cache".');
|
||||
@@ -71,15 +73,11 @@ class SessionHandlerFactory
|
||||
throw new \InvalidArgumentException('Unsupported PDO OCI DSN. Try running "composer require doctrine/dbal".');
|
||||
}
|
||||
$connection[3] = '-';
|
||||
$params = class_exists(DsnParser::class) ? (new DsnParser())->parse($connection) : ['url' => $connection];
|
||||
$params = (new DsnParser())->parse($connection);
|
||||
$config = new Configuration();
|
||||
if (class_exists(DefaultSchemaManagerFactory::class)) {
|
||||
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
|
||||
}
|
||||
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
|
||||
|
||||
$connection = DriverManager::getConnection($params, $config);
|
||||
// The condition should be removed once support for DBAL <3.3 is dropped
|
||||
$connection = method_exists($connection, 'getNativeConnection') ? $connection->getNativeConnection() : $connection->getWrappedConnection();
|
||||
$connection = DriverManager::getConnection($params, $config)->getNativeConnection();
|
||||
// no break;
|
||||
|
||||
case str_starts_with($connection, 'mssql://'):
|
||||
@@ -94,6 +92,6 @@ class SessionHandlerFactory
|
||||
return new PdoSessionHandler($connection, $options);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection));
|
||||
throw new \InvalidArgumentException(\sprintf('Unsupported Connection: "%s".', $connection));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,14 @@ namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
*/
|
||||
class StrictSessionHandler extends AbstractSessionHandler
|
||||
{
|
||||
private \SessionHandlerInterface $handler;
|
||||
private bool $doDestroy;
|
||||
|
||||
public function __construct(\SessionHandlerInterface $handler)
|
||||
{
|
||||
public function __construct(
|
||||
private \SessionHandlerInterface $handler,
|
||||
) {
|
||||
if ($handler instanceof \SessionUpdateTimestampHandlerInterface) {
|
||||
throw new \LogicException(sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".', get_debug_type($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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,35 +26,22 @@ class MetadataBag implements SessionBagInterface
|
||||
public const UPDATED = 'u';
|
||||
public const LIFETIME = 'l';
|
||||
|
||||
protected array $meta = [self::CREATED => 0, self::UPDATED => 0, self::LIFETIME => 0];
|
||||
|
||||
private string $name = '__metadata';
|
||||
private string $storageKey;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $meta = [self::CREATED => 0, self::UPDATED => 0, self::LIFETIME => 0];
|
||||
|
||||
/**
|
||||
* Unix timestamp.
|
||||
*/
|
||||
private int $lastUsed;
|
||||
|
||||
private int $updateThreshold;
|
||||
|
||||
/**
|
||||
* @param string $storageKey The key used to store bag in the session
|
||||
* @param int $updateThreshold The time to wait between two UPDATED updates
|
||||
*/
|
||||
public function __construct(string $storageKey = '_sf2_meta', int $updateThreshold = 0)
|
||||
{
|
||||
$this->storageKey = $storageKey;
|
||||
$this->updateThreshold = $updateThreshold;
|
||||
public function __construct(
|
||||
private string $storageKey = '_sf2_meta',
|
||||
private int $updateThreshold = 0,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array &$array)
|
||||
public function initialize(array &$array): void
|
||||
{
|
||||
$this->meta = &$array;
|
||||
|
||||
@@ -85,10 +72,8 @@ class MetadataBag implements SessionBagInterface
|
||||
* will leave the system settings unchanged, 0 sets the cookie
|
||||
* to expire with browser session. Time is in seconds, and is
|
||||
* not a Unix timestamp.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function stampNew(?int $lifetime = null)
|
||||
public function stampNew(?int $lifetime = null): void
|
||||
{
|
||||
$this->stampCreated($lifetime);
|
||||
}
|
||||
@@ -131,10 +116,8 @@ class MetadataBag implements SessionBagInterface
|
||||
|
||||
/**
|
||||
* Sets name.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name)
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
@@ -27,51 +27,25 @@ use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
|
||||
*/
|
||||
class MockArraySessionStorage implements SessionStorageInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $id = '';
|
||||
protected string $id = '';
|
||||
protected bool $started = false;
|
||||
protected bool $closed = false;
|
||||
protected array $data = [];
|
||||
protected MetadataBag $metadataBag;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var SessionBagInterface[]
|
||||
*/
|
||||
protected $name;
|
||||
protected array $bags = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $started = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $closed = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* @var MetadataBag
|
||||
*/
|
||||
protected $metadataBag;
|
||||
|
||||
/**
|
||||
* @var array|SessionBagInterface[]
|
||||
*/
|
||||
protected $bags = [];
|
||||
|
||||
public function __construct(string $name = 'MOCKSESSID', ?MetadataBag $metaBag = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
public function __construct(
|
||||
protected string $name = 'MOCKSESSID',
|
||||
?MetadataBag $metaBag = null,
|
||||
) {
|
||||
$this->setMetadataBag($metaBag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setSessionData(array $array)
|
||||
public function setSessionData(array $array): void
|
||||
{
|
||||
$this->data = $array;
|
||||
}
|
||||
@@ -82,7 +56,7 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
if (empty($this->id)) {
|
||||
if (!$this->id) {
|
||||
$this->id = $this->generateId();
|
||||
}
|
||||
|
||||
@@ -108,10 +82,7 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setId(string $id)
|
||||
public function setId(string $id): void
|
||||
{
|
||||
if ($this->started) {
|
||||
throw new \LogicException('Cannot set session ID after the session has started.');
|
||||
@@ -125,18 +96,12 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name)
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
if (!$this->started || $this->closed) {
|
||||
throw new \RuntimeException('Trying to save a session that was not started yet or was already closed.');
|
||||
@@ -146,10 +111,7 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
$this->started = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function clear()
|
||||
public function clear(): void
|
||||
{
|
||||
// clear out the bags
|
||||
foreach ($this->bags as $bag) {
|
||||
@@ -163,10 +125,7 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
$this->loadSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function registerBag(SessionBagInterface $bag)
|
||||
public function registerBag(SessionBagInterface $bag): void
|
||||
{
|
||||
$this->bags[$bag->getName()] = $bag;
|
||||
}
|
||||
@@ -174,7 +133,7 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
public function getBag(string $name): SessionBagInterface
|
||||
{
|
||||
if (!isset($this->bags[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('The SessionBagInterface "%s" is not registered.', $name));
|
||||
throw new \InvalidArgumentException(\sprintf('The SessionBagInterface "%s" is not registered.', $name));
|
||||
}
|
||||
|
||||
if (!$this->started) {
|
||||
@@ -189,14 +148,8 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
return $this->started;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setMetadataBag(?MetadataBag $bag = null)
|
||||
public function setMetadataBag(?MetadataBag $bag): void
|
||||
{
|
||||
if (1 > \func_num_args()) {
|
||||
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
|
||||
}
|
||||
$this->metadataBag = $bag ?? new MetadataBag();
|
||||
}
|
||||
|
||||
@@ -216,13 +169,10 @@ class MockArraySessionStorage implements SessionStorageInterface
|
||||
*/
|
||||
protected function generateId(): string
|
||||
{
|
||||
return hash('sha256', uniqid('ss_mock_', true));
|
||||
return bin2hex(random_bytes(16));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function loadSession()
|
||||
protected function loadSession(): void
|
||||
{
|
||||
$bags = array_merge($this->bags, [$this->metadataBag]);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class MockFileSessionStorage extends MockArraySessionStorage
|
||||
$savePath ??= sys_get_temp_dir();
|
||||
|
||||
if (!is_dir($savePath) && !@mkdir($savePath, 0777, true) && !is_dir($savePath)) {
|
||||
throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $savePath));
|
||||
throw new \RuntimeException(\sprintf('Session Storage was not able to create directory "%s".', $savePath));
|
||||
}
|
||||
|
||||
$this->savePath = $savePath;
|
||||
@@ -73,10 +73,7 @@ class MockFileSessionStorage extends MockArraySessionStorage
|
||||
return parent::regenerate($destroy, $lifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
if (!$this->started) {
|
||||
throw new \RuntimeException('Trying to save a session that was not started yet or was already closed.');
|
||||
|
||||
@@ -21,18 +21,14 @@ class_exists(MockFileSessionStorage::class);
|
||||
*/
|
||||
class MockFileSessionStorageFactory implements SessionStorageFactoryInterface
|
||||
{
|
||||
private ?string $savePath;
|
||||
private string $name;
|
||||
private ?MetadataBag $metaBag;
|
||||
|
||||
/**
|
||||
* @see MockFileSessionStorage constructor.
|
||||
*/
|
||||
public function __construct(?string $savePath = null, string $name = 'MOCKSESSID', ?MetadataBag $metaBag = null)
|
||||
{
|
||||
$this->savePath = $savePath;
|
||||
$this->name = $name;
|
||||
$this->metaBag = $metaBag;
|
||||
public function __construct(
|
||||
private ?string $savePath = null,
|
||||
private string $name = 'MOCKSESSID',
|
||||
private ?MetadataBag $metaBag = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public function createStorage(?Request $request): SessionStorageInterface
|
||||
|
||||
@@ -31,27 +31,11 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
/**
|
||||
* @var SessionBagInterface[]
|
||||
*/
|
||||
protected $bags = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $started = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $closed = false;
|
||||
|
||||
/**
|
||||
* @var AbstractProxy|\SessionHandlerInterface
|
||||
*/
|
||||
protected $saveHandler;
|
||||
|
||||
/**
|
||||
* @var MetadataBag
|
||||
*/
|
||||
protected $metadataBag;
|
||||
protected array $bags = [];
|
||||
protected bool $started = false;
|
||||
protected bool $closed = false;
|
||||
protected AbstractProxy|\SessionHandlerInterface $saveHandler;
|
||||
protected MetadataBag $metadataBag;
|
||||
|
||||
/**
|
||||
* Depending on how you want the storage driver to behave you probably
|
||||
@@ -78,16 +62,16 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* gc_probability, "1"
|
||||
* lazy_write, "1"
|
||||
* name, "PHPSESSID"
|
||||
* referer_check, ""
|
||||
* referer_check, "" (deprecated since Symfony 7.2, to be removed in Symfony 8.0)
|
||||
* serialize_handler, "php"
|
||||
* use_strict_mode, "1"
|
||||
* use_cookies, "1"
|
||||
* use_only_cookies, "1"
|
||||
* use_trans_sid, "0"
|
||||
* sid_length, "32"
|
||||
* sid_bits_per_character, "5"
|
||||
* trans_sid_hosts, $_SERVER['HTTP_HOST']
|
||||
* trans_sid_tags, "a=href,area=href,frame=src,form="
|
||||
* use_only_cookies, "1" (deprecated since Symfony 7.2, to be removed in Symfony 8.0)
|
||||
* use_trans_sid, "0" (deprecated since Symfony 7.2, to be removed in Symfony 8.0)
|
||||
* sid_length, "32" (@deprecated since Symfony 7.2, to be removed in 8.0)
|
||||
* sid_bits_per_character, "5" (@deprecated since Symfony 7.2, to be removed in 8.0)
|
||||
* trans_sid_hosts, $_SERVER['HTTP_HOST'] (deprecated since Symfony 7.2, to be removed in Symfony 8.0)
|
||||
* trans_sid_tags, "a=href,area=href,frame=src,form=" (deprecated since Symfony 7.2, to be removed in Symfony 8.0)
|
||||
*/
|
||||
public function __construct(array $options = [], AbstractProxy|\SessionHandlerInterface|null $handler = null, ?MetadataBag $metaBag = null)
|
||||
{
|
||||
@@ -129,7 +113,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
}
|
||||
|
||||
if (filter_var(\ini_get('session.use_cookies'), \FILTER_VALIDATE_BOOL) && headers_sent($file, $line)) {
|
||||
throw new \RuntimeException(sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line));
|
||||
throw new \RuntimeException(\sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line));
|
||||
}
|
||||
|
||||
$sessionId = $_COOKIE[session_name()] ?? null;
|
||||
@@ -142,8 +126,8 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* See https://www.php.net/manual/en/session.configuration.php#ini.session.sid-bits-per-character.
|
||||
* Allowed values are integers such as:
|
||||
* - 4 for range `a-f0-9`
|
||||
* - 5 for range `a-v0-9`
|
||||
* - 6 for range `a-zA-Z0-9,-`
|
||||
* - 5 for range `a-v0-9` (@deprecated since Symfony 7.2, it will default to 4 and the option will be ignored in Symfony 8.0)
|
||||
* - 6 for range `a-zA-Z0-9,-` (@deprecated since Symfony 7.2, it will default to 4 and the option will be ignored in Symfony 8.0)
|
||||
*
|
||||
* ---------- Part 2
|
||||
*
|
||||
@@ -155,6 +139,8 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* - The length of Windows and Linux filenames is limited to 255 bytes. Then the max must not exceed 255.
|
||||
* - The session filename prefix is `sess_`, a 5 bytes string. Then the max must not exceed 255 - 5 = 250.
|
||||
*
|
||||
* This is @deprecated since Symfony 7.2, the sid length will default to 32 and the option will be ignored in Symfony 8.0.
|
||||
*
|
||||
* ---------- Conclusion
|
||||
*
|
||||
* The parts 1 and 2 prevent the warning below:
|
||||
@@ -183,10 +169,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
return $this->saveHandler->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setId(string $id)
|
||||
public function setId(string $id): void
|
||||
{
|
||||
$this->saveHandler->setId($id);
|
||||
}
|
||||
@@ -196,10 +179,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
return $this->saveHandler->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name)
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->saveHandler->setName($name);
|
||||
}
|
||||
@@ -228,10 +208,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
return session_regenerate_id($destroy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
// Store a copy so we can restore the bags in case the session was not left empty
|
||||
$session = $_SESSION;
|
||||
@@ -249,7 +226,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
$previousHandler = set_error_handler(function ($type, $msg, $file, $line) use (&$previousHandler) {
|
||||
if (\E_WARNING === $type && str_starts_with($msg, 'session_write_close():')) {
|
||||
$handler = $this->saveHandler instanceof SessionHandlerProxy ? $this->saveHandler->getHandler() : $this->saveHandler;
|
||||
$msg = sprintf('session_write_close(): Failed to write session data with "%s" handler', $handler::class);
|
||||
$msg = \sprintf('session_write_close(): Failed to write session data with "%s" handler', $handler::class);
|
||||
}
|
||||
|
||||
return $previousHandler ? $previousHandler($type, $msg, $file, $line) : false;
|
||||
@@ -270,10 +247,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
$this->started = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function clear()
|
||||
public function clear(): void
|
||||
{
|
||||
// clear out the bags
|
||||
foreach ($this->bags as $bag) {
|
||||
@@ -287,10 +261,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
$this->loadSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function registerBag(SessionBagInterface $bag)
|
||||
public function registerBag(SessionBagInterface $bag): void
|
||||
{
|
||||
if ($this->started) {
|
||||
throw new \LogicException('Cannot register a bag when the session is already started.');
|
||||
@@ -302,7 +273,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
public function getBag(string $name): SessionBagInterface
|
||||
{
|
||||
if (!isset($this->bags[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('The SessionBagInterface "%s" is not registered.', $name));
|
||||
throw new \InvalidArgumentException(\sprintf('The SessionBagInterface "%s" is not registered.', $name));
|
||||
}
|
||||
|
||||
if (!$this->started && $this->saveHandler->isActive()) {
|
||||
@@ -314,14 +285,8 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
return $this->bags[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setMetadataBag(?MetadataBag $metaBag = null)
|
||||
public function setMetadataBag(?MetadataBag $metaBag): void
|
||||
{
|
||||
if (1 > \func_num_args()) {
|
||||
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
|
||||
}
|
||||
$this->metadataBag = $metaBag ?? new MetadataBag();
|
||||
}
|
||||
|
||||
@@ -347,10 +312,8 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* @param array $options Session ini directives [key => value]
|
||||
*
|
||||
* @see https://php.net/session.configuration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
public function setOptions(array $options): void
|
||||
{
|
||||
if (headers_sent() || \PHP_SESSION_ACTIVE === session_status()) {
|
||||
return;
|
||||
@@ -367,6 +330,10 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
]);
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
if (\in_array($key, ['referer_check', 'use_only_cookies', 'use_trans_sid', 'trans_sid_hosts', 'trans_sid_tags', 'sid_length', 'sid_bits_per_character'], true)) {
|
||||
trigger_deprecation('symfony/http-foundation', '7.2', 'NativeSessionStorage\'s "%s" option is deprecated and will be ignored in Symfony 8.0.', $key);
|
||||
}
|
||||
|
||||
if (isset($validOptions[$key])) {
|
||||
if ('cookie_secure' === $key && 'auto' === $value) {
|
||||
continue;
|
||||
@@ -392,16 +359,10 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* @see https://php.net/sessionhandlerinterface
|
||||
* @see https://php.net/sessionhandler
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setSaveHandler(AbstractProxy|\SessionHandlerInterface|null $saveHandler = null)
|
||||
public function setSaveHandler(AbstractProxy|\SessionHandlerInterface|null $saveHandler): void
|
||||
{
|
||||
if (1 > \func_num_args()) {
|
||||
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
|
||||
}
|
||||
|
||||
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
|
||||
if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
|
||||
$saveHandler = new SessionHandlerProxy($saveHandler);
|
||||
@@ -426,10 +387,8 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
* are set to (either PHP's internal, or a custom save handler set with session_set_save_handler()).
|
||||
* PHP takes the return value from the read() handler, unserializes it
|
||||
* and populates $_SESSION with the result automatically.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function loadSession(?array &$session = null)
|
||||
protected function loadSession(?array &$session = null): void
|
||||
{
|
||||
if (null === $session) {
|
||||
$session = &$_SESSION;
|
||||
|
||||
@@ -22,20 +22,15 @@ class_exists(NativeSessionStorage::class);
|
||||
*/
|
||||
class NativeSessionStorageFactory implements SessionStorageFactoryInterface
|
||||
{
|
||||
private array $options;
|
||||
private AbstractProxy|\SessionHandlerInterface|null $handler;
|
||||
private ?MetadataBag $metaBag;
|
||||
private bool $secure;
|
||||
|
||||
/**
|
||||
* @see NativeSessionStorage constructor.
|
||||
*/
|
||||
public function __construct(array $options = [], AbstractProxy|\SessionHandlerInterface|null $handler = null, ?MetadataBag $metaBag = null, bool $secure = false)
|
||||
{
|
||||
$this->options = $options;
|
||||
$this->handler = $handler;
|
||||
$this->metaBag = $metaBag;
|
||||
$this->secure = $secure;
|
||||
public function __construct(
|
||||
private array $options = [],
|
||||
private AbstractProxy|\SessionHandlerInterface|null $handler = null,
|
||||
private ?MetadataBag $metaBag = null,
|
||||
private bool $secure = false,
|
||||
) {
|
||||
}
|
||||
|
||||
public function createStorage(?Request $request): SessionStorageInterface
|
||||
|
||||
@@ -41,10 +41,7 @@ class PhpBridgeSessionStorage extends NativeSessionStorage
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function clear()
|
||||
public function clear(): void
|
||||
{
|
||||
// clear out the bags and nothing else that may be set
|
||||
// since the purpose of this driver is to share a handler
|
||||
|
||||
@@ -22,15 +22,11 @@ class_exists(PhpBridgeSessionStorage::class);
|
||||
*/
|
||||
class PhpBridgeSessionStorageFactory implements SessionStorageFactoryInterface
|
||||
{
|
||||
private AbstractProxy|\SessionHandlerInterface|null $handler;
|
||||
private ?MetadataBag $metaBag;
|
||||
private bool $secure;
|
||||
|
||||
public function __construct(AbstractProxy|\SessionHandlerInterface|null $handler = null, ?MetadataBag $metaBag = null, bool $secure = false)
|
||||
{
|
||||
$this->handler = $handler;
|
||||
$this->metaBag = $metaBag;
|
||||
$this->secure = $secure;
|
||||
public function __construct(
|
||||
private AbstractProxy|\SessionHandlerInterface|null $handler = null,
|
||||
private ?MetadataBag $metaBag = null,
|
||||
private bool $secure = false,
|
||||
) {
|
||||
}
|
||||
|
||||
public function createStorage(?Request $request): SessionStorageInterface
|
||||
|
||||
@@ -16,17 +16,9 @@ namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
|
||||
*/
|
||||
abstract class AbstractProxy
|
||||
{
|
||||
/**
|
||||
* Flag if handler wraps an internal PHP session handler (using \SessionHandler).
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $wrapper = false;
|
||||
protected bool $wrapper = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $saveHandlerName;
|
||||
protected ?string $saveHandlerName = null;
|
||||
|
||||
/**
|
||||
* Gets the session.save_handler name.
|
||||
@@ -71,11 +63,9 @@ abstract class AbstractProxy
|
||||
/**
|
||||
* Sets the session ID.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function setId(string $id)
|
||||
public function setId(string $id): void
|
||||
{
|
||||
if ($this->isActive()) {
|
||||
throw new \LogicException('Cannot change the ID of an active session.');
|
||||
@@ -95,11 +85,9 @@ abstract class AbstractProxy
|
||||
/**
|
||||
* Sets the session name.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function setName(string $name)
|
||||
public function setName(string $name): void
|
||||
{
|
||||
if ($this->isActive()) {
|
||||
throw new \LogicException('Cannot change the name of an active session.');
|
||||
|
||||
@@ -18,11 +18,9 @@ use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandle
|
||||
*/
|
||||
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
|
||||
{
|
||||
protected $handler;
|
||||
|
||||
public function __construct(\SessionHandlerInterface $handler)
|
||||
{
|
||||
$this->handler = $handler;
|
||||
public function __construct(
|
||||
protected \SessionHandlerInterface $handler,
|
||||
) {
|
||||
$this->wrapper = $handler instanceof \SessionHandler;
|
||||
$this->saveHandlerName = $this->wrapper || ($handler instanceof StrictSessionHandler && $handler->isWrapper()) ? \ini_get('session.save_handler') : 'user';
|
||||
}
|
||||
|
||||
@@ -40,10 +40,8 @@ interface SessionStorageInterface
|
||||
|
||||
/**
|
||||
* Sets the session ID.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setId(string $id);
|
||||
public function setId(string $id): void;
|
||||
|
||||
/**
|
||||
* Returns the session name.
|
||||
@@ -52,10 +50,8 @@ interface SessionStorageInterface
|
||||
|
||||
/**
|
||||
* Sets the session name.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name);
|
||||
public function setName(string $name): void;
|
||||
|
||||
/**
|
||||
* Regenerates id that represents this storage.
|
||||
@@ -94,19 +90,15 @@ interface SessionStorageInterface
|
||||
* a real PHP session would interfere with testing, in which case
|
||||
* it should actually persist the session data if required.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \RuntimeException if the session is saved without being started, or if the session
|
||||
* is already closed
|
||||
*/
|
||||
public function save();
|
||||
public function save(): void;
|
||||
|
||||
/**
|
||||
* Clear all session data in memory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear();
|
||||
public function clear(): void;
|
||||
|
||||
/**
|
||||
* Gets a SessionBagInterface by name.
|
||||
@@ -117,10 +109,8 @@ interface SessionStorageInterface
|
||||
|
||||
/**
|
||||
* Registers a SessionBagInterface for use.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerBag(SessionBagInterface $bag);
|
||||
public function registerBag(SessionBagInterface $bag): void;
|
||||
|
||||
public function getMetadataBag(): MetadataBag;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user