/libraries/joomla/session/storage/xcache.php

https://bitbucket.org/eternaware/joomus · PHP · 109 lines · 40 code · 11 blank · 58 comment · 3 complexity · b67430829846f996660572e325915721 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Session
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. /**
  11. * XCache session storage handler
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage Session
  15. * @since 11.1
  16. */
  17. class JSessionStorageXcache extends JSessionStorage
  18. {
  19. /**
  20. * Constructor
  21. *
  22. * @param array $options Optional parameters.
  23. *
  24. * @since 11.1
  25. * @throws RuntimeException
  26. */
  27. public function __construct($options = array())
  28. {
  29. if (!self::isSupported())
  30. {
  31. throw new RuntimeException('XCache Extension is not available', 404);
  32. }
  33. parent::__construct($options);
  34. }
  35. /**
  36. * Read the data for a particular session identifier from the SessionHandler backend.
  37. *
  38. * @param string $id The session identifier.
  39. *
  40. * @return string The session data.
  41. *
  42. * @since 11.1
  43. */
  44. public function read($id)
  45. {
  46. $sess_id = 'sess_' . $id;
  47. // Check if id exists
  48. if (!xcache_isset($sess_id))
  49. {
  50. return;
  51. }
  52. return (string) xcache_get($sess_id);
  53. }
  54. /**
  55. * Write session data to the SessionHandler backend.
  56. *
  57. * @param string $id The session identifier.
  58. * @param string $session_data The session data.
  59. *
  60. * @return boolean True on success, false otherwise.
  61. *
  62. * @since 11.1
  63. */
  64. public function write($id, $session_data)
  65. {
  66. $sess_id = 'sess_' . $id;
  67. return xcache_set($sess_id, $session_data, ini_get("session.gc_maxlifetime"));
  68. }
  69. /**
  70. * Destroy the data for a particular session identifier in the SessionHandler backend.
  71. *
  72. * @param string $id The session identifier.
  73. *
  74. * @return boolean True on success, false otherwise.
  75. *
  76. * @since 11.1
  77. */
  78. public function destroy($id)
  79. {
  80. $sess_id = 'sess_' . $id;
  81. if (!xcache_isset($sess_id))
  82. {
  83. return true;
  84. }
  85. return xcache_unset($sess_id);
  86. }
  87. /**
  88. * Test to see if the SessionHandler is available.
  89. *
  90. * @return boolean True on success, false otherwise.
  91. *
  92. * @since 12.1
  93. */
  94. static public function isSupported()
  95. {
  96. return (extension_loaded('xcache'));
  97. }
  98. }