refactor: New Session class
So that session is shared between classes and does not get overwritten
This commit is contained in:
parent
25f33bba56
commit
1387d836dc
5 changed files with 48 additions and 18 deletions
|
@ -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)) {
|
||||
|
|
37
classes/SessionManager.php
Normal file
37
classes/SessionManager.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue