Fixed session throwing error in CLI if initialized

This commit is contained in:
Matias Griese
2018-12-12 09:39:13 +02:00
parent 94a843429d
commit 2a20959660
3 changed files with 7 additions and 1 deletions

View File

@@ -26,6 +26,7 @@
* Fixed `Object` serialization breaking if overriding `jsonSerialize()` method
* Grav 1.6: Fixed `FlexObject::update()` call with partial object update
* Fixed `YamlFormatter::decode()` when calling `init_set()` with integer
* Fixed session throwing error in CLI if initialized
# v1.6.0-beta.6
## 11/12/2018

View File

@@ -31,7 +31,7 @@ class Session extends \Grav\Framework\Session\Session
*/
public function init()
{
if ($this->autoStart) {
if ($this->autoStart && !$this->isStarted()) {
$this->start();
$this->autoStart = false;

View File

@@ -175,6 +175,10 @@ class Session implements SessionInterface
*/
public function start($readonly = false)
{
if (\PHP_SAPI === 'cli') {
return $this;
}
// Protection against invalid session cookie names throwing exception: http://php.net/manual/en/function.session-id.php#116836
if (isset($_COOKIE[session_name()]) && !preg_match('/^[-,a-zA-Z0-9]{1,128}$/', $_COOKIE[session_name()])) {
unset($_COOKIE[session_name()]);
@@ -189,6 +193,7 @@ class Session implements SessionInterface
if (!$success) {
$last = error_get_last();
$error = $last ? $last['message'] : 'Unknown error';
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);die();
throw new \RuntimeException('Failed to start session: ' . $error, 500);
}