/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/Http/Session
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/Http/Session/DatabaseSession.php (5382B)
$config The configuration for this engine. It requires the 'model'
* key to be present corresponding to the Table to use for managing the sessions.
*/
public function __construct(array $config = [])
{
if (isset($config['tableLocator'])) {
$this->setTableLocator($config['tableLocator']);
}
$tableLocator = $this->getTableLocator();
if (empty($config['model'])) {
$config = $tableLocator->exists('Sessions') ? [] : ['table' => 'sessions', 'allowFallbackClass' => true];
$this->_table = $tableLocator->get('Sessions', $config);
} else {
$this->_table = $tableLocator->get($config['model']);
}
$this->_timeout = (int)ini_get('session.gc_maxlifetime');
}
/**
* Set the timeout value for sessions.
*
* Primarily used in testing.
*
* @param int $timeout The timeout duration.
* @return $this
*/
public function setTimeout(int $timeout)
{
$this->_timeout = $timeout;
return $this;
}
/**
* Method called on open of a database session.
*
* @param string $path The path where to store/retrieve the session.
* @param string $name The session name.
* @return bool Success
*/
public function open($path, $name): bool
{
return true;
}
/**
* Method called on close of a database session.
*
* @return bool Success
*/
public function close(): bool
{
return true;
}
/**
* Method used to read from a database session.
*
* @param string $id ID that uniquely identifies session in database.
* @return string|false Session data or false if it does not exist.
*/
#[\ReturnTypeWillChange]
public function read($id)
{
/** @var string $pkField */
$pkField = $this->_table->getPrimaryKey();
$result = $this->_table
->find('all')
->select(['data'])
->where([$pkField => $id])
->disableHydration()
->first();
if (empty($result)) {
return '';
}
if (is_string($result['data'])) {
return $result['data'];
}
$session = stream_get_contents($result['data']);
if ($session === false) {
return '';
}
return $session;
}
/**
* Helper function called on write for database sessions.
*
* @param string $id ID that uniquely identifies session in database.
* @param string $data The data to be saved.
* @return bool True for successful write, false otherwise.
*/
public function write($id, $data): bool
{
if (!$id) {
return false;
}
/** @var string $pkField */
$pkField = $this->_table->getPrimaryKey();
$session = $this->_table->newEntity([
$pkField => $id,
'data' => $data,
'expires' => time() + $this->_timeout,
], ['accessibleFields' => [$pkField => true]]);
return (bool)$this->_table->save($session);
}
/**
* Method called on the destruction of a database session.
*
* @param string $id ID that uniquely identifies session in database.
* @return bool True for successful delete, false otherwise.
*/
public function destroy($id): bool
{
/** @var string $pkField */
$pkField = $this->_table->getPrimaryKey();
$this->_table->deleteAll([$pkField => $id]);
return true;
}
/**
* Helper function called on gc for database sessions.
*
* @param int $maxlifetime Sessions that have not updated for the last maxlifetime seconds will be removed.
* @return int|false The number of deleted sessions on success, or false on failure.
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
return $this->_table->deleteAll(['expires <' => time()]);
}
}