/libraries/vendor/joomla/session/Joomla/Session/Storage/Memcache.php

https://gitlab.com/vitaliylukin91/idea-rating · PHP · 72 lines · 29 code · 7 blank · 36 comment · 2 complexity · de98f5e708e3a1188775e8baadab8ed7 MD5 · raw file

  1. <?php
  2. /**
  3. * Part of the Joomla Framework Session Package
  4. *
  5. * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE
  7. */
  8. namespace Joomla\Session\Storage;
  9. use Joomla\Session\Storage;
  10. /**
  11. * Memcache session storage handler for PHP
  12. *
  13. * @since 1.0
  14. * @deprecated The joomla/session package is deprecated
  15. */
  16. class Memcache extends Storage
  17. {
  18. /**
  19. * Constructor
  20. *
  21. * @param array $options Optional parameters.
  22. *
  23. * @since 1.0
  24. * @throws \RuntimeException
  25. */
  26. public function __construct($options = array())
  27. {
  28. if (!self::isSupported())
  29. {
  30. throw new \RuntimeException('Memcache Extension is not available', 404);
  31. }
  32. parent::__construct($options);
  33. // This will be an array of loveliness
  34. // @todo: multiple servers
  35. $this->_servers = array(
  36. array(
  37. 'host' => isset($options['memcache_server_host']) ? $options['memcache_server_host'] : 'localhost',
  38. 'port' => isset($options['memcache_server_port']) ? $options['memcache_server_port'] : 11211
  39. )
  40. );
  41. }
  42. /**
  43. * Register the functions of this class with PHP's session handler
  44. *
  45. * @return void
  46. *
  47. * @since 1.0
  48. */
  49. public function register()
  50. {
  51. ini_set('session.save_path', $this->_servers[0]['host'] . ':' . $this->_servers[0]['port']);
  52. ini_set('session.save_handler', 'memcache');
  53. }
  54. /**
  55. * Test to see if the SessionHandler is available.
  56. *
  57. * @return boolean True on success, false otherwise.
  58. *
  59. * @since 1.0
  60. */
  61. static public function isSupported()
  62. {
  63. return (extension_loaded('memcache') && class_exists('Memcache'));
  64. }
  65. }