Subversion Repositories oidplus

Rev

Rev 1086 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1086 Rev 1116
Line 23... Line 23...
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusAuthContentStoreSession extends OIDplusAuthContentStore {
26
class OIDplusAuthContentStoreSession extends OIDplusAuthContentStore {
27
 
27
 
-
 
28
        /**
-
 
29
         * @return OIDplusSessionHandler
-
 
30
         */
28
        protected static function getSessionHandler() {
31
        protected static function getSessionHandler(): OIDplusSessionHandler {
29
                static $sesHandler = null;
32
                static $sesHandler = null;
30
                if (is_null($sesHandler)) {
33
                if (is_null($sesHandler)) {
31
                        $sesHandler = new OIDplusSessionHandler();
34
                        $sesHandler = new OIDplusSessionHandler();
32
                }
35
                }
33
                return $sesHandler;
36
                return $sesHandler;
34
        }
37
        }
35
 
38
 
36
        // Override abstract functions
39
        // Override abstract functions
37
        # TODO: shouldn't we just include OIDplusSessionHandler in this class?
40
        # TODO: shouldn't we just include OIDplusSessionHandler in this class?
38
 
41
 
-
 
42
        /**
-
 
43
         * @param string $name
-
 
44
         * @param mixed|null $default
-
 
45
         * @return mixed|null
-
 
46
         * @throws OIDplusException
-
 
47
         */
39
        public function getValue($name, $default = NULL) {
48
        public function getValue(string $name, $default = NULL) {
40
                try {
49
                try {
41
                        return self::getSessionHandler()->getValue($name, $default);
50
                        return self::getSessionHandler()->getValue($name, $default);
42
                } catch (\Exception $e) {
51
                } catch (\Exception $e) {
43
                        self::getSessionHandler()->destroySession();
52
                        self::getSessionHandler()->destroySession();
44
                        // TODO: For some reason If destroySession() is called, we won't get this Exception?!
53
                        // TODO: For some reason If destroySession() is called, we won't get this Exception?!
45
                        throw new OIDplusException(_L('Internal error with session. Please reload the page and log-in again. %1', $e->getMessage()));
54
                        throw new OIDplusException(_L('Internal error with session. Please reload the page and log-in again. %1', $e->getMessage()));
46
                }
55
                }
47
        }
56
        }
48
 
57
 
-
 
58
        /**
-
 
59
         * @param string $name
-
 
60
         * @param mixed $value
-
 
61
         * @return void
-
 
62
         * @throws OIDplusException
-
 
63
         */
49
        public function setValue($name, $value) {
64
        public function setValue(string $name, $value) {
50
                return self::getSessionHandler()->setValue($name, $value);
65
                self::getSessionHandler()->setValue($name, $value);
51
        }
66
        }
52
 
67
 
-
 
68
        /**
-
 
69
         * @param string $name
-
 
70
         * @return bool
-
 
71
         * @throws OIDplusException
-
 
72
         */
53
        public function exists($name) {
73
        public function exists(string $name): bool {
54
                return self::getSessionHandler()->exists($name);
74
                return self::getSessionHandler()->exists($name);
55
        }
75
        }
56
 
76
 
-
 
77
        /**
-
 
78
         * @param string $name
-
 
79
         * @return void
-
 
80
         * @throws OIDplusException
-
 
81
         */
57
        public function delete($name) {
82
        public function delete(string $name) {
58
                return self::getSessionHandler()->delete($name);
83
                self::getSessionHandler()->delete($name);
59
        }
84
        }
60
 
85
 
-
 
86
        /**
-
 
87
         * @return void
-
 
88
         * @throws OIDplusException
-
 
89
         */
61
        public function destroySession() {
90
        public function destroySession() {
62
                return self::getSessionHandler()->destroySession();
91
                self::getSessionHandler()->destroySession();
63
        }
92
        }
64
 
93
 
-
 
94
        /**
-
 
95
         * @return OIDplusAuthContentStoreSession|null
-
 
96
         */
65
        public static function getActiveProvider() {
97
        public static function getActiveProvider()/*: ?OIDplusAuthContentStore*/ {
66
                static $contentProvider = null;
98
                static $contentProvider = null;
67
 
99
 
68
                if (!$contentProvider) {
100
                if (!$contentProvider) {
69
                        if (self::getSessionHandler()->isActive()) {
101
                        if (self::getSessionHandler()->isActive()) {
70
                                $contentProvider = new OIDplusAuthContentStoreSession();
102
                                $contentProvider = new OIDplusAuthContentStoreSession();
Line 72... Line 104...
72
                }
104
                }
73
 
105
 
74
                return $contentProvider;
106
                return $contentProvider;
75
        }
107
        }
76
 
108
 
-
 
109
        /**
-
 
110
         * @param string $email
-
 
111
         * @param string $loginfo
-
 
112
         * @return void
-
 
113
         */
77
        public function raLoginEx($email, &$loginfo) {
114
        public function raLoginEx(string $email, string &$loginfo) {
78
                $this->raLogin($email);
115
                $this->raLogin($email);
79
                if (is_null(self::getActiveProvider())) {
116
                if (is_null(self::getActiveProvider())) {
80
                        $loginfo = 'into new PHP session';
117
                        $loginfo = 'into new PHP session';
81
                } else {
118
                } else {
82
                        $loginfo = 'into existing PHP session';
119
                        $loginfo = 'into existing PHP session';
83
                }
120
                }
84
        }
121
        }
85
 
122
 
-
 
123
        /**
-
 
124
         * @param string $loginfo
-
 
125
         * @return void
-
 
126
         */
86
        public function adminLoginEx(&$loginfo) {
127
        public function adminLoginEx(string &$loginfo) {
87
                $this->adminLogin();
128
                $this->adminLogin();
88
                if (is_null(self::getActiveProvider())) {
129
                if (is_null(self::getActiveProvider())) {
89
                        $loginfo = 'into new PHP session';
130
                        $loginfo = 'into new PHP session';
90
                } else {
131
                } else {
91
                        $loginfo = 'into existing PHP session';
132
                        $loginfo = 'into existing PHP session';
92
                }
133
                }
93
        }
134
        }
94
 
135
 
-
 
136
        /**
-
 
137
         * @param string $email
-
 
138
         * @param string $loginfo
-
 
139
         * @return void
-
 
140
         */
95
        public function raLogoutEx($email, &$loginfo) {
141
        public function raLogoutEx(string $email, string &$loginfo) {
96
                $this->raLogout($email);
142
                $this->raLogout($email);
97
                $loginfo = 'from PHP session';
143
                $loginfo = 'from PHP session';
98
        }
144
        }
99
 
145
 
-
 
146
        /**
-
 
147
         * @param string $loginfo
-
 
148
         * @return void
-
 
149
         */
100
        public function adminLogoutEx(&$loginfo) {
150
        public function adminLogoutEx(string &$loginfo) {
101
                $this->adminLogout();
151
                $this->adminLogout();
102
                $loginfo = 'from PHP session';
152
                $loginfo = 'from PHP session';
103
        }
153
        }
104
 
154
 
-
 
155
        /**
-
 
156
         * @return void
-
 
157
         */
105
        public function activate() {
158
        public function activate() {
106
                # Sessions automatically activate during setValue()
159
                # Sessions automatically activate during setValue()
107
                return;
-
 
108
        }
160
        }
109
 
161
 
110
}
162
}