Fr3nch13/CakePHP Utilities

DatabaseSession
in package
implements SessionHandlerInterface uses LocatorAwareTrait

DatabaseSession provides methods to be used with Session.

Table of Contents

Interfaces

SessionHandlerInterface

Properties

$_table  : Table
Reference to the table handling the session data
$_tableLocator  : LocatorInterface|null
Table locator instance
$_timeout  : int
Number of seconds to mark the session as expired
$defaultTable  : string|null
This object's default table alias.

Methods

__construct()  : mixed
Constructor. Looks at Session configuration information and sets up the session model.
close()  : bool
Method called on close of a database session.
destroy()  : bool
Method called on the destruction of a database session.
fetchTable()  : Table
Convenience method to get a table instance.
gc()  : int|false
Helper function called on gc for database sessions.
getTableLocator()  : LocatorInterface
Gets the table locator.
open()  : bool
Method called on open of a database session.
read()  : string|false
Method used to read from a database session.
setTableLocator()  : $this
Sets the table locator.
setTimeout()  : $this
Set the timeout value for sessions.
write()  : bool
Helper function called on write for database sessions.

Properties

$_timeout

Number of seconds to mark the session as expired

protected int $_timeout

$defaultTable

This object's default table alias.

protected string|null $defaultTable = null

Methods

__construct()

Constructor. Looks at Session configuration information and sets up the session model.

public __construct([array<string, mixed> $config = [] ]) : mixed
Parameters
$config : array<string, mixed> = []

The configuration for this engine. It requires the 'model' key to be present corresponding to the Table to use for managing the sessions.

close()

Method called on close of a database session.

public close() : bool
Return values
bool

Success

destroy()

Method called on the destruction of a database session.

public destroy(string $id) : bool
Parameters
$id : string

ID that uniquely identifies session in database.

Return values
bool

True for successful delete, false otherwise.

fetchTable()

Convenience method to get a table instance.

public fetchTable([string|null $alias = null ][, array<string, mixed> $options = [] ]) : Table
Parameters
$alias : string|null = null

The alias name you want to get. Should be in CamelCase format. If null then the value of $defaultTable property is used.

$options : array<string, mixed> = []

The options you want to build the table with. If a table has already been loaded the registry options will be ignored.

Tags
throws
CakeException

If $alias argument and $defaultTable property both are null.

see
TableLocator::get()
since
4.3.0
Return values
Table

gc()

Helper function called on gc for database sessions.

public gc(int $maxlifetime) : int|false
Parameters
$maxlifetime : int

Sessions that have not updated for the last maxlifetime seconds will be removed.

Attributes
#[ReturnTypeWillChange]
Return values
int|false

The number of deleted sessions on success, or false on failure.

open()

Method called on open of a database session.

public open(string $path, string $name) : bool
Parameters
$path : string

The path where to store/retrieve the session.

$name : string

The session name.

Return values
bool

Success

read()

Method used to read from a database session.

public read(string $id) : string|false
Parameters
$id : string

ID that uniquely identifies session in database.

Attributes
#[ReturnTypeWillChange]
Return values
string|false

Session data or false if it does not exist.

setTimeout()

Set the timeout value for sessions.

public setTimeout(int $timeout) : $this

Primarily used in testing.

Parameters
$timeout : int

The timeout duration.

Return values
$this

write()

Helper function called on write for database sessions.

public write(string $id, string $data) : bool
Parameters
$id : string

ID that uniquely identifies session in database.

$data : string

The data to be saved.

Return values
bool

True for successful write, false otherwise.


        
On this page

Search results