MemoryStorage.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * Memory based non-persistent storage for authenticated user record.
  18. */
  19. class MemoryStorage implements StorageInterface
  20. {
  21. /**
  22. * User record.
  23. *
  24. * @var \ArrayAccess|array|null
  25. */
  26. protected $_user;
  27. /**
  28. * Redirect url.
  29. *
  30. * @var string|null
  31. */
  32. protected $_redirectUrl;
  33. /**
  34. * {@inheritDoc}
  35. */
  36. public function read()
  37. {
  38. return $this->_user;
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public function write($user)
  44. {
  45. $this->_user = $user;
  46. }
  47. /**
  48. * {@inheritDoc}
  49. */
  50. public function delete()
  51. {
  52. $this->_user = null;
  53. }
  54. /**
  55. * {@inheritDoc}
  56. */
  57. public function redirectUrl($url = null)
  58. {
  59. if ($url === null) {
  60. return $this->_redirectUrl;
  61. }
  62. if ($url === false) {
  63. $this->_redirectUrl = null;
  64. return null;
  65. }
  66. $this->_redirectUrl = $url;
  67. }
  68. }