1: <?php
2:
3: namespace Csim\Controller;
4:
5: /**
6: * Stores and retrieves session data.
7: */
8: class SessionManager {
9:
10: /**
11: * The key for the controller object is the session storage.
12: */
13: const CONTROLLER_KEY = 'controller';
14:
15: /**
16: * If there is a controller object in the current session, it is returned. If there is not,
17: * a new controller is instantiated and returned.
18: *
19: * @return \Csim\Controller\Controller the controller.
20: */
21: public static function getController() {
22: if (isset($_SESSION[self::CONTROLLER_KEY])) {
23: return unserialize($_SESSION[self::CONTROLLER_KEY]);
24: } else {
25: return new Controller();
26: }
27: }
28:
29: /**
30: * The specified controller instance is stored in the current session.
31: */
32: public static function storeController(Controller $controller) {
33: $_SESSION[self::CONTROLLER_KEY] = serialize($controller);
34: }
35:
36: }
37: