Session::getKeysData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 2
1
<?php
2
3
namespace PhpConsole\Storage;
4
5
/**
6
 * $_SESSION storage for postponed response data. Is used by default.
7
 *
8
 * @package PhpConsole
9
 * @version 3.1
10
 * @link http://consle.com
11
 * @author Sergey Barbushin http://linkedin.com/in/barbushin
12
 * @copyright © Sergey Barbushin, 2011-2013. All rights reserved.
13
 * @license http://www.opensource.org/licenses/BSD-3-Clause "The BSD 3-Clause License"
14
 */
15
class Session extends AllKeysList {
16
17
	protected $sessionKey;
18
19
	/**
20
	 * @param string $sessionKey Key name in $_SESSION variable
21
	 * @param bool $autoStart Start session if it's not started
22
	 */
23 3
	public function __construct($sessionKey = '__PHP_Console_postponed', $autoStart = true) {
24 3
        	if($autoStart && (defined('PHP_SESSION_ACTIVE') ? session_status() != PHP_SESSION_ACTIVE : !session_id()) && !headers_sent()) {
25
        		session_start();
26
		}
27 3
		register_shutdown_function('session_write_close'); // force saving session data if session handler is overridden
28 3
		$this->sessionKey = $sessionKey;
29 3
	}
30
31 3
	protected function getKeysData() {
32 3
		return isset($_SESSION[$this->sessionKey]) ? $_SESSION[$this->sessionKey] : array();
33
	}
34
35 3
	protected function saveKeysData(array $keysData) {
36 3
		$_SESSION[$this->sessionKey] = $keysData;
37 3
	}
38
}
39