Class DatabaseSession
DatabaseSession provides methods to be used with Session.
Property Summary
- 
        $_table protected
Cake\ORM\TableReference to the table handling the session data
 - 
        $_tableLocator protected
Cake\ORM\Locator\LocatorInterface|nullTable locator instance
 - 
        $_timeout protected
intNumber of seconds to mark the session as expired
 - 
        $defaultTable protected
string|nullThis object's default table alias.
 
Method Summary
- 
          
__construct() public
Constructor. Looks at Session configuration information and sets up the session model.
 - 
          
close() public
Method called on close of a database session.
 - 
          
destroy() public
Method called on the destruction of a database session.
 - 
          
fetchTable() public
Convenience method to get a table instance.
 - 
          
gc() public
Helper function called on gc for database sessions.
 - 
          
getTableLocator() public
Gets the table locator.
 - 
          
open() public
Method called on open of a database session.
 - 
          
read() public
Method used to read from a database session.
 - 
          
setTableLocator() public
Sets the table locator.
 - 
          
setTimeout() public
Set the timeout value for sessions.
 - 
          
write() public
Helper function called on write for database sessions.
 
Method Detail
__construct() ¶ public
__construct(array<string, mixed> $config = [])
      Constructor. Looks at Session configuration information and sets up the session model.
Parameters
- 
                
array<string, mixed>$config optional The configuration for this engine. It requires the 'model' key to be present corresponding to the Table to use for managing the sessions.
destroy() ¶ public
destroy(string $id): bool
      Method called on the destruction of a database session.
Parameters
- 
                
string$id ID that uniquely identifies session in database.
Returns
boolTrue for successful delete, false otherwise.
fetchTable() ¶ public
fetchTable(class-string<T>|string|null $alias = null, array<string, mixed> $options = []): $alias is class-string<T> ? T : \Cake\ORM\Table
      Convenience method to get a table instance.
Templates
              T
               of \Cake\ORM\Table                            Parameters
- 
                
class-string<T>|string|null$alias optional The alias name you want to get. Should be in CamelCase format. If
nullthen the value of $defaultTable property is used.- 
                
array<string, mixed>$options optional The options you want to build the table with. If a table has already been loaded the registry options will be ignored.
Returns
$alias is class-string<T> ? T : \Cake\ORM\TableThrows
Cake\Core\Exception\CakeExceptionIf `$alias` argument and `$defaultTable` property both are `null`.
See Also
gc() ¶ public
gc(int $max_lifetime): int|false
      Helper function called on gc for database sessions.
Parameters
- 
                
int$max_lifetime Sessions that have not updated for the last maxlifetime seconds will be removed.
Returns
int|falseThe number of deleted sessions on success, or false on failure.
getTableLocator() ¶ public
getTableLocator(): Cake\ORM\Locator\LocatorInterface
      Gets the table locator.
Returns
Cake\ORM\Locator\LocatorInterfaceopen() ¶ public
open(string $path, string $name): bool
      Method called on open of a database session.
Parameters
- 
                
string$path The path where to store/retrieve the session.
- 
                
string$name The session name.
Returns
boolSuccess
read() ¶ public
read(string $id): string|false
      Method used to read from a database session.
Parameters
- 
                
string$id ID that uniquely identifies session in database.
Returns
string|falseSession data or false if it does not exist.
setTableLocator() ¶ public
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this
      Sets the table locator.
Parameters
- 
                
Cake\ORM\Locator\LocatorInterface$tableLocator LocatorInterface instance.
Returns
$thissetTimeout() ¶ public
setTimeout(int $timeout): $this
      Set the timeout value for sessions.
Primarily used in testing.
Parameters
- 
                
int$timeout The timeout duration.
Returns
$thiswrite() ¶ public
write(string $id, string $data): bool
      Helper function called on write for database sessions.
Parameters
- 
                
string$id ID that uniquely identifies session in database.
- 
                
string$data The data to be saved.
Returns
boolTrue for successful write, false otherwise.