Skip to content

Commit

Permalink
Session code cleanup, add changelog entries
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed May 17, 2018
1 parent e8fd540 commit 00376d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Added new `Grav\Framework\File\Formatter` classes for encoding/decoding YAML, Markdown, JSON, INI and PHP serialized strings
* Added `Grav\Common\Media` interfaces and trait; use those in `Page` and `Media` classes
* Added `Grav\Common\Page` interface to allow custom page types in the future
* Added `Grav\Framework\Session` class to replace `RocketTheme\Toolbox\Session\Session`
1. [](#improved)
* Improved session handling, allow all session configuration options in `system.session.options`
1. [](#bugfix)
* Fixed bug in `ContentBlock` serialization
* Fixed `Route::withQueryParam()` to accept array values
Expand Down
11 changes: 6 additions & 5 deletions system/src/Grav/Framework/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Session implements \IteratorAggregate
*/
public static function instance()
{
if (!isset(self::$instance)) {
if (null === self::$instance) {
throw new \RuntimeException("Session hasn't been initialized.", 500);
}

Expand All @@ -46,14 +46,14 @@ public static function instance()
public function __construct(array $options = [])
{
// Session is a singleton.
if (php_sapi_name() === 'cli') {
if (\PHP_SAPI === 'cli') {
self::$instance = $this;

return;
}

if (isset(self::$instance)) {
throw new \RuntimeException("Session has already been initialized.", 500);
if (null !== self::$instance) {
throw new \RuntimeException('Session has already been initialized.', 500);
}

// Destroy any existing sessions started with session.auto_start
Expand Down Expand Up @@ -147,6 +147,7 @@ public function setOptions(array $options)
/**
* Starts the session storage
*
* @param bool $readonly
* @return $this
* @throws \RuntimeException
*/
Expand Down Expand Up @@ -357,7 +358,7 @@ public function started()
*/
protected function isSessionStarted()
{
return php_sapi_name() !== 'cli' ? \PHP_SESSION_ACTIVE === session_status() : false;
return \PHP_SAPI !== 'cli' ? \PHP_SESSION_ACTIVE === session_status() : false;
}

/**
Expand Down

0 comments on commit 00376d3

Please sign in to comment.