Upgrade to 3.3.0

This commit is contained in:
Bastian Allgeier
2019-11-05 09:35:58 +01:00
parent 447a9dd266
commit a431716732
186 changed files with 3068 additions and 1458 deletions

View File

@@ -21,19 +21,13 @@ class AutoSession
/**
* Creates a new AutoSession instance
*
* @param \Kirby\Session\SessionStore|string $store SessionStore object or a path to the storage directory (uses the FileSessionStore)
* @param array $options Optional additional options:
* - `durationNormal`: Duration of normal sessions in seconds
* Defaults to 2 hours
* - `durationLong`: Duration of "remember me" sessions in seconds
* Defaults to 2 weeks
* - `timeout`: Activity timeout in seconds (integer or false for none)
* *Only* used for normal sessions
* Defaults to `1800` (half an hour)
* - `cookieName`: Name to use for the session cookie
* Defaults to `kirby_session`
* - `gcInterval`: How often should the garbage collector be run?
* Integer or `false` for never; defaults to `100`
* @param \Kirby\Session\SessionStore|string $store SessionStore object or a path to the storage directory (uses the FileSessionStore)
* @param array $options Optional additional options:
* - `durationNormal`: Duration of normal sessions in seconds; defaults to 2 hours
* - `durationLong`: Duration of "remember me" sessions in seconds; defaults to 2 weeks
* - `timeout`: Activity timeout in seconds (integer or false for none); *only* used for normal sessions; defaults to `1800` (half an hour)
* - `cookieName`: Name to use for the session cookie; defaults to `kirby_session`
* - `gcInterval`: How often should the garbage collector be run?; integer or `false` for never; defaults to `100`
*/
public function __construct($store, array $options = [])
{
@@ -56,15 +50,10 @@ class AutoSession
/**
* Returns the automatic session
*
* @param array $options Optional additional options:
* - `detect`: Whether to allow sessions in the `Authorization` HTTP header (`true`)
* or only in the session cookie (`false`)
* Defaults to `false`
* - `createMode`: When creating a new session, should it be set as a cookie or is it going
* to be transmitted manually to be used in a header?
* Defaults to `cookie`
* - `long`: Whether the session is a long "remember me" session or a normal session
* Defaults to `false`
* @param array $options Optional additional options:
* - `detect`: Whether to allow sessions in the `Authorization` HTTP header (`true`) or only in the session cookie (`false`); defaults to `false`
* - `createMode`: When creating a new session, should it be set as a cookie or is it going to be transmitted manually to be used in a header?; defaults to `cookie`
* - `long`: Whether the session is a long "remember me" session or a normal session; defaults to `false`
* @return \Kirby\Session\Session
*/
public function get(array $options = [])
@@ -139,15 +128,11 @@ class AutoSession
* Useful for custom applications like a password reset link
* Does *not* affect the automatic session
*
* @param array $options Optional additional options:
* - `startTime`: Time the session starts being valid (date string or timestamp)
* Defaults to `now`
* - `expiryTime`: Time the session expires (date string or timestamp)
* Defaults to `+ 2 hours`
* - `timeout`: Activity timeout in seconds (integer or false for none)
* Defaults to `1800` (half an hour)
* - `renewable`: Should it be possible to extend the expiry date?
* Defaults to `true`
* @param array $options Optional additional options:
* - `startTime`: Time the session starts being valid (date string or timestamp); defaults to `now`
* - `expiryTime`: Time the session expires (date string or timestamp); defaults to `+ 2 hours`
* - `timeout`: Activity timeout in seconds (integer or false for none); defaults to `1800` (half an hour)
* - `renewable`: Should it be possible to extend the expiry date?; defaults to `true`
* @return \Kirby\Session\Session
*/
public function createManually(array $options = [])

View File

@@ -55,8 +55,8 @@ class FileSessionStore extends SessionStore
* Needs to make sure that the session does not already exist
* and needs to reserve it by locking it exclusively.
*
* @param int $expiryTime Timestamp
* @return string Randomly generated session ID (without timestamp)
* @param int $expiryTime Timestamp
* @return string Randomly generated session ID (without timestamp)
*/
public function createId(int $expiryTime): string
{
@@ -89,10 +89,10 @@ class FileSessionStore extends SessionStore
/**
* Checks if the given session exists
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return boolean true: session exists,
* false: session doesn't exist
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return bool true: session exists,
* false: session doesn't exist
*/
public function exists(int $expiryTime, string $id): bool
{
@@ -108,8 +108,8 @@ class FileSessionStore extends SessionStore
*
* Needs to throw an Exception on error.
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return void
*/
public function lock(int $expiryTime, string $id)
@@ -146,8 +146,8 @@ class FileSessionStore extends SessionStore
*
* Needs to throw an Exception on error.
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return void
*/
public function unlock(int $expiryTime, string $id)
@@ -187,8 +187,8 @@ class FileSessionStore extends SessionStore
*
* Needs to throw an Exception on error.
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return string
*/
public function get(int $expiryTime, string $id): string
@@ -250,9 +250,9 @@ class FileSessionStore extends SessionStore
* Needs to make sure that the session exists.
* Needs to throw an Exception on error.
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param string $data Session data to write
* @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)
@@ -303,8 +303,8 @@ class FileSessionStore extends SessionStore
*
* Needs to throw an Exception on error.
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return void
*/
public function destroy(int $expiryTime, string $id)
@@ -392,8 +392,8 @@ class FileSessionStore extends SessionStore
/**
* Returns the combined name based on expiry time and ID
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return string
*/
protected function name(int $expiryTime, string $id): string
@@ -404,7 +404,7 @@ class FileSessionStore extends SessionStore
/**
* Returns the full path to the session file
*
* @param string $name Combined name
* @param string $name Combined name
* @return string
*/
protected function path(string $name): string
@@ -415,8 +415,8 @@ class FileSessionStore extends SessionStore
/**
* Returns a PHP file handle for a session
*
* @param string $name Combined name
* @return resource File handle
* @param string $name Combined name
* @return resource File handle
*/
protected function handle(string $name)
{
@@ -457,7 +457,7 @@ class FileSessionStore extends SessionStore
/**
* Closes an open file handle
*
* @param string $name Combined name
* @param string $name Combined name
* @return void
*/
protected function closeHandle(string $name)

View File

@@ -49,19 +49,14 @@ class Session
/**
* Creates a new Session instance
*
* @param \Kirby\Session\Sessions $sessions Parent sessions object
* @param string|null $token Session token or null for a new session
* @param array $options Optional additional options:
* - `mode`: Token transmission mode (cookie or manual)
* Defaults to `cookie`
* - `startTime`: Time the session starts being valid (date string or timestamp)
* Defaults to `now`
* - `expiryTime`: Time the session expires (date string or timestamp)
* Defaults to `+ 2 hours`
* - `timeout`: Activity timeout in seconds (integer or false for none)
* Defaults to `1800` (half an hour)
* - `renewable`: Should it be possible to extend the expiry date?
* Defaults to `true`
* @param \Kirby\Session\Sessions $sessions Parent sessions object
* @param string|null $token Session token or null for a new session
* @param array $options Optional additional options:
* - `mode`: Token transmission mode (cookie or manual); defaults to `cookie`
* - `startTime`: Time the session starts being valid (date string or timestamp); defaults to `now`
* - `expiryTime`: Time the session expires (date string or timestamp); defaults to `+ 2 hours`
* - `timeout`: Activity timeout in seconds (integer or false for none); defaults to `1800` (half an hour)
* - `renewable`: Should it be possible to extend the expiry date?; defaults to `true`
*/
public function __construct(Sessions $sessions, $token, array $options)
{
@@ -156,8 +151,8 @@ class Session
* Gets or sets the transmission mode
* Setting only works for new sessions that haven't been transmitted yet
*
* @param string $mode Optional new transmission mode
* @return string Transmission mode
* @param string $mode Optional new transmission mode
* @return string Transmission mode
*/
public function mode(string $mode = null)
{
@@ -180,7 +175,7 @@ class Session
/**
* Gets the session start time
*
* @return integer Timestamp
* @return int Timestamp
*/
public function startTime(): int
{
@@ -191,8 +186,8 @@ class Session
* Gets or sets the session expiry time
* Setting the expiry time also updates the duration and regenerates the session token
*
* @param string|integer $expiryTime Optional new expiry timestamp or time string to set
* @return integer Timestamp
* @param string|int $expiryTime Optional new expiry timestamp or time string to set
* @return int Timestamp
*/
public function expiryTime($expiryTime = null): int
{
@@ -226,8 +221,8 @@ class Session
* Gets or sets the session duration
* Setting the duration also updates the expiry time and regenerates the session token
*
* @param integer $duration Optional new duration in seconds to set
* @return integer Number of seconds
* @param int $duration Optional new duration in seconds to set
* @return int Number of seconds
*/
public function duration(int $duration = null): int
{
@@ -252,8 +247,8 @@ class Session
/**
* Gets or sets the session timeout
*
* @param integer|false $timeout Optional new timeout to set or false to disable timeout
* @return integer|false Number of seconds or false for "no timeout"
* @param int|false $timeout Optional new timeout to set or false to disable timeout
* @return int|false Number of seconds or false for "no timeout"
*/
public function timeout($timeout = null)
{
@@ -288,8 +283,8 @@ class Session
* Gets or sets the renewable flag
* Automatically renews the session if renewing gets enabled
*
* @param boolean $renewable Optional new renewable flag to set
* @return boolean
* @param bool $renewable Optional new renewable flag to set
* @return bool
*/
public function renewable(bool $renewable = null): bool
{
@@ -315,8 +310,8 @@ class Session
/**
* Magic call method that proxies all calls to session data methods
*
* @param string $name Method name (one of set, increment, decrement, get, pull, remove, clear)
* @param array $arguments Method arguments
* @param string $name Method name (one of set, increment, decrement, get, pull, remove, clear)
* @param array $arguments Method arguments
* @return mixed
*/
public function __call(string $name, array $arguments)
@@ -478,7 +473,7 @@ class Session
* Returns whether the session token needs to be retransmitted to the client
* Only relevant in header and manual modes
*
* @return boolean
* @return bool
*/
public function needsRetransmission(): bool
{
@@ -542,8 +537,8 @@ class Session
/**
* Parses a token string into its parts and sets them as instance vars
*
* @param string $token Session token
* @param bool $withoutKey If true, $token is passed without key
* @param string $token Session token
* @param bool $withoutKey If true, $token is passed without key
* @return void
*/
protected function parseToken(string $token, bool $withoutKey = false)
@@ -584,9 +579,9 @@ class Session
/**
* Makes sure that the given value is a valid timestamp
*
* @param string|integer $time Timestamp or date string (must be supported by `strtotime()`)
* @param integer $now Timestamp to use as a base for the calculation of relative dates
* @return integer Timestamp value
* @param string|int $time Timestamp or date string (must be supported by `strtotime()`)
* @param int $now Timestamp to use as a base for the calculation of relative dates
* @return int Timestamp value
*/
protected static function timeToTimestamp($time, int $now = null): int
{
@@ -762,7 +757,7 @@ class Session
* Checks if the session can be renewed and if the last renewal
* was more than half a session duration ago
*
* @return boolean
* @return bool
*/
protected function needsRenewal(): bool
{

View File

@@ -37,8 +37,8 @@ class SessionData
/**
* Sets one or multiple session values by key
*
* @param string|array $key The key to define or a key-value array with multiple values
* @param mixed $value The value for the passed key (only if one $key is passed)
* @param string|array $key The key to define or a key-value array with multiple values
* @param mixed $value The value for the passed key (only if one $key is passed)
* @return void
*/
public function set($key, $value = null)
@@ -61,9 +61,9 @@ class SessionData
/**
* Increments one or multiple session values by a specified amount
*
* @param string|array $key The key to increment or an array with multiple keys
* @param integer $by Increment by which amount?
* @param integer $max Maximum amount (value is not incremented further)
* @param string|array $key The key to increment or an array with multiple keys
* @param int $by Increment by which amount?
* @param int $max Maximum amount (value is not incremented further)
* @return void
*/
public function increment($key, int $by = 1, $max = null)
@@ -115,9 +115,9 @@ class SessionData
/**
* Decrements one or multiple session values by a specified amount
*
* @param string|array $key The key to decrement or an array with multiple keys
* @param integer $by Decrement by which amount?
* @param integer $min Minimum amount (value is not decremented further)
* @param string|array $key The key to decrement or an array with multiple keys
* @param int $by Decrement by which amount?
* @param int $min Minimum amount (value is not decremented further)
* @return void
*/
public function decrement($key, int $by = 1, $min = null)
@@ -169,8 +169,8 @@ class SessionData
/**
* Returns one or all session values by key
*
* @param string|null $key The key to get or null for the entire data array
* @param mixed $default Optional default value to return if the key is not defined
* @param string|null $key The key to get or null for the entire data array
* @param mixed $default Optional default value to return if the key is not defined
* @return mixed
*/
public function get($key = null, $default = null)
@@ -190,8 +190,8 @@ class SessionData
/**
* Retrieves a value and removes it afterwards
*
* @param string $key The key to get
* @param mixed $default Optional default value to return if the key is not defined
* @param string $key The key to get
* @param mixed $default Optional default value to return if the key is not defined
* @return mixed
*/
public function pull(string $key, $default = null)
@@ -208,7 +208,7 @@ class SessionData
/**
* Removes one or multiple session values by key
*
* @param string|array $key The key to remove or an array with multiple keys
* @param string|array $key The key to remove or an array with multiple keys
* @return void
*/
public function remove($key)
@@ -245,7 +245,7 @@ class SessionData
* Reloads the data array with the current session data
* Only used internally
*
* @param array $data Currently stored session data
* @param array $data Currently stored session data
* @return void
*/
public function reload(array $data)

View File

@@ -17,18 +17,18 @@ abstract class SessionStore
* Needs to make sure that the session does not already exist
* and needs to reserve it by locking it exclusively.
*
* @param int $expiryTime Timestamp
* @return string Randomly generated session ID (without timestamp)
* @param int $expiryTime Timestamp
* @return string Randomly generated session ID (without timestamp)
*/
abstract public function createId(int $expiryTime): string;
/**
* Checks if the given session exists
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return boolean true: session exists,
* false: session doesn't exist
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return bool true: session exists,
* false: session doesn't exist
*/
abstract public function exists(int $expiryTime, string $id): bool;
@@ -37,8 +37,8 @@ abstract class SessionStore
*
* Needs to throw an Exception on error.
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return void
*/
abstract public function lock(int $expiryTime, string $id);
@@ -48,8 +48,8 @@ abstract class SessionStore
*
* Needs to throw an Exception on error.
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return void
*/
abstract public function unlock(int $expiryTime, string $id);
@@ -59,8 +59,8 @@ abstract class SessionStore
*
* Needs to throw an Exception on error.
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return string
*/
abstract public function get(int $expiryTime, string $id): string;
@@ -71,9 +71,9 @@ abstract class SessionStore
* Needs to make sure that the session exists.
* Needs to throw an Exception on error.
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param string $data Session data to write
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param string $data Session data to write
* @return void
*/
abstract public function set(int $expiryTime, string $id, string $data);
@@ -83,8 +83,8 @@ abstract class SessionStore
*
* Needs to throw an Exception on error.
*
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @param int $expiryTime Timestamp
* @param string $id Session ID
* @return void
*/
abstract public function destroy(int $expiryTime, string $id);

View File

@@ -30,14 +30,11 @@ class Sessions
/**
* Creates a new Sessions instance
*
* @param \Kirby\Session\SessionStore|string $store SessionStore object or a path to the storage directory (uses the FileSessionStore)
* @param array $options Optional additional options:
* - `mode`: Default token transmission mode (cookie, header or manual)
* Defaults to `cookie`
* - `cookieName`: Name to use for the session cookie
* Defaults to `kirby_session`
* - `gcInterval`: How often should the garbage collector be run?
* Integer or `false` for never; defaults to `100`
* @param \Kirby\Session\SessionStore|string $store SessionStore object or a path to the storage directory (uses the FileSessionStore)
* @param array $options Optional additional options:
* - `mode`: Default token transmission mode (cookie, header or manual); defaults to `cookie`
* - `cookieName`: Name to use for the session cookie; defaults to `kirby_session`
* - `gcInterval`: How often should the garbage collector be run?; integer or `false` for never; defaults to `100`
*/
public function __construct($store, array $options = [])
{
@@ -93,17 +90,12 @@ class Sessions
/**
* Creates a new empty session
*
* @param array $options Optional additional options:
* - `mode`: Token transmission mode (cookie or manual)
* Defaults to default mode of the Sessions instance
* - `startTime`: Time the session starts being valid (date string or timestamp)
* Defaults to `now`
* - `expiryTime`: Time the session expires (date string or timestamp)
* Defaults to `+ 2 hours`
* - `timeout`: Activity timeout in seconds (integer or false for none)
* Defaults to `1800` (half an hour)
* - `renewable`: Should it be possible to extend the expiry date?
* Defaults to `true`
* @param array $options Optional additional options:
* - `mode`: Token transmission mode (cookie or manual); defaults to default mode of the Sessions instance
* - `startTime`: Time the session starts being valid (date string or timestamp); defaults to `now`
* - `expiryTime`: Time the session expires (date string or timestamp); defaults to `+ 2 hours`
* - `timeout`: Activity timeout in seconds (integer or false for none); defaults to `1800` (half an hour)
* - `renewable`: Should it be possible to extend the expiry date?; defaults to `true`
* @return \Kirby\Session\Session
*/
public function create(array $options = [])
@@ -119,8 +111,8 @@ class Sessions
/**
* Returns the specified Session object
*
* @param string $token Session token, either including or without the key
* @param string $mode Optional transmission mode override
* @param string $token Session token, either including or without the key
* @param string $mode Optional transmission mode override
* @return \Kirby\Session\Session
*/
public function get(string $token, string $mode = null)