mirror of
https://github.com/friendica/friendica
synced 2025-05-11 21:04:11 +02:00
Add Session Management instances (including Depenency Injection)
- Prerequesite for mocking Sessions - Reduce "App" class complexity
This commit is contained in:
parent
009a8bb939
commit
555513e4b4
10 changed files with 408 additions and 143 deletions
84
src/Core/Session/MemorySession.php
Normal file
84
src/Core/Session/MemorySession.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Core\Session;
|
||||
|
||||
/**
|
||||
* Native Session functions for internal Session usage.
|
||||
*
|
||||
* Usable for backend processes (daemon/worker) and testing
|
||||
*/
|
||||
final class MemorySession implements ISession
|
||||
{
|
||||
private $data = [];
|
||||
|
||||
public function start()
|
||||
{
|
||||
$this->clear();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function exists(string $name)
|
||||
{
|
||||
return isset($this->data[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(string $name, $defaults = null)
|
||||
{
|
||||
return $this->data[$name] ?? $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function set(string $name, $value)
|
||||
{
|
||||
$this->data[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setMultiple(array $values)
|
||||
{
|
||||
foreach ($values as $key => $value) {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function remove(string $name)
|
||||
{
|
||||
if ($this->exists($name)) {
|
||||
unset($this->data[$name]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->data = [];
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->data = [];
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue