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