Skip to content

Commit fb12591

Browse files
authored
Update SessionStorage.php
Only check for session when utilizing functions
1 parent eebb629 commit fb12591

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/Storage/SessionStorage.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ class SessionStorage implements PersistentStorageInterface
1010

1111
public function __construct()
1212
{
13-
if (session_status() !== PHP_SESSION_ACTIVE) {
14-
throw new ShopifySdkException(
15-
"Sessions are not active. Please start one using session_start()"
16-
);
17-
}
13+
1814
}
1915

2016
public function get($key)
2117
{
18+
$this->assertSession();
2219
if (isset($_SESSION[$this->prefix . $key])) {
2320
return $_SESSION[$this->prefix . $key];
2421
}
@@ -27,6 +24,16 @@ public function get($key)
2724

2825
public function set($key, $value)
2926
{
27+
$this->assertSession();
3028
$_SESSION[$this->prefix . $key] = $value;
3129
}
30+
31+
public function assertSession()
32+
{
33+
if (session_status() !== PHP_SESSION_ACTIVE) {
34+
throw new ShopifySdkException(
35+
"Sessions are not active. Please start one using session_start()"
36+
);
37+
}
38+
}
3239
}

0 commit comments

Comments
 (0)