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