1 | <?php |
||
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() { |
|
34 | |||
35 | 3 | protected function saveKeysData(array $keysData) { |
|
38 | } |
||
39 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: