1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11: * @link https://cakephp.org CakePHP(tm) Project
12: * @since 3.1.0
13: * @license https://opensource.org/licenses/mit-license.php MIT License
14: */
15: namespace Cake\Auth\Storage;
16:
17: /**
18: * Memory based non-persistent storage for authenticated user record.
19: */
20: class MemoryStorage implements StorageInterface
21: {
22: /**
23: * User record.
24: *
25: * @var \ArrayAccess|array|null
26: */
27: protected $_user;
28:
29: /**
30: * Redirect URL.
31: *
32: * @var string|array|null
33: */
34: protected $_redirectUrl;
35:
36: /**
37: * {@inheritDoc}
38: */
39: public function read()
40: {
41: return $this->_user;
42: }
43:
44: /**
45: * {@inheritDoc}
46: */
47: public function write($user)
48: {
49: $this->_user = $user;
50: }
51:
52: /**
53: * {@inheritDoc}
54: */
55: public function delete()
56: {
57: $this->_user = null;
58: }
59:
60: /**
61: * {@inheritDoc}
62: */
63: public function redirectUrl($url = null)
64: {
65: if ($url === null) {
66: return $this->_redirectUrl;
67: }
68:
69: if ($url === false) {
70: $this->_redirectUrl = null;
71:
72: return null;
73: }
74:
75: $this->_redirectUrl = $url;
76: }
77: }
78: