Update to Kirby 4.7.0
This commit is contained in:
parent
02a9ab387c
commit
ba25a9a198
509 changed files with 26604 additions and 14872 deletions
|
@ -19,11 +19,11 @@ use Kirby\Toolkit\Str;
|
|||
*/
|
||||
class FileSessionStore extends SessionStore
|
||||
{
|
||||
protected $path;
|
||||
protected string $path;
|
||||
|
||||
// state of the session files
|
||||
protected $handles = [];
|
||||
protected $isLocked = [];
|
||||
protected array $handles = [];
|
||||
protected array $isLocked = [];
|
||||
|
||||
/**
|
||||
* Creates a new instance of the file session store
|
||||
|
@ -39,7 +39,7 @@ class FileSessionStore extends SessionStore
|
|||
$this->path = realpath($path);
|
||||
|
||||
// make sure it is usable for storage
|
||||
if (!is_writable($this->path)) {
|
||||
if (is_writable($this->path) === false) {
|
||||
throw new Exception([
|
||||
'key' => 'session.filestore.dirNotWritable',
|
||||
'data' => ['path' => $this->path],
|
||||
|
@ -64,8 +64,7 @@ class FileSessionStore extends SessionStore
|
|||
clearstatcache();
|
||||
do {
|
||||
// use helper from the abstract SessionStore class
|
||||
$id = static::generateId();
|
||||
|
||||
$id = static::generateId();
|
||||
$name = $this->name($expiryTime, $id);
|
||||
$path = $this->path($name);
|
||||
} while (file_exists($path));
|
||||
|
@ -111,14 +110,13 @@ class FileSessionStore extends SessionStore
|
|||
*
|
||||
* @param int $expiryTime Timestamp
|
||||
* @param string $id Session ID
|
||||
* @return void
|
||||
*/
|
||||
public function lock(int $expiryTime, string $id)
|
||||
public function lock(int $expiryTime, string $id): void
|
||||
{
|
||||
$name = $this->name($expiryTime, $id);
|
||||
|
||||
// check if the file is already locked
|
||||
if (isset($this->isLocked[$name])) {
|
||||
if (isset($this->isLocked[$name]) === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -126,19 +124,19 @@ class FileSessionStore extends SessionStore
|
|||
$handle = $this->handle($name);
|
||||
$result = flock($handle, LOCK_EX);
|
||||
|
||||
// make a note that the file is now locked
|
||||
if ($result === true) {
|
||||
$this->isLocked[$name] = true;
|
||||
} else {
|
||||
// @codeCoverageIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($result !== true) {
|
||||
throw new Exception([
|
||||
'key' => 'session.filestore.unexpectedFilesystemError',
|
||||
'fallback' => 'Unexpected file system error',
|
||||
'translate' => false,
|
||||
'httpCode' => 500
|
||||
]);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// make a note that the file is now locked
|
||||
$this->isLocked[$name] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,14 +146,13 @@ class FileSessionStore extends SessionStore
|
|||
*
|
||||
* @param int $expiryTime Timestamp
|
||||
* @param string $id Session ID
|
||||
* @return void
|
||||
*/
|
||||
public function unlock(int $expiryTime, string $id)
|
||||
public function unlock(int $expiryTime, string $id): void
|
||||
{
|
||||
$name = $this->name($expiryTime, $id);
|
||||
|
||||
// check if the file is already unlocked or doesn't exist
|
||||
if (!isset($this->isLocked[$name])) {
|
||||
if (isset($this->isLocked[$name]) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -168,19 +165,19 @@ class FileSessionStore extends SessionStore
|
|||
$handle = $this->handle($name);
|
||||
$result = flock($handle, LOCK_UN);
|
||||
|
||||
// make a note that the file is no longer locked
|
||||
if ($result === true) {
|
||||
unset($this->isLocked[$name]);
|
||||
} else {
|
||||
// @codeCoverageIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($result !== true) {
|
||||
throw new Exception([
|
||||
'key' => 'session.filestore.unexpectedFilesystemError',
|
||||
'fallback' => 'Unexpected file system error',
|
||||
'translate' => false,
|
||||
'httpCode' => 500
|
||||
]);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// make a note that the file is no longer locked
|
||||
unset($this->isLocked[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,7 +187,6 @@ class FileSessionStore extends SessionStore
|
|||
*
|
||||
* @param int $expiryTime Timestamp
|
||||
* @param string $id Session ID
|
||||
* @return string
|
||||
*/
|
||||
public function get(int $expiryTime, string $id): string
|
||||
{
|
||||
|
@ -200,7 +196,7 @@ class FileSessionStore extends SessionStore
|
|||
|
||||
// set read lock to prevent other threads from corrupting the data while we read it
|
||||
// only if we don't already have a write lock, which is even better
|
||||
if (!isset($this->isLocked[$name])) {
|
||||
if (isset($this->isLocked[$name]) === false) {
|
||||
$result = flock($handle, LOCK_SH);
|
||||
|
||||
if ($result !== true) {
|
||||
|
@ -227,7 +223,7 @@ class FileSessionStore extends SessionStore
|
|||
}
|
||||
|
||||
// remove the shared lock if we set one above
|
||||
if (!isset($this->isLocked[$name])) {
|
||||
if (isset($this->isLocked[$name]) === false) {
|
||||
$result = flock($handle, LOCK_UN);
|
||||
|
||||
if ($result !== true) {
|
||||
|
@ -254,15 +250,14 @@ class FileSessionStore extends SessionStore
|
|||
* @param int $expiryTime Timestamp
|
||||
* @param string $id Session ID
|
||||
* @param string $data Session data to write
|
||||
* @return void
|
||||
*/
|
||||
public function set(int $expiryTime, string $id, string $data)
|
||||
public function set(int $expiryTime, string $id, string $data): void
|
||||
{
|
||||
$name = $this->name($expiryTime, $id);
|
||||
$handle = $this->handle($name);
|
||||
|
||||
// validate that we have an exclusive lock already
|
||||
if (!isset($this->isLocked[$name])) {
|
||||
if (isset($this->isLocked[$name]) === false) {
|
||||
throw new LogicException([
|
||||
'key' => 'session.filestore.notLocked',
|
||||
'data' => ['name' => $name],
|
||||
|
@ -286,7 +281,7 @@ class FileSessionStore extends SessionStore
|
|||
|
||||
// write the new contents
|
||||
$result = fwrite($handle, $data);
|
||||
if (!is_int($result) || $result === 0) {
|
||||
if (is_int($result) === false || $result === 0) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new Exception([
|
||||
'key' => 'session.filestore.unexpectedFilesystemError',
|
||||
|
@ -305,9 +300,8 @@ class FileSessionStore extends SessionStore
|
|||
*
|
||||
* @param int $expiryTime Timestamp
|
||||
* @param string $id Session ID
|
||||
* @return void
|
||||
*/
|
||||
public function destroy(int $expiryTime, string $id)
|
||||
public function destroy(int $expiryTime, string $id): void
|
||||
{
|
||||
$name = $this->name($expiryTime, $id);
|
||||
$path = $this->path($name);
|
||||
|
@ -341,10 +335,8 @@ class FileSessionStore extends SessionStore
|
|||
* Deletes all expired sessions
|
||||
*
|
||||
* Needs to throw an Exception on error.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function collectGarbage()
|
||||
public function collectGarbage(): void
|
||||
{
|
||||
$iterator = new FilesystemIterator($this->path);
|
||||
|
||||
|
@ -394,7 +386,6 @@ class FileSessionStore extends SessionStore
|
|||
*
|
||||
* @param int $expiryTime Timestamp
|
||||
* @param string $id Session ID
|
||||
* @return string
|
||||
*/
|
||||
protected function name(int $expiryTime, string $id): string
|
||||
{
|
||||
|
@ -405,7 +396,6 @@ class FileSessionStore extends SessionStore
|
|||
* Returns the full path to the session file
|
||||
*
|
||||
* @param string $name Combined name
|
||||
* @return string
|
||||
*/
|
||||
protected function path(string $name): string
|
||||
{
|
||||
|
@ -424,7 +414,7 @@ class FileSessionStore extends SessionStore
|
|||
// ensures thread-safeness for recently deleted sessions, see $this->destroy()
|
||||
$path = $this->path($name);
|
||||
clearstatcache();
|
||||
if (!is_file($path)) {
|
||||
if (is_file($path) === false) {
|
||||
throw new NotFoundException([
|
||||
'key' => 'session.filestore.notFound',
|
||||
'data' => ['name' => $name],
|
||||
|
@ -435,13 +425,13 @@ class FileSessionStore extends SessionStore
|
|||
}
|
||||
|
||||
// return from cache
|
||||
if (isset($this->handles[$name])) {
|
||||
if (isset($this->handles[$name]) === true) {
|
||||
return $this->handles[$name];
|
||||
}
|
||||
|
||||
// open a new handle
|
||||
$handle = @fopen($path, 'r+b');
|
||||
if (!is_resource($handle)) {
|
||||
if (is_resource($handle) === false) {
|
||||
throw new Exception([
|
||||
'key' => 'session.filestore.notOpened',
|
||||
'data' => ['name' => $name],
|
||||
|
@ -458,11 +448,10 @@ class FileSessionStore extends SessionStore
|
|||
* Closes an open file handle
|
||||
*
|
||||
* @param string $name Combined name
|
||||
* @return void
|
||||
*/
|
||||
protected function closeHandle(string $name)
|
||||
protected function closeHandle(string $name): void
|
||||
{
|
||||
if (!isset($this->handles[$name])) {
|
||||
if (isset($this->handles[$name]) === false) {
|
||||
return;
|
||||
}
|
||||
$handle = $this->handles[$name];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue