@@ -8,56 +8,56 @@ |
||
| 8 | 8 | |
| 9 | 9 | abstract class BaseStore implements SessionHandlerInterface |
| 10 | 10 | { |
| 11 | - use Configurable; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * Session secret key |
|
| 15 | - * |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - protected $key = null; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Assign a new session secret key |
|
| 22 | - * |
|
| 23 | - * @param string $key |
|
| 24 | - */ |
|
| 25 | - public function setKey($key) |
|
| 26 | - { |
|
| 27 | - $this->key = $key; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Get the session secret key |
|
| 32 | - * |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - protected function getKey() |
|
| 36 | - { |
|
| 37 | - return $this->key; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Get lifetime in number of seconds |
|
| 42 | - * |
|
| 43 | - * @return int |
|
| 44 | - */ |
|
| 45 | - protected function getLifetime() |
|
| 46 | - { |
|
| 47 | - $params = session_get_cookie_params(); |
|
| 48 | - $cookieLifetime = (int)$params['lifetime']; |
|
| 49 | - $gcLifetime = (int)ini_get('session.gc_maxlifetime'); |
|
| 50 | - |
|
| 51 | - return $cookieLifetime ? min($cookieLifetime, $gcLifetime) : $gcLifetime; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Gets the current unix timestamp |
|
| 56 | - * |
|
| 57 | - * @return int |
|
| 58 | - */ |
|
| 59 | - protected function getNow() |
|
| 60 | - { |
|
| 61 | - return (int) DBDatetime::now()->getTimestamp(); |
|
| 62 | - } |
|
| 11 | + use Configurable; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * Session secret key |
|
| 15 | + * |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + protected $key = null; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Assign a new session secret key |
|
| 22 | + * |
|
| 23 | + * @param string $key |
|
| 24 | + */ |
|
| 25 | + public function setKey($key) |
|
| 26 | + { |
|
| 27 | + $this->key = $key; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Get the session secret key |
|
| 32 | + * |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + protected function getKey() |
|
| 36 | + { |
|
| 37 | + return $this->key; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Get lifetime in number of seconds |
|
| 42 | + * |
|
| 43 | + * @return int |
|
| 44 | + */ |
|
| 45 | + protected function getLifetime() |
|
| 46 | + { |
|
| 47 | + $params = session_get_cookie_params(); |
|
| 48 | + $cookieLifetime = (int)$params['lifetime']; |
|
| 49 | + $gcLifetime = (int)ini_get('session.gc_maxlifetime'); |
|
| 50 | + |
|
| 51 | + return $cookieLifetime ? min($cookieLifetime, $gcLifetime) : $gcLifetime; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Gets the current unix timestamp |
|
| 56 | + * |
|
| 57 | + * @return int |
|
| 58 | + */ |
|
| 59 | + protected function getNow() |
|
| 60 | + { |
|
| 61 | + return (int) DBDatetime::now()->getTimestamp(); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -45,8 +45,8 @@ |
||
| 45 | 45 | protected function getLifetime() |
| 46 | 46 | { |
| 47 | 47 | $params = session_get_cookie_params(); |
| 48 | - $cookieLifetime = (int)$params['lifetime']; |
|
| 49 | - $gcLifetime = (int)ini_get('session.gc_maxlifetime'); |
|
| 48 | + $cookieLifetime = (int) $params['lifetime']; |
|
| 49 | + $gcLifetime = (int) ini_get('session.gc_maxlifetime'); |
|
| 50 | 50 | |
| 51 | 51 | return $cookieLifetime ? min($cookieLifetime, $gcLifetime) : $gcLifetime; |
| 52 | 52 | } |
@@ -6,18 +6,18 @@ |
||
| 6 | 6 | |
| 7 | 7 | class HybridSessionDataObject extends DataObject |
| 8 | 8 | { |
| 9 | - private static $db = [ |
|
| 10 | - 'SessionID' => 'Varchar(64)', |
|
| 11 | - 'Expiry' => 'Int', |
|
| 12 | - 'Data' => 'Text' |
|
| 13 | - ]; |
|
| 9 | + private static $db = [ |
|
| 10 | + 'SessionID' => 'Varchar(64)', |
|
| 11 | + 'Expiry' => 'Int', |
|
| 12 | + 'Data' => 'Text' |
|
| 13 | + ]; |
|
| 14 | 14 | |
| 15 | - private static $indexes = [ |
|
| 16 | - 'SessionID' => [ |
|
| 17 | - 'type' => 'unique' |
|
| 18 | - ], |
|
| 19 | - 'Expiry' => true |
|
| 20 | - ]; |
|
| 15 | + private static $indexes = [ |
|
| 16 | + 'SessionID' => [ |
|
| 17 | + 'type' => 'unique' |
|
| 18 | + ], |
|
| 19 | + 'Expiry' => true |
|
| 20 | + ]; |
|
| 21 | 21 | |
| 22 | - private static $table_name = 'HybridSessionDataObject'; |
|
| 22 | + private static $table_name = 'HybridSessionDataObject'; |
|
| 23 | 23 | } |
@@ -5,27 +5,27 @@ |
||
| 5 | 5 | interface CryptoHandler |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @param string $data |
|
| 10 | - * |
|
| 11 | - * @return string |
|
| 12 | - */ |
|
| 13 | - public function encrypt($data); |
|
| 8 | + /** |
|
| 9 | + * @param string $data |
|
| 10 | + * |
|
| 11 | + * @return string |
|
| 12 | + */ |
|
| 13 | + public function encrypt($data); |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param string $data |
|
| 17 | - * |
|
| 18 | - * @return string |
|
| 19 | - */ |
|
| 20 | - public function decrypt($data); |
|
| 15 | + /** |
|
| 16 | + * @param string $data |
|
| 17 | + * |
|
| 18 | + * @return string |
|
| 19 | + */ |
|
| 20 | + public function decrypt($data); |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public function getKey(); |
|
| 22 | + /** |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public function getKey(); |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function getSalt(); |
|
| 27 | + /** |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function getSalt(); |
|
| 31 | 31 | } |
@@ -8,25 +8,25 @@ |
||
| 8 | 8 | |
| 9 | 9 | class HybridSessionMiddleware implements HTTPMiddleware |
| 10 | 10 | { |
| 11 | - public function process(HTTPRequest $request, callable $delegate) |
|
| 12 | - { |
|
| 13 | - try { |
|
| 14 | - // Start session and execute |
|
| 15 | - $request->getSession()->init($request); |
|
| 11 | + public function process(HTTPRequest $request, callable $delegate) |
|
| 12 | + { |
|
| 13 | + try { |
|
| 14 | + // Start session and execute |
|
| 15 | + $request->getSession()->init($request); |
|
| 16 | 16 | |
| 17 | - // Generate output |
|
| 18 | - $response = $delegate($request); |
|
| 19 | - } finally { |
|
| 20 | - // Save session data, even if there was an exception |
|
| 21 | - // Note that save() will start/resume the session if required. |
|
| 22 | - $request->getSession()->save($request); |
|
| 17 | + // Generate output |
|
| 18 | + $response = $delegate($request); |
|
| 19 | + } finally { |
|
| 20 | + // Save session data, even if there was an exception |
|
| 21 | + // Note that save() will start/resume the session if required. |
|
| 22 | + $request->getSession()->save($request); |
|
| 23 | 23 | |
| 24 | - if (HybridSession::is_enabled()) { |
|
| 25 | - // Close the session |
|
| 26 | - session_write_close(); |
|
| 27 | - } |
|
| 28 | - } |
|
| 24 | + if (HybridSession::is_enabled()) { |
|
| 25 | + // Close the session |
|
| 26 | + session_write_close(); |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - return $response; |
|
| 31 | - } |
|
| 30 | + return $response; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -9,12 +9,12 @@ |
||
| 9 | 9 | |
| 10 | 10 | class ConfigurationTest extends SapphireTest |
| 11 | 11 | { |
| 12 | - public function testHybridSessionsSessionMiddlewareReplacesCore() |
|
| 13 | - { |
|
| 14 | - $this->assertInstanceOf( |
|
| 15 | - HybridSessionMiddleware::class, |
|
| 16 | - Injector::inst()->get(SessionMiddleware::class), |
|
| 17 | - 'HybridSession\'s middleware should replace the default SessionMiddleware' |
|
| 18 | - ); |
|
| 19 | - } |
|
| 12 | + public function testHybridSessionsSessionMiddlewareReplacesCore() |
|
| 13 | + { |
|
| 14 | + $this->assertInstanceOf( |
|
| 15 | + HybridSessionMiddleware::class, |
|
| 16 | + Injector::inst()->get(SessionMiddleware::class), |
|
| 17 | + 'HybridSession\'s middleware should replace the default SessionMiddleware' |
|
| 18 | + ); |
|
| 19 | + } |
|
| 20 | 20 | } |