refactor: New Session class

So that session is shared between classes and does not get overwritten
This commit is contained in:
Pierre Rudloff 2019-04-22 17:00:51 +02:00
parent 25f33bba56
commit 1387d836dc
5 changed files with 48 additions and 18 deletions

View file

@ -6,7 +6,6 @@
namespace Alltube;
use Aura\Session\Segment;
use Aura\Session\SessionFactory;
use Symfony\Component\Process\Process;
/**
@ -37,13 +36,10 @@ class LocaleManager
/**
* LocaleManager constructor.
*
* @param array $cookies Cookie array
*/
public function __construct(array $cookies = [])
public function __construct()
{
$session_factory = new SessionFactory();
$session = $session_factory->newInstance($cookies);
$session = SessionManager::getSession();
$this->sessionSegment = $session->getSegment(self::class);
$cookieLocale = $this->sessionSegment->get('locale');
if (isset($cookieLocale)) {

View file

@ -0,0 +1,37 @@
<?php
/**
* SessionManager class.
*/
namespace Alltube;
use Aura\Session\Session;
use Aura\Session\SessionFactory;
/**
* Manage sessions.
*/
class SessionManager
{
/**
* Current session.
*
* @var Session
*/
private static $session;
/**
* Get the current session.
*
* @return Session
*/
public static function getSession()
{
if (!isset(self::$session)) {
$session_factory = new SessionFactory();
self::$session = $session_factory->newInstance($_COOKIE);
}
return self::$session;
}
}