alltube/classes/Factory/SessionFactory.php

43 lines
884 B
PHP
Raw Normal View History

<?php
/**
* SessionFactory class.
*/
namespace Alltube\Factory;
use Aura\Session\Session;
2022-02-03 19:03:55 +00:00
use Aura\Session\SessionFactory as AuraSessionFactory;
use Slim\Container;
/**
* Manage sessions.
*/
class SessionFactory
{
/**
* Get the current session.
*
* @param Container $container
* @return Session
*/
2020-12-17 21:43:05 +00:00
public static function create(Container $container): Session
{
2022-02-03 19:03:55 +00:00
$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;
}
}