1. sfStorage.class.php
  2. /** * sfStorage allows you to customize the way symfony stores its persistent data. * * @package symfony * @subpackage storage * @author Fabien Potencier * @author Sean Kerr * @version SVN: $Id: sfStorage.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. abstract class sfStorage
  4. {
  5. protected
  6. $options = array();
  7. /**
  8. * Class constructor.
  9. *
  10. * @see initialize()
  11. */
  12. public function __construct($options = array())
  13. {
  14. $this->initialize($options);
  15. if ($this->options['auto_shutdown'])
  16. {
  17. register_shutdown_function(array($this, 'shutdown'));
  18. }
  19. }
  20. /**
  21. * Initializes this Storage instance.
  22. *
  23. * Available options:
  24. *
  25. * * auto_shutdown: Whether to automatically save the changes to the session (true by default)
  26. *
  27. * @param array $options An associative array of options
  28. *
  29. * @return bool true, if initialization completes successfully, otherwise false
  30. *
  31. * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfStorage
  32. */
  33. public function initialize($options = array())
  34. {
  35. $this->options = array_merge(array(
  36. 'auto_shutdown' => true,
  37. ), $options);
  38. }
  39. /**
  40. * Returns the option array.
  41. *
  42. * @return array The array of options
  43. */
  44. public function getOptions()
  45. {
  46. return $this->options;
  47. }
  48. /**
  49. * Reads data from this storage.
  50. *
  51. * The preferred format for a key is directory style so naming conflicts can be avoided.
  52. *
  53. * @param string $key A unique key identifying your data
  54. *
  55. * @return mixed Data associated with the key
  56. *
  57. * @throws <b>sfStorageException</b> If an error occurs while reading data from this storage
  58. */
  59. abstract public function read($key);
  60. /**
  61. * Regenerates id that represents this storage.
  62. *
  63. * @param boolean $destroy Destroy session when regenerating?
  64. *
  65. * @return boolean True if session regenerated, false if error
  66. *
  67. * @throws <b>sfStorageException</b> If an error occurs while regenerating this storage
  68. */
  69. abstract public function regenerate($destroy = false);
  70. /**
  71. * Removes data from this storage.
  72. *
  73. * The preferred format for a key is directory style so naming conflicts can be avoided.
  74. *
  75. * @param string $key A unique key identifying your data
  76. *
  77. * @return mixed Data associated with the key
  78. *
  79. * @throws <b>sfStorageException</b> If an error occurs while removing data from this storage
  80. */
  81. abstract public function remove($key);
  82. /**
  83. * Executes the shutdown procedure.
  84. *
  85. * @throws <b>sfStorageException</b> If an error occurs while shutting down this storage
  86. */
  87. abstract public function shutdown();
  88. /**
  89. * Writes data to this storage.
  90. *
  91. * The preferred format for a key is directory style so naming conflicts can be avoided.
  92. *
  93. * @param string $key A unique key identifying your data
  94. * @param mixed $data Data associated with your key
  95. *
  96. * @throws <b>sfStorageException</b> If an error occurs while writing to this storage
  97. */
  98. abstract public function write($key, $data);
  99. }

Debug toolbar