alltube/classes/Factory/SessionFactory.php
Pierre Rudloff f475fa2a47
Lint
2023-03-03 00:18:00 +01:00

41 lines
883 B
PHP

<?php
/**
* SessionFactory class.
*/
namespace Alltube\Factory;
use Aura\Session\Session;
use Aura\Session\SessionFactory as AuraSessionFactory;
use Slim\Container;
/**
* Manage sessions.
*/
class SessionFactory
{
/**
* Get the current session.
*
* @param Container $container
* @return Session
*/
public static function create(Container $container): Session
{
$session_factory = new AuraSessionFactory();
$session = $session_factory->newInstance($_COOKIE);
$session->setCookieParams(['httponly' => true]);
$request = $container->get('request');
if (
in_array('https', $request->getHeader('X-Forwarded-Proto'))
|| $request->getUri()->getScheme() == 'https'
) {
$session->setCookieParams(['secure' => true]);
}
return $session;
}
}