mirror of
https://github.com/filegator/filegator.git
synced 2025-08-20 09:11:45 +02:00
initial commit
This commit is contained in:
74
backend/Services/Session/Adapters/SessionStorage.php
Normal file
74
backend/Services/Session/Adapters/SessionStorage.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Services\Session\Adapters;
|
||||
|
||||
use Filegator\Kernel\Request;
|
||||
use Filegator\Services\Service;
|
||||
use Filegator\Services\Session\Session;
|
||||
use Filegator\Services\Session\SessionStorageInterface;
|
||||
|
||||
class SessionStorage implements Service, SessionStorageInterface
|
||||
{
|
||||
protected $request;
|
||||
|
||||
protected $config;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function init(array $config = [])
|
||||
{
|
||||
// we don't have a previous session attached
|
||||
if (! $this->getSession()) {
|
||||
$handler = $config['available'][$config['session_handler']];
|
||||
$session = new Session($handler());
|
||||
$session->setName('filegator');
|
||||
|
||||
$this->setSession($session);
|
||||
}
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->getSession()->save();
|
||||
}
|
||||
|
||||
public function set(string $key, $data)
|
||||
{
|
||||
return $this->getSession()->set($key, $data);
|
||||
}
|
||||
|
||||
public function get(string $key, $default = null)
|
||||
{
|
||||
return $this->getSession() ? $this->getSession()->get($key, $default) : $default;
|
||||
}
|
||||
|
||||
public function invalidate()
|
||||
{
|
||||
if (! $this->getSession()->isStarted()) {
|
||||
$this->getSession()->start();
|
||||
}
|
||||
|
||||
$this->getSession()->invalidate();
|
||||
}
|
||||
|
||||
private function setSession(Session $session)
|
||||
{
|
||||
return $this->request->setSession($session);
|
||||
}
|
||||
|
||||
private function getSession(): ?Session
|
||||
{
|
||||
return $this->request->getSession();
|
||||
}
|
||||
}
|
17
backend/Services/Session/Session.php
Normal file
17
backend/Services/Session/Session.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Services\Session;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
|
||||
|
||||
class Session extends SymfonySession
|
||||
{
|
||||
}
|
22
backend/Services/Session/SessionStorageInterface.php
Normal file
22
backend/Services/Session/SessionStorageInterface.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Services\Session;
|
||||
|
||||
interface SessionStorageInterface
|
||||
{
|
||||
public function set(string $key, $data);
|
||||
|
||||
public function get(string $key, $default = null);
|
||||
|
||||
public function invalidate();
|
||||
|
||||
public function save();
|
||||
}
|
Reference in New Issue
Block a user