MockFileSessionStorage
extends MockArraySessionStorage
in package
MockFileSessionStorage is used to mock sessions for functional testing where you may need to persist session data across separate PHP processes.
No PHP session is actually started since a session can be initialized and shutdown only once per PHP execution cycle and this class does not pollute any session related globals, including session_() functions or session. PHP ini directives.
Tags
Table of Contents
- $bags : array<string|int, mixed>|array<string|int, SessionBagInterface>
- $closed : bool
- $data : array<string|int, mixed>
- $id : string
- $metadataBag : MetadataBag
- $name : string
- $started : bool
- $savePath : mixed
- __construct() : mixed
- clear() : mixed
- Clear all session data in memory.
- getBag() : SessionBagInterface
- Gets a SessionBagInterface by name.
- getId() : string
- Returns the session ID.
- getMetadataBag() : MetadataBag
- Gets the MetadataBag.
- getName() : string
- Returns the session name.
- isStarted() : bool
- Checks if the session is started.
- regenerate() : bool
- Regenerates id that represents this storage.
- registerBag() : mixed
- Registers a SessionBagInterface for use.
- save() : mixed
- Force the session to be saved and closed.
- setId() : mixed
- Sets the session ID.
- setMetadataBag() : mixed
- setName() : mixed
- Sets the session name.
- setSessionData() : mixed
- start() : bool
- Starts the session.
- generateId() : string
- Generates a session ID.
- loadSession() : mixed
- destroy() : void
- Deletes a session from persistent storage.
- getFilePath() : string
- Calculate path to file.
- read() : void
- Reads session from storage and loads session.
Properties
$bags
protected
array<string|int, mixed>|array<string|int, SessionBagInterface>
$bags
= []
$closed
protected
bool
$closed
= false
$data
protected
array<string|int, mixed>
$data
= []
$id
protected
string
$id
= ''
$metadataBag
protected
MetadataBag
$metadataBag
$name
protected
string
$name
$started
protected
bool
$started
= false
$savePath
private
mixed
$savePath
Methods
__construct()
public
__construct([string|null $savePath = null ][, string $name = 'MOCKSESSID' ][, MetadataBag|null $metaBag = null ]) : mixed
Parameters
- $savePath : string|null = null
-
Path of directory to save session files
- $name : string = 'MOCKSESSID'
- $metaBag : MetadataBag|null = null
Return values
mixed —clear()
Clear all session data in memory.
public
clear() : mixed
Return values
mixed —getBag()
Gets a SessionBagInterface by name.
public
getBag(string $name) : SessionBagInterface
Parameters
- $name : string
Return values
SessionBagInterface —getId()
Returns the session ID.
public
getId() : string
Return values
string —getMetadataBag()
Gets the MetadataBag.
public
getMetadataBag() : MetadataBag
Return values
MetadataBag —getName()
Returns the session name.
public
getName() : string
Return values
string —isStarted()
Checks if the session is started.
public
isStarted() : bool
Return values
bool —regenerate()
Regenerates id that represents this storage.
public
regenerate([bool $destroy = false ][, int|null $lifetime = null ]) : bool
Parameters
- $destroy : bool = false
-
Destroy session when regenerating?
- $lifetime : int|null = null
-
Sets the cookie lifetime for the session cookie. A null value 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 values
bool —registerBag()
Registers a SessionBagInterface for use.
public
registerBag(SessionBagInterface $bag) : mixed
Parameters
- $bag : SessionBagInterface
Return values
mixed —save()
Force the session to be saved and closed.
public
save() : mixed
Return values
mixed —setId()
Sets the session ID.
public
setId(string $id) : mixed
Parameters
- $id : string
Return values
mixed —setMetadataBag()
public
setMetadataBag([MetadataBag|null $bag = null ]) : mixed
Parameters
- $bag : MetadataBag|null = null
Return values
mixed —setName()
Sets the session name.
public
setName(string $name) : mixed
Parameters
- $name : string
Return values
mixed —setSessionData()
public
setSessionData(array<string|int, mixed> $array) : mixed
Parameters
- $array : array<string|int, mixed>
Return values
mixed —start()
Starts the session.
public
start() : bool
Return values
bool —generateId()
Generates a session ID.
protected
generateId() : string
This doesn't need to be particularly cryptographically secure since this is just a mock.
Return values
string —loadSession()
protected
loadSession() : mixed
Return values
mixed —destroy()
Deletes a session from persistent storage.
private
destroy() : void
Deliberately leaves session data in memory intact.
Return values
void —getFilePath()
Calculate path to file.
private
getFilePath() : string
Return values
string —read()
Reads session from storage and loads session.
private
read() : void