diff --git a/library/Icinga/Web/Session.php b/library/Icinga/Web/Session.php index e6f7218ad..40df89f9e 100644 --- a/library/Icinga/Web/Session.php +++ b/library/Icinga/Web/Session.php @@ -29,7 +29,7 @@ class Session public static function create(BaseSession $session = null) { if ($session === null) { - self::$session = new PhpSession(); + self::$session = PhpSession::create(); } else { self::$session = $session; } diff --git a/library/Icinga/Web/Session/Php72Session.php b/library/Icinga/Web/Session/Php72Session.php new file mode 100644 index 000000000..e6a6b1919 --- /dev/null +++ b/library/Icinga/Web/Session/Php72Session.php @@ -0,0 +1,37 @@ +sessionName); + + $cookie = new Cookie('bogus'); + session_set_cookie_params( + 0, + $cookie->getPath(), + $cookie->getDomain(), + $cookie->isSecure(), + true + ); + + session_start(array( + 'use_cookies' => true, + 'use_only_cookies' => true, + 'use_trans_sid' => false + )); + } +} diff --git a/library/Icinga/Web/Session/PhpSession.php b/library/Icinga/Web/Session/PhpSession.php index e00544cf9..36dd84e9d 100644 --- a/library/Icinga/Web/Session/PhpSession.php +++ b/library/Icinga/Web/Session/PhpSession.php @@ -33,6 +33,21 @@ class PhpSession extends Session */ protected $sessionName = 'Icingaweb2'; + /** + * Create a new PHPSession object using the provided options (if any) + * + * @param array $options An optional array of ini options to set + * + * @return static + * + * @throws ConfigurationError + * @see http://php.net/manual/en/session.configuration.php + */ + public static function create(array $options = null) + { + return version_compare(PHP_VERSION, '7.2.0') < 0 ? new self($options) : new Php72Session($options); + } + /** * Create a new PHPSession object using the provided options (if any) * diff --git a/test/php/library/Icinga/Web/Session/PhpSessionTest.php b/test/php/library/Icinga/Web/Session/PhpSessionTest.php index d835fb034..224e98462 100644 --- a/test/php/library/Icinga/Web/Session/PhpSessionTest.php +++ b/test/php/library/Icinga/Web/Session/PhpSessionTest.php @@ -13,7 +13,7 @@ class PhpSessionTest extends BaseTestCase if (!is_writable('/tmp')) { $this->markTestSkipped('Could not write to session directory'); } - return new PhpSession( + return PhpSession::create( array( 'use_cookies' => false, 'save_path' => '/tmp',