1 | <?php |
||
15 | trait Sessions { |
||
16 | /** |
||
17 | * @var string Session ID |
||
18 | */ |
||
19 | protected $sessionId; |
||
20 | |||
21 | /** |
||
22 | * @var integer |
||
23 | */ |
||
24 | protected $sessionStartTimeout = 10; |
||
25 | |||
26 | /** |
||
27 | * @var boolean |
||
28 | */ |
||
29 | protected $sessionStarted = false; |
||
30 | |||
31 | /** |
||
32 | * @var boolean |
||
33 | */ |
||
34 | protected $sessionFlushing = false; |
||
35 | |||
36 | /** |
||
37 | * @var resource |
||
38 | */ |
||
39 | protected $sessionFp; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $sessionPrefix = 'sess_'; |
||
45 | |||
46 | /** |
||
47 | * Is session started? |
||
48 | * @return boolean |
||
49 | */ |
||
50 | public function sessionStarted() { |
||
53 | |||
54 | /** |
||
55 | * Deferred event 'onSessionStart' |
||
56 | * @return callable |
||
57 | */ |
||
58 | public function onSessionStartEvent() { |
||
80 | |||
81 | /** |
||
82 | * Deferred event 'onSessionRead' |
||
83 | * @return callable |
||
84 | */ |
||
85 | public function onSessionReadEvent() { |
||
104 | |||
105 | /** |
||
106 | * Reads session data |
||
107 | * @param string $sid Session ID |
||
108 | * @param callable $cb Callback |
||
109 | * @return void |
||
110 | */ |
||
111 | public function sessionRead($sid, $cb = null) { |
||
123 | |||
124 | /** |
||
125 | * Commmit session data |
||
126 | * @param callable $cb Callback |
||
127 | * @return void |
||
128 | */ |
||
129 | public function sessionCommit($cb = null) { |
||
149 | |||
150 | /** |
||
151 | * Session start |
||
152 | * @param boolean $force_start |
||
153 | * @return void |
||
154 | */ |
||
155 | protected function sessionStart($force_start = true) { |
||
173 | |||
174 | /** |
||
175 | * Start new session |
||
176 | * @param callable $cb Callback |
||
177 | * @return void |
||
178 | */ |
||
179 | protected function sessionStartNew($cb = null) { |
||
199 | |||
200 | /** |
||
201 | * Encodes session data |
||
202 | * @return string|false |
||
203 | */ |
||
204 | protected function sessionEncode() { |
||
214 | |||
215 | /** |
||
216 | * Set session state |
||
217 | * @param mixed $var |
||
218 | * @return void |
||
219 | */ |
||
220 | protected function setSessionState($var) { |
||
223 | |||
224 | /** |
||
225 | * Get session state |
||
226 | * @return mixed |
||
227 | */ |
||
228 | protected function getSessionState() { |
||
231 | |||
232 | /** |
||
233 | * Decodes session data |
||
234 | * @param string $str Data |
||
235 | * @return boolean |
||
236 | */ |
||
237 | protected function sessionDecode($str) { |
||
249 | |||
250 | /** |
||
251 | * session_encode() - clone, which not require session_start() |
||
252 | * @see http://www.php.net/manual/en/function.session-encode.php |
||
253 | * @param array $array |
||
254 | * @return string |
||
255 | */ |
||
256 | public function serialize_php($array) { |
||
274 | |||
275 | /** |
||
276 | * session_decode() - clone, which not require session_start() |
||
277 | * @see http://www.php.net/manual/en/function.session-decode.php#108037 |
||
278 | * @param string $session_data |
||
279 | * @return array |
||
280 | */ |
||
281 | protected function unserialize_php($session_data) { |
||
299 | } |
||
300 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.