@@ -44,237 +44,237 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | class HTTP_Session_Container |
| 46 | 46 | { |
| 47 | - /** |
|
| 48 | - * Additional options for the container object |
|
| 49 | - * |
|
| 50 | - * @var array |
|
| 51 | - * @access private |
|
| 52 | - */ |
|
| 53 | - public $options = array(); |
|
| 47 | + /** |
|
| 48 | + * Additional options for the container object |
|
| 49 | + * |
|
| 50 | + * @var array |
|
| 51 | + * @access private |
|
| 52 | + */ |
|
| 53 | + public $options = array(); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Constrtuctor method |
|
| 57 | - * |
|
| 58 | - * @param array $options Additional options for the container object |
|
| 59 | - * |
|
| 60 | - * @access public |
|
| 61 | - * @return object |
|
| 62 | - */ |
|
| 63 | - public function HTTP_Session_Container($options = null) |
|
| 64 | - { |
|
| 65 | - $this->_setDefaults(); |
|
| 66 | - if (is_array($options)) { |
|
| 67 | - $this->_parseOptions(); |
|
| 68 | - } |
|
| 69 | - } |
|
| 55 | + /** |
|
| 56 | + * Constrtuctor method |
|
| 57 | + * |
|
| 58 | + * @param array $options Additional options for the container object |
|
| 59 | + * |
|
| 60 | + * @access public |
|
| 61 | + * @return object |
|
| 62 | + */ |
|
| 63 | + public function HTTP_Session_Container($options = null) |
|
| 64 | + { |
|
| 65 | + $this->_setDefaults(); |
|
| 66 | + if (is_array($options)) { |
|
| 67 | + $this->_parseOptions(); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Set some default options |
|
| 73 | - * |
|
| 74 | - * @access private |
|
| 75 | - * @return void |
|
| 76 | - */ |
|
| 77 | - public function _setDefaults() |
|
| 78 | - { |
|
| 79 | - } |
|
| 71 | + /** |
|
| 72 | + * Set some default options |
|
| 73 | + * |
|
| 74 | + * @access private |
|
| 75 | + * @return void |
|
| 76 | + */ |
|
| 77 | + public function _setDefaults() |
|
| 78 | + { |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Parse options passed to the container class |
|
| 83 | - * |
|
| 84 | - * @param array $options Options |
|
| 85 | - * |
|
| 86 | - * @access private |
|
| 87 | - * @return void |
|
| 88 | - */ |
|
| 89 | - public function _parseOptions($options) |
|
| 90 | - { |
|
| 91 | - foreach ($options as $option => $value) { |
|
| 92 | - if (in_array($option, array_keys($this->options))) { |
|
| 93 | - $this->options[$option] = $value; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 81 | + /** |
|
| 82 | + * Parse options passed to the container class |
|
| 83 | + * |
|
| 84 | + * @param array $options Options |
|
| 85 | + * |
|
| 86 | + * @access private |
|
| 87 | + * @return void |
|
| 88 | + */ |
|
| 89 | + public function _parseOptions($options) |
|
| 90 | + { |
|
| 91 | + foreach ($options as $option => $value) { |
|
| 92 | + if (in_array($option, array_keys($this->options))) { |
|
| 93 | + $this->options[$option] = $value; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * This function is called by the session handler to initialize things |
|
| 100 | - * |
|
| 101 | - * @param string $save_path Save path |
|
| 102 | - * @param string $session_name Session name |
|
| 103 | - * |
|
| 104 | - * @access public |
|
| 105 | - * @return bool |
|
| 106 | - */ |
|
| 107 | - public function open($save_path, $session_name) |
|
| 108 | - { |
|
| 109 | - return true; |
|
| 110 | - } |
|
| 98 | + /** |
|
| 99 | + * This function is called by the session handler to initialize things |
|
| 100 | + * |
|
| 101 | + * @param string $save_path Save path |
|
| 102 | + * @param string $session_name Session name |
|
| 103 | + * |
|
| 104 | + * @access public |
|
| 105 | + * @return bool |
|
| 106 | + */ |
|
| 107 | + public function open($save_path, $session_name) |
|
| 108 | + { |
|
| 109 | + return true; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * This function is called when the page is finished |
|
| 114 | - * executing and the session handler needs to close things off |
|
| 115 | - * |
|
| 116 | - * Has to be overwritten by each container class |
|
| 117 | - * |
|
| 118 | - * @access public |
|
| 119 | - * @return bool |
|
| 120 | - */ |
|
| 121 | - public function close() |
|
| 122 | - { |
|
| 123 | - return true; |
|
| 124 | - } |
|
| 112 | + /** |
|
| 113 | + * This function is called when the page is finished |
|
| 114 | + * executing and the session handler needs to close things off |
|
| 115 | + * |
|
| 116 | + * Has to be overwritten by each container class |
|
| 117 | + * |
|
| 118 | + * @access public |
|
| 119 | + * @return bool |
|
| 120 | + */ |
|
| 121 | + public function close() |
|
| 122 | + { |
|
| 123 | + return true; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * This function is called by the session handler |
|
| 128 | - * to read the data associated with a given session ID. |
|
| 129 | - * This function must retrieve and return the session data |
|
| 130 | - * for the session identified by $id. |
|
| 131 | - * |
|
| 132 | - * Has to be overwritten by each container class |
|
| 133 | - * |
|
| 134 | - * @param string $id ID of the session |
|
| 135 | - * |
|
| 136 | - * @access public |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - public function read($id) |
|
| 140 | - { |
|
| 141 | - return ''; |
|
| 142 | - } |
|
| 126 | + /** |
|
| 127 | + * This function is called by the session handler |
|
| 128 | + * to read the data associated with a given session ID. |
|
| 129 | + * This function must retrieve and return the session data |
|
| 130 | + * for the session identified by $id. |
|
| 131 | + * |
|
| 132 | + * Has to be overwritten by each container class |
|
| 133 | + * |
|
| 134 | + * @param string $id ID of the session |
|
| 135 | + * |
|
| 136 | + * @access public |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + public function read($id) |
|
| 140 | + { |
|
| 141 | + return ''; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * This function is called when the session handler |
|
| 146 | - * has session data to save, which usually happens |
|
| 147 | - * at the end of your script |
|
| 148 | - * |
|
| 149 | - * Has to be overwritten by each container class |
|
| 150 | - * |
|
| 151 | - * @param string $id ID of the session |
|
| 152 | - * @param mixed $data The data associated with a given session ID |
|
| 153 | - * |
|
| 154 | - * @access public |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public function write($id, $data) |
|
| 158 | - { |
|
| 159 | - return true; |
|
| 160 | - } |
|
| 144 | + /** |
|
| 145 | + * This function is called when the session handler |
|
| 146 | + * has session data to save, which usually happens |
|
| 147 | + * at the end of your script |
|
| 148 | + * |
|
| 149 | + * Has to be overwritten by each container class |
|
| 150 | + * |
|
| 151 | + * @param string $id ID of the session |
|
| 152 | + * @param mixed $data The data associated with a given session ID |
|
| 153 | + * |
|
| 154 | + * @access public |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public function write($id, $data) |
|
| 158 | + { |
|
| 159 | + return true; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * This function is called when a session is destroyed. |
|
| 164 | - * It is responsible for deleting the session and cleaning things up. |
|
| 165 | - * |
|
| 166 | - * Has to be overwritten by each container class |
|
| 167 | - * |
|
| 168 | - * @param string $id ID of the session |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @return bool |
|
| 172 | - */ |
|
| 173 | - public function destroy($id) |
|
| 174 | - { |
|
| 175 | - return true; |
|
| 176 | - } |
|
| 162 | + /** |
|
| 163 | + * This function is called when a session is destroyed. |
|
| 164 | + * It is responsible for deleting the session and cleaning things up. |
|
| 165 | + * |
|
| 166 | + * Has to be overwritten by each container class |
|
| 167 | + * |
|
| 168 | + * @param string $id ID of the session |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @return bool |
|
| 172 | + */ |
|
| 173 | + public function destroy($id) |
|
| 174 | + { |
|
| 175 | + return true; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * This function copies session data of specified id to specified table |
|
| 180 | - * |
|
| 181 | - * Has to be overwritten by each container class |
|
| 182 | - * |
|
| 183 | - * @param string $targetTable Table to replicate data to |
|
| 184 | - * @param string $id ID of the session |
|
| 185 | - * |
|
| 186 | - * @access public |
|
| 187 | - * @return bool |
|
| 188 | - */ |
|
| 189 | - public function replicate($targetTable, $id = null) |
|
| 190 | - { |
|
| 191 | - return true; |
|
| 192 | - } |
|
| 178 | + /** |
|
| 179 | + * This function copies session data of specified id to specified table |
|
| 180 | + * |
|
| 181 | + * Has to be overwritten by each container class |
|
| 182 | + * |
|
| 183 | + * @param string $targetTable Table to replicate data to |
|
| 184 | + * @param string $id ID of the session |
|
| 185 | + * |
|
| 186 | + * @access public |
|
| 187 | + * @return bool |
|
| 188 | + */ |
|
| 189 | + public function replicate($targetTable, $id = null) |
|
| 190 | + { |
|
| 191 | + return true; |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * This function is responsible for garbage collection. |
|
| 196 | - * In the case of session handling, it is responsible |
|
| 197 | - * for deleting old, stale sessions that are hanging around. |
|
| 198 | - * The session handler will call this every now and then. |
|
| 199 | - * |
|
| 200 | - * Has to be overwritten by each container class |
|
| 201 | - * |
|
| 202 | - * @param integer $maxlifetime Maximum lifetime |
|
| 203 | - * |
|
| 204 | - * @access public |
|
| 205 | - * @return bool |
|
| 206 | - */ |
|
| 207 | - public function gc($maxlifetime) |
|
| 208 | - { |
|
| 209 | - return true; |
|
| 210 | - } |
|
| 194 | + /** |
|
| 195 | + * This function is responsible for garbage collection. |
|
| 196 | + * In the case of session handling, it is responsible |
|
| 197 | + * for deleting old, stale sessions that are hanging around. |
|
| 198 | + * The session handler will call this every now and then. |
|
| 199 | + * |
|
| 200 | + * Has to be overwritten by each container class |
|
| 201 | + * |
|
| 202 | + * @param integer $maxlifetime Maximum lifetime |
|
| 203 | + * |
|
| 204 | + * @access public |
|
| 205 | + * @return bool |
|
| 206 | + */ |
|
| 207 | + public function gc($maxlifetime) |
|
| 208 | + { |
|
| 209 | + return true; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Set session save handler |
|
| 214 | - * |
|
| 215 | - * @access public |
|
| 216 | - * @return void |
|
| 217 | - */ |
|
| 218 | - public function set() |
|
| 219 | - { |
|
| 220 | - $GLOBALS['HTTP_Session_Container'] =& $this; |
|
| 221 | - session_module_name('user'); |
|
| 222 | - session_set_save_handler('HTTP_Session_Open', |
|
| 223 | - 'HTTP_Session_Close', |
|
| 224 | - 'HTTP_Session_Read', |
|
| 225 | - 'HTTP_Session_Write', |
|
| 226 | - 'HTTP_Session_Destroy', |
|
| 227 | - 'HTTP_Session_GC'); |
|
| 228 | - } |
|
| 212 | + /** |
|
| 213 | + * Set session save handler |
|
| 214 | + * |
|
| 215 | + * @access public |
|
| 216 | + * @return void |
|
| 217 | + */ |
|
| 218 | + public function set() |
|
| 219 | + { |
|
| 220 | + $GLOBALS['HTTP_Session_Container'] =& $this; |
|
| 221 | + session_module_name('user'); |
|
| 222 | + session_set_save_handler('HTTP_Session_Open', |
|
| 223 | + 'HTTP_Session_Close', |
|
| 224 | + 'HTTP_Session_Read', |
|
| 225 | + 'HTTP_Session_Write', |
|
| 226 | + 'HTTP_Session_Destroy', |
|
| 227 | + 'HTTP_Session_GC'); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * Destructor for compatibility with PHP >= 5.0.5 |
|
| 232 | - * |
|
| 233 | - * @access private |
|
| 234 | - * @return void |
|
| 235 | - */ |
|
| 236 | - public function __destruct() |
|
| 237 | - { |
|
| 238 | - $GLOBALS['HTTP_Session_Container'] =& $this; |
|
| 239 | - session_write_close(); |
|
| 240 | - } |
|
| 230 | + /** |
|
| 231 | + * Destructor for compatibility with PHP >= 5.0.5 |
|
| 232 | + * |
|
| 233 | + * @access private |
|
| 234 | + * @return void |
|
| 235 | + */ |
|
| 236 | + public function __destruct() |
|
| 237 | + { |
|
| 238 | + $GLOBALS['HTTP_Session_Container'] =& $this; |
|
| 239 | + session_write_close(); |
|
| 240 | + } |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | // Delegate function calls to the object's methods |
| 244 | 244 | /** @ignore */ |
| 245 | 245 | function HTTP_Session_Open($save_path, $session_name) |
| 246 | 246 | { |
| 247 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->open($save_path, $session_name) |
|
| 248 | - : false; |
|
| 247 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->open($save_path, $session_name) |
|
| 248 | + : false; |
|
| 249 | 249 | } |
| 250 | 250 | /** @ignore */ |
| 251 | 251 | function HTTP_Session_Close() |
| 252 | 252 | { |
| 253 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->close() |
|
| 254 | - : false; |
|
| 253 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->close() |
|
| 254 | + : false; |
|
| 255 | 255 | } |
| 256 | 256 | /** @ignore */ |
| 257 | 257 | function HTTP_Session_Read($id) |
| 258 | 258 | { |
| 259 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->read($id) |
|
| 260 | - : false; |
|
| 259 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->read($id) |
|
| 260 | + : false; |
|
| 261 | 261 | } |
| 262 | 262 | /** @ignore */ |
| 263 | 263 | function HTTP_Session_Write($id, $data) |
| 264 | 264 | { |
| 265 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->write($id, $data) |
|
| 266 | - : false; |
|
| 265 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->write($id, $data) |
|
| 266 | + : false; |
|
| 267 | 267 | } |
| 268 | 268 | /** @ignore */ |
| 269 | 269 | function HTTP_Session_Destroy($id) |
| 270 | 270 | { |
| 271 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->destroy($id) |
|
| 272 | - : false; |
|
| 271 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->destroy($id) |
|
| 272 | + : false; |
|
| 273 | 273 | } |
| 274 | 274 | /** @ignore */ |
| 275 | 275 | function HTTP_Session_GC($maxlifetime) |
| 276 | 276 | { |
| 277 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->gc($maxlifetime) |
|
| 278 | - : false; |
|
| 277 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->gc($maxlifetime) |
|
| 278 | + : false; |
|
| 279 | 279 | } |
| 280 | 280 | ?> |
| 281 | 281 | \ No newline at end of file |
@@ -59,306 +59,306 @@ |
||
| 59 | 59 | */ |
| 60 | 60 | class HTTP_Session_Container_DB extends HTTP_Session_Container |
| 61 | 61 | { |
| 62 | - /** |
|
| 63 | - * DB connection object |
|
| 64 | - * |
|
| 65 | - * @var object DB |
|
| 66 | - * @access private |
|
| 67 | - */ |
|
| 68 | - public $db = null; |
|
| 62 | + /** |
|
| 63 | + * DB connection object |
|
| 64 | + * |
|
| 65 | + * @var object DB |
|
| 66 | + * @access private |
|
| 67 | + */ |
|
| 68 | + public $db = null; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Session data cache id |
|
| 72 | - * |
|
| 73 | - * @var mixed |
|
| 74 | - * @access private |
|
| 75 | - */ |
|
| 76 | - public $crc = false; |
|
| 70 | + /** |
|
| 71 | + * Session data cache id |
|
| 72 | + * |
|
| 73 | + * @var mixed |
|
| 74 | + * @access private |
|
| 75 | + */ |
|
| 76 | + public $crc = false; |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Constrtuctor method |
|
| 80 | - * |
|
| 81 | - * $options is an array with the options.<br> |
|
| 82 | - * The options are: |
|
| 83 | - * <ul> |
|
| 84 | - * <li>'dsn' - The DSN string</li> |
|
| 85 | - * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 86 | - * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 87 | - * the table on garbage collection, default is 'false'.</li> |
|
| 88 | - * </ul> |
|
| 89 | - * |
|
| 90 | - * @param array $options Options |
|
| 91 | - * |
|
| 92 | - * @access public |
|
| 93 | - * @return object |
|
| 94 | - */ |
|
| 95 | - public function HTTP_Session_Container_DB($options) |
|
| 96 | - { |
|
| 97 | - $this->_setDefaults(); |
|
| 98 | - if (is_array($options)) { |
|
| 99 | - $this->_parseOptions($options); |
|
| 100 | - } else { |
|
| 101 | - $this->options['dsn'] = $options; |
|
| 102 | - } |
|
| 103 | - } |
|
| 78 | + /** |
|
| 79 | + * Constrtuctor method |
|
| 80 | + * |
|
| 81 | + * $options is an array with the options.<br> |
|
| 82 | + * The options are: |
|
| 83 | + * <ul> |
|
| 84 | + * <li>'dsn' - The DSN string</li> |
|
| 85 | + * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 86 | + * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 87 | + * the table on garbage collection, default is 'false'.</li> |
|
| 88 | + * </ul> |
|
| 89 | + * |
|
| 90 | + * @param array $options Options |
|
| 91 | + * |
|
| 92 | + * @access public |
|
| 93 | + * @return object |
|
| 94 | + */ |
|
| 95 | + public function HTTP_Session_Container_DB($options) |
|
| 96 | + { |
|
| 97 | + $this->_setDefaults(); |
|
| 98 | + if (is_array($options)) { |
|
| 99 | + $this->_parseOptions($options); |
|
| 100 | + } else { |
|
| 101 | + $this->options['dsn'] = $options; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Connect to database by using the given DSN string |
|
| 107 | - * |
|
| 108 | - * @param string $dsn DSN string |
|
| 109 | - * |
|
| 110 | - * @access private |
|
| 111 | - * @return mixed Object on error, otherwise bool |
|
| 112 | - */ |
|
| 113 | - public function _connect($dsn) |
|
| 114 | - { |
|
| 115 | - if (is_string($dsn) || is_array($dsn)) { |
|
| 116 | - $this->db = DB::connect($dsn); |
|
| 117 | - } else if (is_object($dsn) && is_a($dsn, "db_common")) { |
|
| 118 | - $this->db = $dsn; |
|
| 119 | - } else if (is_object($dsn) && DB::isError($dsn)) { |
|
| 120 | - return new DB_Error($dsn->code, PEAR_ERROR_DIE); |
|
| 121 | - } else { |
|
| 122 | - return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 123 | - . " at line " . __LINE__, |
|
| 124 | - 41, |
|
| 125 | - PEAR_ERROR_RETURN, |
|
| 126 | - null, |
|
| 127 | - null |
|
| 128 | - ); |
|
| 105 | + /** |
|
| 106 | + * Connect to database by using the given DSN string |
|
| 107 | + * |
|
| 108 | + * @param string $dsn DSN string |
|
| 109 | + * |
|
| 110 | + * @access private |
|
| 111 | + * @return mixed Object on error, otherwise bool |
|
| 112 | + */ |
|
| 113 | + public function _connect($dsn) |
|
| 114 | + { |
|
| 115 | + if (is_string($dsn) || is_array($dsn)) { |
|
| 116 | + $this->db = DB::connect($dsn); |
|
| 117 | + } else if (is_object($dsn) && is_a($dsn, "db_common")) { |
|
| 118 | + $this->db = $dsn; |
|
| 119 | + } else if (is_object($dsn) && DB::isError($dsn)) { |
|
| 120 | + return new DB_Error($dsn->code, PEAR_ERROR_DIE); |
|
| 121 | + } else { |
|
| 122 | + return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 123 | + . " at line " . __LINE__, |
|
| 124 | + 41, |
|
| 125 | + PEAR_ERROR_RETURN, |
|
| 126 | + null, |
|
| 127 | + null |
|
| 128 | + ); |
|
| 129 | 129 | |
| 130 | - } |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - if (DB::isError($this->db)) { |
|
| 133 | - return new DB_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 134 | - } |
|
| 132 | + if (DB::isError($this->db)) { |
|
| 133 | + return new DB_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - return true; |
|
| 137 | - } |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Set some default options |
|
| 141 | - * |
|
| 142 | - * @access private |
|
| 143 | - * @return void |
|
| 144 | - */ |
|
| 145 | - public function _setDefaults() |
|
| 146 | - { |
|
| 147 | - $this->options['dsn'] = null; |
|
| 148 | - $this->options['table'] = 'sessiondata'; |
|
| 149 | - $this->options['autooptimize'] = false; |
|
| 150 | - } |
|
| 139 | + /** |
|
| 140 | + * Set some default options |
|
| 141 | + * |
|
| 142 | + * @access private |
|
| 143 | + * @return void |
|
| 144 | + */ |
|
| 145 | + public function _setDefaults() |
|
| 146 | + { |
|
| 147 | + $this->options['dsn'] = null; |
|
| 148 | + $this->options['table'] = 'sessiondata'; |
|
| 149 | + $this->options['autooptimize'] = false; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Establish connection to a database |
|
| 154 | - * |
|
| 155 | - * @param string $save_path Save path |
|
| 156 | - * @param string $session_name Session name |
|
| 157 | - * |
|
| 158 | - * @return bool |
|
| 159 | - */ |
|
| 160 | - public function open($save_path, $session_name) |
|
| 161 | - { |
|
| 162 | - if (DB::isError($this->_connect($this->options['dsn']))) { |
|
| 163 | - return false; |
|
| 164 | - } else { |
|
| 165 | - return true; |
|
| 166 | - } |
|
| 167 | - } |
|
| 152 | + /** |
|
| 153 | + * Establish connection to a database |
|
| 154 | + * |
|
| 155 | + * @param string $save_path Save path |
|
| 156 | + * @param string $session_name Session name |
|
| 157 | + * |
|
| 158 | + * @return bool |
|
| 159 | + */ |
|
| 160 | + public function open($save_path, $session_name) |
|
| 161 | + { |
|
| 162 | + if (DB::isError($this->_connect($this->options['dsn']))) { |
|
| 163 | + return false; |
|
| 164 | + } else { |
|
| 165 | + return true; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Free resources |
|
| 171 | - * |
|
| 172 | - * @return void |
|
| 173 | - */ |
|
| 174 | - public function close() |
|
| 175 | - { |
|
| 176 | - return true; |
|
| 177 | - } |
|
| 169 | + /** |
|
| 170 | + * Free resources |
|
| 171 | + * |
|
| 172 | + * @return void |
|
| 173 | + */ |
|
| 174 | + public function close() |
|
| 175 | + { |
|
| 176 | + return true; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * Read session data |
|
| 181 | - * |
|
| 182 | - * @param string $id Session id |
|
| 183 | - * |
|
| 184 | - * @return void |
|
| 185 | - */ |
|
| 186 | - public function read($id) |
|
| 187 | - { |
|
| 188 | - $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 189 | - $this->options['table'], |
|
| 190 | - $this->db->quoteSmart(md5($id)), |
|
| 191 | - time()); |
|
| 192 | - $result = $this->db->getOne($query); |
|
| 193 | - if (DB::isError($result)) { |
|
| 194 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - $this->crc = strlen($result) . crc32($result); |
|
| 198 | - return $result; |
|
| 199 | - } |
|
| 179 | + /** |
|
| 180 | + * Read session data |
|
| 181 | + * |
|
| 182 | + * @param string $id Session id |
|
| 183 | + * |
|
| 184 | + * @return void |
|
| 185 | + */ |
|
| 186 | + public function read($id) |
|
| 187 | + { |
|
| 188 | + $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 189 | + $this->options['table'], |
|
| 190 | + $this->db->quoteSmart(md5($id)), |
|
| 191 | + time()); |
|
| 192 | + $result = $this->db->getOne($query); |
|
| 193 | + if (DB::isError($result)) { |
|
| 194 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + $this->crc = strlen($result) . crc32($result); |
|
| 198 | + return $result; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Write session data |
|
| 203 | - * |
|
| 204 | - * @param string $id Session id |
|
| 205 | - * @param mixed $data Data |
|
| 206 | - * |
|
| 207 | - * @return bool |
|
| 208 | - */ |
|
| 209 | - public function write($id, $data) |
|
| 210 | - { |
|
| 211 | - if ((false !== $this->crc) && |
|
| 212 | - ($this->crc === strlen($data) . crc32($data))) { |
|
| 213 | - // $_SESSION hasn't been touched, no need to update the blob column |
|
| 214 | - $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 215 | - $this->options['table'], |
|
| 216 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 217 | - $this->db->quoteSmart(md5($id))); |
|
| 218 | - } else { |
|
| 219 | - // Check if table row already exists |
|
| 220 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 221 | - $this->options['table'], |
|
| 222 | - $this->db->quoteSmart(md5($id))); |
|
| 223 | - $result = $this->db->getOne($query); |
|
| 224 | - if (DB::isError($result)) { |
|
| 225 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - if (0 == intval($result)) { |
|
| 229 | - // Insert new row into table |
|
| 230 | - $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 231 | - $this->options['table'], |
|
| 232 | - $this->db->quoteSmart(md5($id)), |
|
| 233 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 234 | - $this->db->quoteSmart($data)); |
|
| 235 | - } else { |
|
| 236 | - // Update existing row |
|
| 237 | - $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 238 | - $this->options['table'], |
|
| 239 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 240 | - $this->db->quoteSmart($data), |
|
| 241 | - $this->db->quoteSmart(md5($id))); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - $result = $this->db->query($query); |
|
| 245 | - if (DB::isError($result)) { |
|
| 246 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 247 | - return false; |
|
| 248 | - } |
|
| 201 | + /** |
|
| 202 | + * Write session data |
|
| 203 | + * |
|
| 204 | + * @param string $id Session id |
|
| 205 | + * @param mixed $data Data |
|
| 206 | + * |
|
| 207 | + * @return bool |
|
| 208 | + */ |
|
| 209 | + public function write($id, $data) |
|
| 210 | + { |
|
| 211 | + if ((false !== $this->crc) && |
|
| 212 | + ($this->crc === strlen($data) . crc32($data))) { |
|
| 213 | + // $_SESSION hasn't been touched, no need to update the blob column |
|
| 214 | + $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 215 | + $this->options['table'], |
|
| 216 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 217 | + $this->db->quoteSmart(md5($id))); |
|
| 218 | + } else { |
|
| 219 | + // Check if table row already exists |
|
| 220 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 221 | + $this->options['table'], |
|
| 222 | + $this->db->quoteSmart(md5($id))); |
|
| 223 | + $result = $this->db->getOne($query); |
|
| 224 | + if (DB::isError($result)) { |
|
| 225 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + if (0 == intval($result)) { |
|
| 229 | + // Insert new row into table |
|
| 230 | + $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 231 | + $this->options['table'], |
|
| 232 | + $this->db->quoteSmart(md5($id)), |
|
| 233 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 234 | + $this->db->quoteSmart($data)); |
|
| 235 | + } else { |
|
| 236 | + // Update existing row |
|
| 237 | + $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 238 | + $this->options['table'], |
|
| 239 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 240 | + $this->db->quoteSmart($data), |
|
| 241 | + $this->db->quoteSmart(md5($id))); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + $result = $this->db->query($query); |
|
| 245 | + if (DB::isError($result)) { |
|
| 246 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - return true; |
|
| 251 | - } |
|
| 250 | + return true; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Destroy session data |
|
| 255 | - * |
|
| 256 | - * @param string $id Session id |
|
| 257 | - * |
|
| 258 | - * @return void |
|
| 259 | - */ |
|
| 260 | - public function destroy($id) |
|
| 261 | - { |
|
| 262 | - $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 263 | - $this->options['table'], |
|
| 264 | - $this->db->quoteSmart(md5($id))); |
|
| 265 | - $result = $this->db->query($query); |
|
| 266 | - if (DB::isError($result)) { |
|
| 267 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 268 | - return false; |
|
| 269 | - } |
|
| 253 | + /** |
|
| 254 | + * Destroy session data |
|
| 255 | + * |
|
| 256 | + * @param string $id Session id |
|
| 257 | + * |
|
| 258 | + * @return void |
|
| 259 | + */ |
|
| 260 | + public function destroy($id) |
|
| 261 | + { |
|
| 262 | + $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 263 | + $this->options['table'], |
|
| 264 | + $this->db->quoteSmart(md5($id))); |
|
| 265 | + $result = $this->db->query($query); |
|
| 266 | + if (DB::isError($result)) { |
|
| 267 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 268 | + return false; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - return true; |
|
| 272 | - } |
|
| 271 | + return true; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 276 | - * |
|
| 277 | - * @param string $targetTable Table to replicate to |
|
| 278 | - * @param string $id Id of record to replicate |
|
| 279 | - * |
|
| 280 | - * @access private |
|
| 281 | - * @return bool |
|
| 282 | - */ |
|
| 283 | - public function replicate($targetTable, $id = null) |
|
| 284 | - { |
|
| 285 | - if (is_null($id)) { |
|
| 286 | - $id = HTTP_Session::id(); |
|
| 287 | - } |
|
| 274 | + /** |
|
| 275 | + * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 276 | + * |
|
| 277 | + * @param string $targetTable Table to replicate to |
|
| 278 | + * @param string $id Id of record to replicate |
|
| 279 | + * |
|
| 280 | + * @access private |
|
| 281 | + * @return bool |
|
| 282 | + */ |
|
| 283 | + public function replicate($targetTable, $id = null) |
|
| 284 | + { |
|
| 285 | + if (is_null($id)) { |
|
| 286 | + $id = HTTP_Session::id(); |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - // Check if table row already exists |
|
| 290 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 291 | - $targetTable, |
|
| 292 | - $this->db->quoteSmart(md5($id))); |
|
| 293 | - $result = $this->db->getOne($query); |
|
| 294 | - if (DB::isError($result)) { |
|
| 295 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 296 | - return false; |
|
| 297 | - } |
|
| 289 | + // Check if table row already exists |
|
| 290 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 291 | + $targetTable, |
|
| 292 | + $this->db->quoteSmart(md5($id))); |
|
| 293 | + $result = $this->db->getOne($query); |
|
| 294 | + if (DB::isError($result)) { |
|
| 295 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 296 | + return false; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - // Insert new row into dest table |
|
| 300 | - if (0 == intval($result)) { |
|
| 301 | - $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 302 | - $targetTable, |
|
| 303 | - $this->options['table'], |
|
| 304 | - $this->db->quoteSmart(md5($id))); |
|
| 299 | + // Insert new row into dest table |
|
| 300 | + if (0 == intval($result)) { |
|
| 301 | + $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 302 | + $targetTable, |
|
| 303 | + $this->options['table'], |
|
| 304 | + $this->db->quoteSmart(md5($id))); |
|
| 305 | 305 | |
| 306 | - } else { |
|
| 307 | - // Update existing row |
|
| 308 | - $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | - $targetTable, |
|
| 310 | - $this->options['table'], |
|
| 311 | - $this->db->quoteSmart(md5($id))); |
|
| 312 | - } |
|
| 306 | + } else { |
|
| 307 | + // Update existing row |
|
| 308 | + $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | + $targetTable, |
|
| 310 | + $this->options['table'], |
|
| 311 | + $this->db->quoteSmart(md5($id))); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $result = $this->db->query($query); |
|
| 315 | - if (DB::isError($result)) { |
|
| 316 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 317 | - return false; |
|
| 318 | - } |
|
| 314 | + $result = $this->db->query($query); |
|
| 315 | + if (DB::isError($result)) { |
|
| 316 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 317 | + return false; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - return true; |
|
| 321 | - } |
|
| 320 | + return true; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - /** |
|
| 324 | - * Garbage collection |
|
| 325 | - * |
|
| 326 | - * @param int $maxlifetime Maximum lifetime |
|
| 327 | - * |
|
| 328 | - * @return bool |
|
| 329 | - */ |
|
| 330 | - public function gc($maxlifetime) |
|
| 331 | - { |
|
| 332 | - $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | - $this->options['table'], |
|
| 334 | - time()); |
|
| 335 | - $result = $this->db->query($query); |
|
| 336 | - if (DB::isError($result)) { |
|
| 337 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 338 | - return false; |
|
| 339 | - } |
|
| 340 | - if ($this->options['autooptimize']) { |
|
| 341 | - switch($this->db->phptype) { |
|
| 342 | - case 'mysql': |
|
| 343 | - $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | - break; |
|
| 345 | - case 'pgsql': |
|
| 346 | - $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | - break; |
|
| 348 | - default: |
|
| 349 | - $query = null; |
|
| 350 | - break; |
|
| 351 | - } |
|
| 352 | - if (isset($query)) { |
|
| 353 | - $result = $this->db->query($query); |
|
| 354 | - if (DB::isError($result)) { |
|
| 355 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 323 | + /** |
|
| 324 | + * Garbage collection |
|
| 325 | + * |
|
| 326 | + * @param int $maxlifetime Maximum lifetime |
|
| 327 | + * |
|
| 328 | + * @return bool |
|
| 329 | + */ |
|
| 330 | + public function gc($maxlifetime) |
|
| 331 | + { |
|
| 332 | + $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | + $this->options['table'], |
|
| 334 | + time()); |
|
| 335 | + $result = $this->db->query($query); |
|
| 336 | + if (DB::isError($result)) { |
|
| 337 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + if ($this->options['autooptimize']) { |
|
| 341 | + switch($this->db->phptype) { |
|
| 342 | + case 'mysql': |
|
| 343 | + $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | + break; |
|
| 345 | + case 'pgsql': |
|
| 346 | + $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | + break; |
|
| 348 | + default: |
|
| 349 | + $query = null; |
|
| 350 | + break; |
|
| 351 | + } |
|
| 352 | + if (isset($query)) { |
|
| 353 | + $result = $this->db->query($query); |
|
| 354 | + if (DB::isError($result)) { |
|
| 355 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - return true; |
|
| 362 | - } |
|
| 361 | + return true; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | ?> |
| 365 | 365 | \ No newline at end of file |
@@ -60,305 +60,305 @@ |
||
| 60 | 60 | class HTTP_Session_Container_MDB extends HTTP_Session_Container |
| 61 | 61 | { |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * MDB connection object |
|
| 65 | - * |
|
| 66 | - * @var object MDB |
|
| 67 | - * @access private |
|
| 68 | - */ |
|
| 69 | - public $db = null; |
|
| 63 | + /** |
|
| 64 | + * MDB connection object |
|
| 65 | + * |
|
| 66 | + * @var object MDB |
|
| 67 | + * @access private |
|
| 68 | + */ |
|
| 69 | + public $db = null; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Session data cache id |
|
| 73 | - * |
|
| 74 | - * @var mixed |
|
| 75 | - * @access private |
|
| 76 | - */ |
|
| 77 | - public $crc = false; |
|
| 71 | + /** |
|
| 72 | + * Session data cache id |
|
| 73 | + * |
|
| 74 | + * @var mixed |
|
| 75 | + * @access private |
|
| 76 | + */ |
|
| 77 | + public $crc = false; |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Constructor method |
|
| 81 | - * |
|
| 82 | - * $options is an array with the options.<br> |
|
| 83 | - * The options are: |
|
| 84 | - * <ul> |
|
| 85 | - * <li>'dsn' - The DSN string</li> |
|
| 86 | - * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 87 | - * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 88 | - * the table on garbage collection, default is 'false'.</li> |
|
| 89 | - * </ul> |
|
| 90 | - * |
|
| 91 | - * @param array $options Options |
|
| 92 | - * |
|
| 93 | - * @access public |
|
| 94 | - * @return object |
|
| 95 | - */ |
|
| 96 | - public function HTTP_Session_Container_MDB($options) |
|
| 97 | - { |
|
| 98 | - $this->_setDefaults(); |
|
| 99 | - if (is_array($options)) { |
|
| 100 | - $this->_parseOptions($options); |
|
| 101 | - } else { |
|
| 102 | - $this->options['dsn'] = $options; |
|
| 103 | - } |
|
| 104 | - } |
|
| 79 | + /** |
|
| 80 | + * Constructor method |
|
| 81 | + * |
|
| 82 | + * $options is an array with the options.<br> |
|
| 83 | + * The options are: |
|
| 84 | + * <ul> |
|
| 85 | + * <li>'dsn' - The DSN string</li> |
|
| 86 | + * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 87 | + * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 88 | + * the table on garbage collection, default is 'false'.</li> |
|
| 89 | + * </ul> |
|
| 90 | + * |
|
| 91 | + * @param array $options Options |
|
| 92 | + * |
|
| 93 | + * @access public |
|
| 94 | + * @return object |
|
| 95 | + */ |
|
| 96 | + public function HTTP_Session_Container_MDB($options) |
|
| 97 | + { |
|
| 98 | + $this->_setDefaults(); |
|
| 99 | + if (is_array($options)) { |
|
| 100 | + $this->_parseOptions($options); |
|
| 101 | + } else { |
|
| 102 | + $this->options['dsn'] = $options; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Connect to database by using the given DSN string |
|
| 108 | - * |
|
| 109 | - * @param string $dsn DSN string |
|
| 110 | - * |
|
| 111 | - * @access private |
|
| 112 | - * @return mixed Object on error, otherwise bool |
|
| 113 | - */ |
|
| 114 | - public function _connect($dsn) |
|
| 115 | - { |
|
| 116 | - if (is_string($dsn) || is_array($dsn)) { |
|
| 117 | - $this->db = MDB::connect($dsn); |
|
| 118 | - } else if (is_object($dsn) && is_a($dsn, 'mdb_common')) { |
|
| 119 | - $this->db = $dsn; |
|
| 120 | - } else if (is_object($dsn) && MDB::isError($dsn)) { |
|
| 121 | - return new MDB_Error($dsn->code, PEAR_ERROR_DIE); |
|
| 122 | - } else { |
|
| 123 | - return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 124 | - . " at line " . __LINE__, |
|
| 125 | - 41, |
|
| 126 | - PEAR_ERROR_RETURN, |
|
| 127 | - null, |
|
| 128 | - null |
|
| 129 | - ); |
|
| 106 | + /** |
|
| 107 | + * Connect to database by using the given DSN string |
|
| 108 | + * |
|
| 109 | + * @param string $dsn DSN string |
|
| 110 | + * |
|
| 111 | + * @access private |
|
| 112 | + * @return mixed Object on error, otherwise bool |
|
| 113 | + */ |
|
| 114 | + public function _connect($dsn) |
|
| 115 | + { |
|
| 116 | + if (is_string($dsn) || is_array($dsn)) { |
|
| 117 | + $this->db = MDB::connect($dsn); |
|
| 118 | + } else if (is_object($dsn) && is_a($dsn, 'mdb_common')) { |
|
| 119 | + $this->db = $dsn; |
|
| 120 | + } else if (is_object($dsn) && MDB::isError($dsn)) { |
|
| 121 | + return new MDB_Error($dsn->code, PEAR_ERROR_DIE); |
|
| 122 | + } else { |
|
| 123 | + return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 124 | + . " at line " . __LINE__, |
|
| 125 | + 41, |
|
| 126 | + PEAR_ERROR_RETURN, |
|
| 127 | + null, |
|
| 128 | + null |
|
| 129 | + ); |
|
| 130 | 130 | |
| 131 | - } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - if (MDB::isError($this->db)) { |
|
| 134 | - return new MDB_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 135 | - } |
|
| 133 | + if (MDB::isError($this->db)) { |
|
| 134 | + return new MDB_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - return true; |
|
| 138 | - } |
|
| 137 | + return true; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Set some default options |
|
| 142 | - * |
|
| 143 | - * @access private |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - public function _setDefaults() |
|
| 147 | - { |
|
| 148 | - $this->options['dsn'] = null; |
|
| 149 | - $this->options['table'] = 'sessiondata'; |
|
| 150 | - $this->options['autooptimize'] = false; |
|
| 151 | - } |
|
| 140 | + /** |
|
| 141 | + * Set some default options |
|
| 142 | + * |
|
| 143 | + * @access private |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + public function _setDefaults() |
|
| 147 | + { |
|
| 148 | + $this->options['dsn'] = null; |
|
| 149 | + $this->options['table'] = 'sessiondata'; |
|
| 150 | + $this->options['autooptimize'] = false; |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Establish connection to a database |
|
| 155 | - * |
|
| 156 | - * @param string $save_path Save path |
|
| 157 | - * @param string $session_name Session name |
|
| 158 | - * |
|
| 159 | - * @return bool |
|
| 160 | - */ |
|
| 161 | - public function open($save_path, $session_name) |
|
| 162 | - { |
|
| 163 | - if (MDB::isError($this->_connect($this->options['dsn']))) { |
|
| 164 | - return false; |
|
| 165 | - } else { |
|
| 166 | - return true; |
|
| 167 | - } |
|
| 168 | - } |
|
| 153 | + /** |
|
| 154 | + * Establish connection to a database |
|
| 155 | + * |
|
| 156 | + * @param string $save_path Save path |
|
| 157 | + * @param string $session_name Session name |
|
| 158 | + * |
|
| 159 | + * @return bool |
|
| 160 | + */ |
|
| 161 | + public function open($save_path, $session_name) |
|
| 162 | + { |
|
| 163 | + if (MDB::isError($this->_connect($this->options['dsn']))) { |
|
| 164 | + return false; |
|
| 165 | + } else { |
|
| 166 | + return true; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Free resources |
|
| 172 | - * |
|
| 173 | - * @return bool |
|
| 174 | - */ |
|
| 175 | - public function close() |
|
| 176 | - { |
|
| 177 | - return true; |
|
| 178 | - } |
|
| 170 | + /** |
|
| 171 | + * Free resources |
|
| 172 | + * |
|
| 173 | + * @return bool |
|
| 174 | + */ |
|
| 175 | + public function close() |
|
| 176 | + { |
|
| 177 | + return true; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Read session data |
|
| 182 | - * |
|
| 183 | - * @param string $id Session id |
|
| 184 | - * |
|
| 185 | - * @return mixed |
|
| 186 | - */ |
|
| 187 | - public function read($id) |
|
| 188 | - { |
|
| 189 | - $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 190 | - $this->options['table'], |
|
| 191 | - $this->db->getTextValue(md5($id)), |
|
| 192 | - time()); |
|
| 193 | - $result = $this->db->getOne($query); |
|
| 194 | - if (MDB::isError($result)) { |
|
| 195 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - $this->crc = strlen($result) . crc32($result); |
|
| 199 | - return $result; |
|
| 200 | - } |
|
| 180 | + /** |
|
| 181 | + * Read session data |
|
| 182 | + * |
|
| 183 | + * @param string $id Session id |
|
| 184 | + * |
|
| 185 | + * @return mixed |
|
| 186 | + */ |
|
| 187 | + public function read($id) |
|
| 188 | + { |
|
| 189 | + $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 190 | + $this->options['table'], |
|
| 191 | + $this->db->getTextValue(md5($id)), |
|
| 192 | + time()); |
|
| 193 | + $result = $this->db->getOne($query); |
|
| 194 | + if (MDB::isError($result)) { |
|
| 195 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + $this->crc = strlen($result) . crc32($result); |
|
| 199 | + return $result; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Write session data |
|
| 204 | - * |
|
| 205 | - * @param string $id Session id |
|
| 206 | - * @param mixed $data Data |
|
| 207 | - * |
|
| 208 | - * @return bool |
|
| 209 | - */ |
|
| 210 | - public function write($id, $data) |
|
| 211 | - { |
|
| 212 | - if ((false !== $this->crc) && |
|
| 213 | - ($this->crc === strlen($data) . crc32($data))) { |
|
| 214 | - // $_SESSION hasn't been touched, no need to update the blob column |
|
| 215 | - $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 216 | - $this->options['table'], |
|
| 217 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 218 | - $this->db->getTextValue(md5($id))); |
|
| 219 | - } else { |
|
| 220 | - // Check if table row already exists |
|
| 221 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 222 | - $this->options['table'], |
|
| 223 | - $this->db->getTextValue(md5($id))); |
|
| 224 | - $result = $this->db->getOne($query); |
|
| 225 | - if (MDB::isError($result)) { |
|
| 226 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - if (0 == intval($result)) { |
|
| 230 | - // Insert new row into table |
|
| 231 | - $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 232 | - $this->options['table'], |
|
| 233 | - $this->db->getTextValue(md5($id)), |
|
| 234 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 235 | - $this->db->getTextValue($data)); |
|
| 236 | - } else { |
|
| 237 | - // Update existing row |
|
| 238 | - $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 239 | - $this->options['table'], |
|
| 240 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 241 | - $this->db->getTextValue($data), |
|
| 242 | - $this->db->getTextValue(md5($id))); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - $result = $this->db->query($query); |
|
| 246 | - if (MDB::isError($result)) { |
|
| 247 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 202 | + /** |
|
| 203 | + * Write session data |
|
| 204 | + * |
|
| 205 | + * @param string $id Session id |
|
| 206 | + * @param mixed $data Data |
|
| 207 | + * |
|
| 208 | + * @return bool |
|
| 209 | + */ |
|
| 210 | + public function write($id, $data) |
|
| 211 | + { |
|
| 212 | + if ((false !== $this->crc) && |
|
| 213 | + ($this->crc === strlen($data) . crc32($data))) { |
|
| 214 | + // $_SESSION hasn't been touched, no need to update the blob column |
|
| 215 | + $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 216 | + $this->options['table'], |
|
| 217 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 218 | + $this->db->getTextValue(md5($id))); |
|
| 219 | + } else { |
|
| 220 | + // Check if table row already exists |
|
| 221 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 222 | + $this->options['table'], |
|
| 223 | + $this->db->getTextValue(md5($id))); |
|
| 224 | + $result = $this->db->getOne($query); |
|
| 225 | + if (MDB::isError($result)) { |
|
| 226 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + if (0 == intval($result)) { |
|
| 230 | + // Insert new row into table |
|
| 231 | + $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 232 | + $this->options['table'], |
|
| 233 | + $this->db->getTextValue(md5($id)), |
|
| 234 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 235 | + $this->db->getTextValue($data)); |
|
| 236 | + } else { |
|
| 237 | + // Update existing row |
|
| 238 | + $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 239 | + $this->options['table'], |
|
| 240 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 241 | + $this->db->getTextValue($data), |
|
| 242 | + $this->db->getTextValue(md5($id))); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + $result = $this->db->query($query); |
|
| 246 | + if (MDB::isError($result)) { |
|
| 247 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - return true; |
|
| 252 | - } |
|
| 251 | + return true; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Destroy session data |
|
| 256 | - * |
|
| 257 | - * @param string $id Session id |
|
| 258 | - * |
|
| 259 | - * @return bool |
|
| 260 | - */ |
|
| 261 | - public function destroy($id) |
|
| 262 | - { |
|
| 263 | - $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 264 | - $this->options['table'], |
|
| 265 | - $this->db->getTextValue(md5($id))); |
|
| 266 | - $result = $this->db->query($query); |
|
| 267 | - if (MDB::isError($result)) { |
|
| 268 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 269 | - return false; |
|
| 270 | - } |
|
| 254 | + /** |
|
| 255 | + * Destroy session data |
|
| 256 | + * |
|
| 257 | + * @param string $id Session id |
|
| 258 | + * |
|
| 259 | + * @return bool |
|
| 260 | + */ |
|
| 261 | + public function destroy($id) |
|
| 262 | + { |
|
| 263 | + $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 264 | + $this->options['table'], |
|
| 265 | + $this->db->getTextValue(md5($id))); |
|
| 266 | + $result = $this->db->query($query); |
|
| 267 | + if (MDB::isError($result)) { |
|
| 268 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 269 | + return false; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - return true; |
|
| 273 | - } |
|
| 272 | + return true; |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 277 | - * |
|
| 278 | - * @param string $targetTable Table to replicate to |
|
| 279 | - * @param string $id Id of record to replicate |
|
| 280 | - * |
|
| 281 | - * @access private |
|
| 282 | - * @return bool |
|
| 283 | - */ |
|
| 284 | - public function replicate($targetTable, $id = null) |
|
| 285 | - { |
|
| 286 | - if (is_null($id)) { |
|
| 287 | - $id = HTTP_Session::id(); |
|
| 288 | - } |
|
| 275 | + /** |
|
| 276 | + * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 277 | + * |
|
| 278 | + * @param string $targetTable Table to replicate to |
|
| 279 | + * @param string $id Id of record to replicate |
|
| 280 | + * |
|
| 281 | + * @access private |
|
| 282 | + * @return bool |
|
| 283 | + */ |
|
| 284 | + public function replicate($targetTable, $id = null) |
|
| 285 | + { |
|
| 286 | + if (is_null($id)) { |
|
| 287 | + $id = HTTP_Session::id(); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - // Check if table row already exists |
|
| 291 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 292 | - $targetTable, |
|
| 293 | - $this->db->getTextValue(md5($id))); |
|
| 294 | - $result = $this->db->getOne($query); |
|
| 295 | - if (MDB::isError($result)) { |
|
| 296 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 297 | - return false; |
|
| 298 | - } |
|
| 290 | + // Check if table row already exists |
|
| 291 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 292 | + $targetTable, |
|
| 293 | + $this->db->getTextValue(md5($id))); |
|
| 294 | + $result = $this->db->getOne($query); |
|
| 295 | + if (MDB::isError($result)) { |
|
| 296 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 297 | + return false; |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - // Insert new row into dest table |
|
| 301 | - if (0 == intval($result)) { |
|
| 302 | - $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 303 | - $targetTable, |
|
| 304 | - $this->options['table'], |
|
| 305 | - $this->db->getTextValue(md5($id))); |
|
| 306 | - } else { |
|
| 307 | - // Update existing row |
|
| 308 | - $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | - $targetTable, |
|
| 310 | - $this->options['table'], |
|
| 311 | - $this->db->getTextValue(md5($id))); |
|
| 312 | - } |
|
| 300 | + // Insert new row into dest table |
|
| 301 | + if (0 == intval($result)) { |
|
| 302 | + $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 303 | + $targetTable, |
|
| 304 | + $this->options['table'], |
|
| 305 | + $this->db->getTextValue(md5($id))); |
|
| 306 | + } else { |
|
| 307 | + // Update existing row |
|
| 308 | + $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | + $targetTable, |
|
| 310 | + $this->options['table'], |
|
| 311 | + $this->db->getTextValue(md5($id))); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $result = $this->db->query($query); |
|
| 315 | - if (MDB::isError($result)) { |
|
| 316 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 317 | - return false; |
|
| 318 | - } |
|
| 314 | + $result = $this->db->query($query); |
|
| 315 | + if (MDB::isError($result)) { |
|
| 316 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 317 | + return false; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - return true; |
|
| 321 | - } |
|
| 320 | + return true; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - /** |
|
| 324 | - * Garbage collection |
|
| 325 | - * |
|
| 326 | - * @param int $maxlifetime Maximum lifetime |
|
| 327 | - * |
|
| 328 | - * @return bool |
|
| 329 | - */ |
|
| 330 | - public function gc($maxlifetime) |
|
| 331 | - { |
|
| 332 | - $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | - $this->options['table'], |
|
| 334 | - time()); |
|
| 335 | - $result = $this->db->query($query); |
|
| 336 | - if (MDB::isError($result)) { |
|
| 337 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 338 | - return false; |
|
| 339 | - } |
|
| 340 | - if ($this->options['autooptimize']) { |
|
| 341 | - switch($this->db->phptype) { |
|
| 342 | - case 'mysql': |
|
| 343 | - $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | - break; |
|
| 345 | - case 'pgsql': |
|
| 346 | - $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | - break; |
|
| 348 | - default: |
|
| 349 | - $query = null; |
|
| 350 | - break; |
|
| 351 | - } |
|
| 352 | - if (isset($query)) { |
|
| 353 | - $result = $this->db->query($query); |
|
| 354 | - if (MDB::isError($result)) { |
|
| 355 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 323 | + /** |
|
| 324 | + * Garbage collection |
|
| 325 | + * |
|
| 326 | + * @param int $maxlifetime Maximum lifetime |
|
| 327 | + * |
|
| 328 | + * @return bool |
|
| 329 | + */ |
|
| 330 | + public function gc($maxlifetime) |
|
| 331 | + { |
|
| 332 | + $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | + $this->options['table'], |
|
| 334 | + time()); |
|
| 335 | + $result = $this->db->query($query); |
|
| 336 | + if (MDB::isError($result)) { |
|
| 337 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + if ($this->options['autooptimize']) { |
|
| 341 | + switch($this->db->phptype) { |
|
| 342 | + case 'mysql': |
|
| 343 | + $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | + break; |
|
| 345 | + case 'pgsql': |
|
| 346 | + $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | + break; |
|
| 348 | + default: |
|
| 349 | + $query = null; |
|
| 350 | + break; |
|
| 351 | + } |
|
| 352 | + if (isset($query)) { |
|
| 353 | + $result = $this->db->query($query); |
|
| 354 | + if (MDB::isError($result)) { |
|
| 355 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - return true; |
|
| 362 | - } |
|
| 361 | + return true; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | ?> |
| 365 | 365 | \ No newline at end of file |
@@ -43,160 +43,160 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | class HTTP_Session_Container_Memcache extends HTTP_Session_Container |
| 45 | 45 | { |
| 46 | - /** |
|
| 47 | - * Memcache connection object |
|
| 48 | - * |
|
| 49 | - * @var object Memcache |
|
| 50 | - * @access private |
|
| 51 | - */ |
|
| 52 | - public $mc; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Constructor method |
|
| 56 | - * |
|
| 57 | - * $options is an array with the options.<br> |
|
| 58 | - * The options are: |
|
| 59 | - * <ul> |
|
| 60 | - * <li>'memcache' - Memcache object |
|
| 61 | - * <li>'prefix' - Key prefix, default is 'sessiondata:'</li> |
|
| 62 | - * </ul> |
|
| 63 | - * |
|
| 64 | - * @param array $options Options |
|
| 65 | - * |
|
| 66 | - * @access public |
|
| 67 | - * @return object |
|
| 68 | - */ |
|
| 69 | - public function HTTP_Session_Container_Memcache($options) |
|
| 70 | - { |
|
| 71 | - $this->_setDefaults(); |
|
| 72 | - |
|
| 73 | - if (is_array($options)) { |
|
| 74 | - $this->_parseOptions($options); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Connect to database by using the given DSN string |
|
| 80 | - * |
|
| 81 | - * @param string $mc Memcache object |
|
| 82 | - * |
|
| 83 | - * @access private |
|
| 84 | - * @return mixed Object on error, otherwise bool |
|
| 85 | - */ |
|
| 86 | - public function _connect($mc) |
|
| 87 | - { |
|
| 88 | - if (is_object($mc) && is_a($mc, 'Memcache')) { |
|
| 89 | - $this->mc = $mc; |
|
| 90 | - |
|
| 91 | - } else { |
|
| 92 | - |
|
| 93 | - return new PEAR_Error('The given memcache object was not valid in file ' |
|
| 94 | - . __FILE__ . ' at line ' . __LINE__, |
|
| 95 | - 41, |
|
| 96 | - PEAR_ERROR_RETURN, |
|
| 97 | - null, |
|
| 98 | - null |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - return true; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Set some default options |
|
| 107 | - * |
|
| 108 | - * @access private |
|
| 109 | - * @return void |
|
| 110 | - */ |
|
| 111 | - public function _setDefaults() |
|
| 112 | - { |
|
| 113 | - $this->options['prefix'] = 'sessiondata:'; |
|
| 114 | - $this->options['memcache'] = null; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Establish connection to a database |
|
| 119 | - * |
|
| 120 | - * @param string $save_path Save path |
|
| 121 | - * @param string $session_name Session name |
|
| 122 | - * |
|
| 123 | - * @access public |
|
| 124 | - * @return mixed Object on error, otherwise bool |
|
| 125 | - */ |
|
| 126 | - public function open($save_path, $session_name) |
|
| 127 | - { |
|
| 128 | - return $this->_connect($this->options['memcache']); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Free resources |
|
| 133 | - * |
|
| 134 | - * @access public |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - public function close() |
|
| 138 | - { |
|
| 139 | - return true; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Read session data |
|
| 144 | - * |
|
| 145 | - * @param string $id Session id |
|
| 146 | - * |
|
| 147 | - * @access public |
|
| 148 | - * @return mixed |
|
| 149 | - */ |
|
| 150 | - public function read($id) |
|
| 151 | - { |
|
| 152 | - $result = $this->mc->get($this->options['prefix'] . $id); |
|
| 153 | - return $result; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Write session data |
|
| 158 | - * |
|
| 159 | - * @param string $id Session id |
|
| 160 | - * @param mixed $data Session data |
|
| 161 | - * |
|
| 162 | - * @access public |
|
| 163 | - * @return bool |
|
| 164 | - */ |
|
| 165 | - public function write($id, $data) |
|
| 166 | - { |
|
| 167 | - $this->mc->set($this->options['prefix'] . $id, |
|
| 168 | - $data, |
|
| 169 | - MEMCACHE_COMPRESSED, |
|
| 170 | - time() + ini_get('session.gc_maxlifetime')); |
|
| 171 | - |
|
| 172 | - return true; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Destroy session data |
|
| 177 | - * |
|
| 178 | - * @param string $id Session id |
|
| 179 | - * |
|
| 180 | - * @access public |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - public function destroy($id) |
|
| 184 | - { |
|
| 185 | - $this->mc->delete($this->options['prefix'] . $id); |
|
| 186 | - return true; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Garbage collection |
|
| 191 | - * |
|
| 192 | - * @param int $maxlifetime Maximum lifetime |
|
| 193 | - * |
|
| 194 | - * @access public |
|
| 195 | - * @return bool |
|
| 196 | - */ |
|
| 197 | - public function gc($maxlifetime) |
|
| 198 | - { |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 46 | + /** |
|
| 47 | + * Memcache connection object |
|
| 48 | + * |
|
| 49 | + * @var object Memcache |
|
| 50 | + * @access private |
|
| 51 | + */ |
|
| 52 | + public $mc; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Constructor method |
|
| 56 | + * |
|
| 57 | + * $options is an array with the options.<br> |
|
| 58 | + * The options are: |
|
| 59 | + * <ul> |
|
| 60 | + * <li>'memcache' - Memcache object |
|
| 61 | + * <li>'prefix' - Key prefix, default is 'sessiondata:'</li> |
|
| 62 | + * </ul> |
|
| 63 | + * |
|
| 64 | + * @param array $options Options |
|
| 65 | + * |
|
| 66 | + * @access public |
|
| 67 | + * @return object |
|
| 68 | + */ |
|
| 69 | + public function HTTP_Session_Container_Memcache($options) |
|
| 70 | + { |
|
| 71 | + $this->_setDefaults(); |
|
| 72 | + |
|
| 73 | + if (is_array($options)) { |
|
| 74 | + $this->_parseOptions($options); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Connect to database by using the given DSN string |
|
| 80 | + * |
|
| 81 | + * @param string $mc Memcache object |
|
| 82 | + * |
|
| 83 | + * @access private |
|
| 84 | + * @return mixed Object on error, otherwise bool |
|
| 85 | + */ |
|
| 86 | + public function _connect($mc) |
|
| 87 | + { |
|
| 88 | + if (is_object($mc) && is_a($mc, 'Memcache')) { |
|
| 89 | + $this->mc = $mc; |
|
| 90 | + |
|
| 91 | + } else { |
|
| 92 | + |
|
| 93 | + return new PEAR_Error('The given memcache object was not valid in file ' |
|
| 94 | + . __FILE__ . ' at line ' . __LINE__, |
|
| 95 | + 41, |
|
| 96 | + PEAR_ERROR_RETURN, |
|
| 97 | + null, |
|
| 98 | + null |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + return true; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Set some default options |
|
| 107 | + * |
|
| 108 | + * @access private |
|
| 109 | + * @return void |
|
| 110 | + */ |
|
| 111 | + public function _setDefaults() |
|
| 112 | + { |
|
| 113 | + $this->options['prefix'] = 'sessiondata:'; |
|
| 114 | + $this->options['memcache'] = null; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Establish connection to a database |
|
| 119 | + * |
|
| 120 | + * @param string $save_path Save path |
|
| 121 | + * @param string $session_name Session name |
|
| 122 | + * |
|
| 123 | + * @access public |
|
| 124 | + * @return mixed Object on error, otherwise bool |
|
| 125 | + */ |
|
| 126 | + public function open($save_path, $session_name) |
|
| 127 | + { |
|
| 128 | + return $this->_connect($this->options['memcache']); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Free resources |
|
| 133 | + * |
|
| 134 | + * @access public |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + public function close() |
|
| 138 | + { |
|
| 139 | + return true; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Read session data |
|
| 144 | + * |
|
| 145 | + * @param string $id Session id |
|
| 146 | + * |
|
| 147 | + * @access public |
|
| 148 | + * @return mixed |
|
| 149 | + */ |
|
| 150 | + public function read($id) |
|
| 151 | + { |
|
| 152 | + $result = $this->mc->get($this->options['prefix'] . $id); |
|
| 153 | + return $result; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Write session data |
|
| 158 | + * |
|
| 159 | + * @param string $id Session id |
|
| 160 | + * @param mixed $data Session data |
|
| 161 | + * |
|
| 162 | + * @access public |
|
| 163 | + * @return bool |
|
| 164 | + */ |
|
| 165 | + public function write($id, $data) |
|
| 166 | + { |
|
| 167 | + $this->mc->set($this->options['prefix'] . $id, |
|
| 168 | + $data, |
|
| 169 | + MEMCACHE_COMPRESSED, |
|
| 170 | + time() + ini_get('session.gc_maxlifetime')); |
|
| 171 | + |
|
| 172 | + return true; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Destroy session data |
|
| 177 | + * |
|
| 178 | + * @param string $id Session id |
|
| 179 | + * |
|
| 180 | + * @access public |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + public function destroy($id) |
|
| 184 | + { |
|
| 185 | + $this->mc->delete($this->options['prefix'] . $id); |
|
| 186 | + return true; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Garbage collection |
|
| 191 | + * |
|
| 192 | + * @param int $maxlifetime Maximum lifetime |
|
| 193 | + * |
|
| 194 | + * @access public |
|
| 195 | + * @return bool |
|
| 196 | + */ |
|
| 197 | + public function gc($maxlifetime) |
|
| 198 | + { |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | 201 | } |
| 202 | 202 | ?> |
| 203 | 203 | \ No newline at end of file |
@@ -59,306 +59,306 @@ |
||
| 59 | 59 | */ |
| 60 | 60 | class HTTP_Session_Container_MDB2 extends HTTP_Session_Container |
| 61 | 61 | { |
| 62 | - /** |
|
| 63 | - * MDB2 connection object |
|
| 64 | - * |
|
| 65 | - * @var object MDB2 |
|
| 66 | - * @access private |
|
| 67 | - */ |
|
| 68 | - public $db = null; |
|
| 62 | + /** |
|
| 63 | + * MDB2 connection object |
|
| 64 | + * |
|
| 65 | + * @var object MDB2 |
|
| 66 | + * @access private |
|
| 67 | + */ |
|
| 68 | + public $db = null; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Session data cache id |
|
| 72 | - * |
|
| 73 | - * @var mixed |
|
| 74 | - * @access private |
|
| 75 | - */ |
|
| 76 | - public $crc = false; |
|
| 70 | + /** |
|
| 71 | + * Session data cache id |
|
| 72 | + * |
|
| 73 | + * @var mixed |
|
| 74 | + * @access private |
|
| 75 | + */ |
|
| 76 | + public $crc = false; |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Constructor method |
|
| 80 | - * |
|
| 81 | - * $options is an array with the options.<br> |
|
| 82 | - * The options are: |
|
| 83 | - * <ul> |
|
| 84 | - * <li>'dsn' - The DSN string</li> |
|
| 85 | - * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 86 | - * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 87 | - * the table on garbage collection, default is 'false'.</li> |
|
| 88 | - * </ul> |
|
| 89 | - * |
|
| 90 | - * @param array $options Options |
|
| 91 | - * |
|
| 92 | - * @access public |
|
| 93 | - * @return void |
|
| 94 | - */ |
|
| 95 | - public function HTTP_Session_Container_MDB2($options) |
|
| 96 | - { |
|
| 97 | - $this->_setDefaults(); |
|
| 98 | - if (is_array($options)) { |
|
| 99 | - $this->_parseOptions($options); |
|
| 100 | - } else { |
|
| 101 | - $this->options['dsn'] = $options; |
|
| 102 | - } |
|
| 103 | - } |
|
| 78 | + /** |
|
| 79 | + * Constructor method |
|
| 80 | + * |
|
| 81 | + * $options is an array with the options.<br> |
|
| 82 | + * The options are: |
|
| 83 | + * <ul> |
|
| 84 | + * <li>'dsn' - The DSN string</li> |
|
| 85 | + * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 86 | + * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 87 | + * the table on garbage collection, default is 'false'.</li> |
|
| 88 | + * </ul> |
|
| 89 | + * |
|
| 90 | + * @param array $options Options |
|
| 91 | + * |
|
| 92 | + * @access public |
|
| 93 | + * @return void |
|
| 94 | + */ |
|
| 95 | + public function HTTP_Session_Container_MDB2($options) |
|
| 96 | + { |
|
| 97 | + $this->_setDefaults(); |
|
| 98 | + if (is_array($options)) { |
|
| 99 | + $this->_parseOptions($options); |
|
| 100 | + } else { |
|
| 101 | + $this->options['dsn'] = $options; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Connect to database by using the given DSN string |
|
| 107 | - * |
|
| 108 | - * @param string $dsn DSN string |
|
| 109 | - * |
|
| 110 | - * @access private |
|
| 111 | - * @return mixed Object on error, otherwise bool |
|
| 112 | - */ |
|
| 113 | - public function _connect($dsn) |
|
| 114 | - { |
|
| 115 | - if (is_string($dsn) || is_array($dsn)) { |
|
| 116 | - $this->db = MDB2::connect($dsn); |
|
| 117 | - } else if (is_object($dsn) && is_a($dsn, 'MDB2_Driver_Common')) { |
|
| 118 | - $this->db = $dsn; |
|
| 119 | - } else if (is_object($dsn) && MDB2::isError($dsn)) { |
|
| 120 | - return $dsn; |
|
| 121 | - } else { |
|
| 122 | - return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 123 | - . " at line " . __LINE__, |
|
| 124 | - 41, |
|
| 125 | - PEAR_ERROR_RETURN, |
|
| 126 | - null, |
|
| 127 | - null |
|
| 128 | - ); |
|
| 105 | + /** |
|
| 106 | + * Connect to database by using the given DSN string |
|
| 107 | + * |
|
| 108 | + * @param string $dsn DSN string |
|
| 109 | + * |
|
| 110 | + * @access private |
|
| 111 | + * @return mixed Object on error, otherwise bool |
|
| 112 | + */ |
|
| 113 | + public function _connect($dsn) |
|
| 114 | + { |
|
| 115 | + if (is_string($dsn) || is_array($dsn)) { |
|
| 116 | + $this->db = MDB2::connect($dsn); |
|
| 117 | + } else if (is_object($dsn) && is_a($dsn, 'MDB2_Driver_Common')) { |
|
| 118 | + $this->db = $dsn; |
|
| 119 | + } else if (is_object($dsn) && MDB2::isError($dsn)) { |
|
| 120 | + return $dsn; |
|
| 121 | + } else { |
|
| 122 | + return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 123 | + . " at line " . __LINE__, |
|
| 124 | + 41, |
|
| 125 | + PEAR_ERROR_RETURN, |
|
| 126 | + null, |
|
| 127 | + null |
|
| 128 | + ); |
|
| 129 | 129 | |
| 130 | - } |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - if (MDB2::isError($this->db)) { |
|
| 133 | - return new MDB2_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 134 | - } |
|
| 132 | + if (MDB2::isError($this->db)) { |
|
| 133 | + return new MDB2_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - return true; |
|
| 137 | - } |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Set some default options |
|
| 141 | - * |
|
| 142 | - * @access private |
|
| 143 | - * @return void |
|
| 144 | - */ |
|
| 145 | - public function _setDefaults() |
|
| 146 | - { |
|
| 147 | - $this->options['dsn'] = null; |
|
| 148 | - $this->options['table'] = 'sessiondata'; |
|
| 149 | - $this->options['autooptimize'] = false; |
|
| 150 | - } |
|
| 139 | + /** |
|
| 140 | + * Set some default options |
|
| 141 | + * |
|
| 142 | + * @access private |
|
| 143 | + * @return void |
|
| 144 | + */ |
|
| 145 | + public function _setDefaults() |
|
| 146 | + { |
|
| 147 | + $this->options['dsn'] = null; |
|
| 148 | + $this->options['table'] = 'sessiondata'; |
|
| 149 | + $this->options['autooptimize'] = false; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Establish connection to a database |
|
| 154 | - * |
|
| 155 | - * @param string $save_path Save path |
|
| 156 | - * @param string $session_name Session name |
|
| 157 | - * |
|
| 158 | - * @return bool |
|
| 159 | - */ |
|
| 160 | - public function open($save_path, $session_name) |
|
| 161 | - { |
|
| 162 | - if (MDB2::isError($this->_connect($this->options['dsn']))) { |
|
| 163 | - return false; |
|
| 164 | - } else { |
|
| 165 | - return true; |
|
| 166 | - } |
|
| 167 | - } |
|
| 152 | + /** |
|
| 153 | + * Establish connection to a database |
|
| 154 | + * |
|
| 155 | + * @param string $save_path Save path |
|
| 156 | + * @param string $session_name Session name |
|
| 157 | + * |
|
| 158 | + * @return bool |
|
| 159 | + */ |
|
| 160 | + public function open($save_path, $session_name) |
|
| 161 | + { |
|
| 162 | + if (MDB2::isError($this->_connect($this->options['dsn']))) { |
|
| 163 | + return false; |
|
| 164 | + } else { |
|
| 165 | + return true; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Free resources |
|
| 171 | - * |
|
| 172 | - * @return bool |
|
| 173 | - */ |
|
| 174 | - public function close() |
|
| 175 | - { |
|
| 176 | - return true; |
|
| 177 | - } |
|
| 169 | + /** |
|
| 170 | + * Free resources |
|
| 171 | + * |
|
| 172 | + * @return bool |
|
| 173 | + */ |
|
| 174 | + public function close() |
|
| 175 | + { |
|
| 176 | + return true; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * Read session data |
|
| 181 | - * |
|
| 182 | - * @param string $id Session id |
|
| 183 | - * |
|
| 184 | - * @return mixed |
|
| 185 | - */ |
|
| 186 | - public function read($id) |
|
| 187 | - { |
|
| 188 | - $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 189 | - $this->options['table'], |
|
| 190 | - $this->db->quote(md5($id), 'text'), |
|
| 191 | - time()); |
|
| 192 | - $result = $this->db->queryOne($query); |
|
| 193 | - if (MDB2::isError($result)) { |
|
| 194 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - $this->crc = strlen($result) . crc32($result); |
|
| 198 | - return $result; |
|
| 199 | - } |
|
| 179 | + /** |
|
| 180 | + * Read session data |
|
| 181 | + * |
|
| 182 | + * @param string $id Session id |
|
| 183 | + * |
|
| 184 | + * @return mixed |
|
| 185 | + */ |
|
| 186 | + public function read($id) |
|
| 187 | + { |
|
| 188 | + $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 189 | + $this->options['table'], |
|
| 190 | + $this->db->quote(md5($id), 'text'), |
|
| 191 | + time()); |
|
| 192 | + $result = $this->db->queryOne($query); |
|
| 193 | + if (MDB2::isError($result)) { |
|
| 194 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + $this->crc = strlen($result) . crc32($result); |
|
| 198 | + return $result; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Write session data |
|
| 203 | - * |
|
| 204 | - * @param string $id Session id |
|
| 205 | - * @param mixed $data Data |
|
| 206 | - * |
|
| 207 | - * @return bool |
|
| 208 | - */ |
|
| 209 | - public function write($id, $data) |
|
| 210 | - { |
|
| 211 | - if ((false !== $this->crc) && |
|
| 212 | - ($this->crc === strlen($data) . crc32($data))) { |
|
| 213 | - // $_SESSION hasn't been touched, no need to update the blob column |
|
| 214 | - $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 215 | - $this->options['table'], |
|
| 216 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 217 | - $this->db->quote(md5($id), 'text')); |
|
| 218 | - } else { |
|
| 219 | - // Check if table row already exists |
|
| 220 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 221 | - $this->options['table'], |
|
| 222 | - $this->db->quote(md5($id), 'text')); |
|
| 223 | - $result = $this->db->queryOne($query); |
|
| 224 | - if (MDB2::isError($result)) { |
|
| 225 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - if (0 == intval($result)) { |
|
| 229 | - // Insert new row into table |
|
| 230 | - $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 231 | - $this->options['table'], |
|
| 232 | - $this->db->quote(md5($id), 'text'), |
|
| 233 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 234 | - $this->db->quote($data, 'text')); |
|
| 235 | - } else { |
|
| 236 | - // Update existing row |
|
| 237 | - $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 238 | - $this->options['table'], |
|
| 239 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 240 | - $this->db->quote($data, 'text'), |
|
| 241 | - $this->db->quote(md5($id), 'text')); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - $result = $this->db->query($query); |
|
| 245 | - if (MDB2::isError($result)) { |
|
| 246 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 247 | - return false; |
|
| 248 | - } |
|
| 201 | + /** |
|
| 202 | + * Write session data |
|
| 203 | + * |
|
| 204 | + * @param string $id Session id |
|
| 205 | + * @param mixed $data Data |
|
| 206 | + * |
|
| 207 | + * @return bool |
|
| 208 | + */ |
|
| 209 | + public function write($id, $data) |
|
| 210 | + { |
|
| 211 | + if ((false !== $this->crc) && |
|
| 212 | + ($this->crc === strlen($data) . crc32($data))) { |
|
| 213 | + // $_SESSION hasn't been touched, no need to update the blob column |
|
| 214 | + $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 215 | + $this->options['table'], |
|
| 216 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 217 | + $this->db->quote(md5($id), 'text')); |
|
| 218 | + } else { |
|
| 219 | + // Check if table row already exists |
|
| 220 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 221 | + $this->options['table'], |
|
| 222 | + $this->db->quote(md5($id), 'text')); |
|
| 223 | + $result = $this->db->queryOne($query); |
|
| 224 | + if (MDB2::isError($result)) { |
|
| 225 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + if (0 == intval($result)) { |
|
| 229 | + // Insert new row into table |
|
| 230 | + $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 231 | + $this->options['table'], |
|
| 232 | + $this->db->quote(md5($id), 'text'), |
|
| 233 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 234 | + $this->db->quote($data, 'text')); |
|
| 235 | + } else { |
|
| 236 | + // Update existing row |
|
| 237 | + $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 238 | + $this->options['table'], |
|
| 239 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 240 | + $this->db->quote($data, 'text'), |
|
| 241 | + $this->db->quote(md5($id), 'text')); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + $result = $this->db->query($query); |
|
| 245 | + if (MDB2::isError($result)) { |
|
| 246 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - return true; |
|
| 251 | - } |
|
| 250 | + return true; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Destroy session data |
|
| 255 | - * |
|
| 256 | - * @param string $id Session id |
|
| 257 | - * |
|
| 258 | - * @return bool |
|
| 259 | - */ |
|
| 260 | - public function destroy($id) |
|
| 261 | - { |
|
| 262 | - $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 263 | - $this->options['table'], |
|
| 264 | - $this->db->quote(md5($id), 'text')); |
|
| 265 | - $result = $this->db->query($query); |
|
| 266 | - if (MDB2::isError($result)) { |
|
| 267 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 268 | - return false; |
|
| 269 | - } |
|
| 253 | + /** |
|
| 254 | + * Destroy session data |
|
| 255 | + * |
|
| 256 | + * @param string $id Session id |
|
| 257 | + * |
|
| 258 | + * @return bool |
|
| 259 | + */ |
|
| 260 | + public function destroy($id) |
|
| 261 | + { |
|
| 262 | + $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 263 | + $this->options['table'], |
|
| 264 | + $this->db->quote(md5($id), 'text')); |
|
| 265 | + $result = $this->db->query($query); |
|
| 266 | + if (MDB2::isError($result)) { |
|
| 267 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 268 | + return false; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - return true; |
|
| 272 | - } |
|
| 271 | + return true; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 276 | - * |
|
| 277 | - * @param string $targetTable Table to replicate to |
|
| 278 | - * @param string $id Id of record to replicate |
|
| 279 | - * |
|
| 280 | - * @access private |
|
| 281 | - * @return bool |
|
| 282 | - */ |
|
| 283 | - public function replicate($targetTable, $id = null) |
|
| 284 | - { |
|
| 285 | - if (is_null($id)) { |
|
| 286 | - $id = HTTP_Session::id(); |
|
| 287 | - } |
|
| 274 | + /** |
|
| 275 | + * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 276 | + * |
|
| 277 | + * @param string $targetTable Table to replicate to |
|
| 278 | + * @param string $id Id of record to replicate |
|
| 279 | + * |
|
| 280 | + * @access private |
|
| 281 | + * @return bool |
|
| 282 | + */ |
|
| 283 | + public function replicate($targetTable, $id = null) |
|
| 284 | + { |
|
| 285 | + if (is_null($id)) { |
|
| 286 | + $id = HTTP_Session::id(); |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - // Check if table row already exists |
|
| 290 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 291 | - $targetTable, |
|
| 292 | - $this->db->quote(md5($id), 'text')); |
|
| 293 | - $result = $this->db->queryOne($query); |
|
| 294 | - if (MDB2::isError($result)) { |
|
| 295 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 296 | - return false; |
|
| 297 | - } |
|
| 289 | + // Check if table row already exists |
|
| 290 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 291 | + $targetTable, |
|
| 292 | + $this->db->quote(md5($id), 'text')); |
|
| 293 | + $result = $this->db->queryOne($query); |
|
| 294 | + if (MDB2::isError($result)) { |
|
| 295 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 296 | + return false; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - // Insert new row into dest table |
|
| 300 | - if (0 == intval($result)) { |
|
| 301 | - $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 302 | - $targetTable, |
|
| 303 | - $this->options['table'], |
|
| 304 | - $this->db->quote(md5($id), 'text')); |
|
| 299 | + // Insert new row into dest table |
|
| 300 | + if (0 == intval($result)) { |
|
| 301 | + $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 302 | + $targetTable, |
|
| 303 | + $this->options['table'], |
|
| 304 | + $this->db->quote(md5($id), 'text')); |
|
| 305 | 305 | |
| 306 | - } else { |
|
| 307 | - // Update existing row |
|
| 308 | - $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | - $targetTable, |
|
| 310 | - $this->options['table'], |
|
| 311 | - $this->db->quote(md5($id), 'text')); |
|
| 312 | - } |
|
| 306 | + } else { |
|
| 307 | + // Update existing row |
|
| 308 | + $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | + $targetTable, |
|
| 310 | + $this->options['table'], |
|
| 311 | + $this->db->quote(md5($id), 'text')); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $result = $this->db->query($query); |
|
| 315 | - if (MDB2::isError($result)) { |
|
| 316 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 317 | - return false; |
|
| 318 | - } |
|
| 314 | + $result = $this->db->query($query); |
|
| 315 | + if (MDB2::isError($result)) { |
|
| 316 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 317 | + return false; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - return true; |
|
| 321 | - } |
|
| 320 | + return true; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - /** |
|
| 324 | - * Garbage collection |
|
| 325 | - * |
|
| 326 | - * @param int $maxlifetime Maximum lifetime |
|
| 327 | - * |
|
| 328 | - * @return bool |
|
| 329 | - */ |
|
| 330 | - public function gc($maxlifetime) |
|
| 331 | - { |
|
| 332 | - $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | - $this->options['table'], |
|
| 334 | - time()); |
|
| 335 | - $result = $this->db->query($query); |
|
| 336 | - if (MDB2::isError($result)) { |
|
| 337 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 338 | - return false; |
|
| 339 | - } |
|
| 340 | - if ($this->options['autooptimize']) { |
|
| 341 | - switch($this->db->phptype) { |
|
| 342 | - case 'mysql': |
|
| 343 | - $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | - break; |
|
| 345 | - case 'pgsql': |
|
| 346 | - $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | - break; |
|
| 348 | - default: |
|
| 349 | - $query = null; |
|
| 350 | - break; |
|
| 351 | - } |
|
| 352 | - if (isset($query)) { |
|
| 353 | - $result = $this->db->query($query); |
|
| 354 | - if (MDB2::isError($result)) { |
|
| 355 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 323 | + /** |
|
| 324 | + * Garbage collection |
|
| 325 | + * |
|
| 326 | + * @param int $maxlifetime Maximum lifetime |
|
| 327 | + * |
|
| 328 | + * @return bool |
|
| 329 | + */ |
|
| 330 | + public function gc($maxlifetime) |
|
| 331 | + { |
|
| 332 | + $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | + $this->options['table'], |
|
| 334 | + time()); |
|
| 335 | + $result = $this->db->query($query); |
|
| 336 | + if (MDB2::isError($result)) { |
|
| 337 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + if ($this->options['autooptimize']) { |
|
| 341 | + switch($this->db->phptype) { |
|
| 342 | + case 'mysql': |
|
| 343 | + $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | + break; |
|
| 345 | + case 'pgsql': |
|
| 346 | + $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | + break; |
|
| 348 | + default: |
|
| 349 | + $query = null; |
|
| 350 | + break; |
|
| 351 | + } |
|
| 352 | + if (isset($query)) { |
|
| 353 | + $result = $this->db->query($query); |
|
| 354 | + if (MDB2::isError($result)) { |
|
| 355 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - return true; |
|
| 362 | - } |
|
| 361 | + return true; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | ?> |
| 365 | 365 | \ No newline at end of file |
@@ -23,17 +23,17 @@ discard block |
||
| 23 | 23 | if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); |
| 24 | 24 | |
| 25 | 25 | if (!defined('LOG4PHP_LINE_SEP')) { |
| 26 | - if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 27 | - /** |
|
| 28 | - * @ignore |
|
| 29 | - */ |
|
| 30 | - define('LOG4PHP_LINE_SEP', "\r\n"); |
|
| 31 | - } else { |
|
| 32 | - /** |
|
| 33 | - * @ignore |
|
| 34 | - */ |
|
| 35 | - define('LOG4PHP_LINE_SEP', "\n"); |
|
| 36 | - } |
|
| 26 | + if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 27 | + /** |
|
| 28 | + * @ignore |
|
| 29 | + */ |
|
| 30 | + define('LOG4PHP_LINE_SEP', "\r\n"); |
|
| 31 | + } else { |
|
| 32 | + /** |
|
| 33 | + * @ignore |
|
| 34 | + */ |
|
| 35 | + define('LOG4PHP_LINE_SEP', "\n"); |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -53,204 +53,204 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | class LoggerLayoutHtml extends LoggerLayout { |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 58 | - * default, it is set to false which means there will be no location |
|
| 59 | - * information output by this layout. If the the option is set to |
|
| 60 | - * true, then the file name and line number of the statement |
|
| 61 | - * at the origin of the log statement will be output. |
|
| 62 | - * |
|
| 63 | - * <p>If you are embedding this layout within a {@link LoggerAppenderMail} |
|
| 64 | - * or a {@link LoggerAppenderMailEvent} then make sure to set the |
|
| 65 | - * <b>LocationInfo</b> option of that appender as well. |
|
| 66 | - * @var boolean |
|
| 67 | - */ |
|
| 68 | - public $locationInfo = false; |
|
| 56 | + /** |
|
| 57 | + * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 58 | + * default, it is set to false which means there will be no location |
|
| 59 | + * information output by this layout. If the the option is set to |
|
| 60 | + * true, then the file name and line number of the statement |
|
| 61 | + * at the origin of the log statement will be output. |
|
| 62 | + * |
|
| 63 | + * <p>If you are embedding this layout within a {@link LoggerAppenderMail} |
|
| 64 | + * or a {@link LoggerAppenderMailEvent} then make sure to set the |
|
| 65 | + * <b>LocationInfo</b> option of that appender as well. |
|
| 66 | + * @var boolean |
|
| 67 | + */ |
|
| 68 | + public $locationInfo = false; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * The <b>Title</b> option takes a String value. This option sets the |
|
| 72 | - * document title of the generated HTML document. |
|
| 73 | - * Defaults to 'Log4php Log Messages'. |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $title = "Log4php Log Messages"; |
|
| 70 | + /** |
|
| 71 | + * The <b>Title</b> option takes a String value. This option sets the |
|
| 72 | + * document title of the generated HTML document. |
|
| 73 | + * Defaults to 'Log4php Log Messages'. |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $title = "Log4php Log Messages"; |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Constructor |
|
| 80 | - */ |
|
| 81 | - public function LoggerLayoutHtml() |
|
| 82 | - { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 78 | + /** |
|
| 79 | + * Constructor |
|
| 80 | + */ |
|
| 81 | + public function LoggerLayoutHtml() |
|
| 82 | + { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 88 | - * default, it is set to false which means there will be no location |
|
| 89 | - * information output by this layout. If the the option is set to |
|
| 90 | - * true, then the file name and line number of the statement |
|
| 91 | - * at the origin of the log statement will be output. |
|
| 92 | - * |
|
| 93 | - * <p>If you are embedding this layout within a {@link LoggerAppenderMail} |
|
| 94 | - * or a {@link LoggerAppenderMailEvent} then make sure to set the |
|
| 95 | - * <b>LocationInfo</b> option of that appender as well. |
|
| 96 | - */ |
|
| 97 | - public function setLocationInfo($flag) |
|
| 98 | - { |
|
| 99 | - if (is_bool($flag)) { |
|
| 100 | - $this->locationInfo = $flag; |
|
| 101 | - } else { |
|
| 102 | - $this->locationInfo = (bool)(strtolower($flag) == 'true'); |
|
| 103 | - } |
|
| 104 | - } |
|
| 86 | + /** |
|
| 87 | + * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 88 | + * default, it is set to false which means there will be no location |
|
| 89 | + * information output by this layout. If the the option is set to |
|
| 90 | + * true, then the file name and line number of the statement |
|
| 91 | + * at the origin of the log statement will be output. |
|
| 92 | + * |
|
| 93 | + * <p>If you are embedding this layout within a {@link LoggerAppenderMail} |
|
| 94 | + * or a {@link LoggerAppenderMailEvent} then make sure to set the |
|
| 95 | + * <b>LocationInfo</b> option of that appender as well. |
|
| 96 | + */ |
|
| 97 | + public function setLocationInfo($flag) |
|
| 98 | + { |
|
| 99 | + if (is_bool($flag)) { |
|
| 100 | + $this->locationInfo = $flag; |
|
| 101 | + } else { |
|
| 102 | + $this->locationInfo = (bool)(strtolower($flag) == 'true'); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Returns the current value of the <b>LocationInfo</b> option. |
|
| 108 | - */ |
|
| 109 | - public function getLocationInfo() |
|
| 110 | - { |
|
| 111 | - return $this->locationInfo; |
|
| 112 | - } |
|
| 106 | + /** |
|
| 107 | + * Returns the current value of the <b>LocationInfo</b> option. |
|
| 108 | + */ |
|
| 109 | + public function getLocationInfo() |
|
| 110 | + { |
|
| 111 | + return $this->locationInfo; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * The <b>Title</b> option takes a String value. This option sets the |
|
| 116 | - * document title of the generated HTML document. |
|
| 117 | - * Defaults to 'Log4php Log Messages'. |
|
| 118 | - */ |
|
| 119 | - public function setTitle($title) |
|
| 120 | - { |
|
| 121 | - $this->title = $title; |
|
| 122 | - } |
|
| 114 | + /** |
|
| 115 | + * The <b>Title</b> option takes a String value. This option sets the |
|
| 116 | + * document title of the generated HTML document. |
|
| 117 | + * Defaults to 'Log4php Log Messages'. |
|
| 118 | + */ |
|
| 119 | + public function setTitle($title) |
|
| 120 | + { |
|
| 121 | + $this->title = $title; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * @return string Returns the current value of the <b>Title</b> option. |
|
| 126 | - */ |
|
| 127 | - public function getTitle() |
|
| 128 | - { |
|
| 129 | - return $this->title; |
|
| 130 | - } |
|
| 124 | + /** |
|
| 125 | + * @return string Returns the current value of the <b>Title</b> option. |
|
| 126 | + */ |
|
| 127 | + public function getTitle() |
|
| 128 | + { |
|
| 129 | + return $this->title; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * @return string Returns the content type output by this layout, i.e "text/html". |
|
| 134 | - */ |
|
| 135 | - public function getContentType() |
|
| 136 | - { |
|
| 137 | - return "text/html"; |
|
| 138 | - } |
|
| 132 | + /** |
|
| 133 | + * @return string Returns the content type output by this layout, i.e "text/html". |
|
| 134 | + */ |
|
| 135 | + public function getContentType() |
|
| 136 | + { |
|
| 137 | + return "text/html"; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * No options to activate. |
|
| 142 | - */ |
|
| 143 | - public function activateOptions() |
|
| 144 | - { |
|
| 145 | - return true; |
|
| 146 | - } |
|
| 140 | + /** |
|
| 141 | + * No options to activate. |
|
| 142 | + */ |
|
| 143 | + public function activateOptions() |
|
| 144 | + { |
|
| 145 | + return true; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * @param LoggerLoggingEvent $event |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - public function format($event) |
|
| 153 | - { |
|
| 154 | - $sbuf = LOG4PHP_LINE_SEP . "<tr>" . LOG4PHP_LINE_SEP; |
|
| 148 | + /** |
|
| 149 | + * @param LoggerLoggingEvent $event |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + public function format($event) |
|
| 153 | + { |
|
| 154 | + $sbuf = LOG4PHP_LINE_SEP . "<tr>" . LOG4PHP_LINE_SEP; |
|
| 155 | 155 | |
| 156 | - $sbuf .= "<td>"; |
|
| 156 | + $sbuf .= "<td>"; |
|
| 157 | 157 | |
| 158 | - $eventTime = (float)$event->getTimeStamp(); |
|
| 159 | - $eventStartTime = (float)LoggerLoggingEvent::getStartTime(); |
|
| 160 | - $sbuf .= number_format(($eventTime - $eventStartTime) * 1000, 0, '', ''); |
|
| 161 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 158 | + $eventTime = (float)$event->getTimeStamp(); |
|
| 159 | + $eventStartTime = (float)LoggerLoggingEvent::getStartTime(); |
|
| 160 | + $sbuf .= number_format(($eventTime - $eventStartTime) * 1000, 0, '', ''); |
|
| 161 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 162 | 162 | |
| 163 | - $sbuf .= "<td title=\"" . $event->getThreadName() . " thread\">"; |
|
| 164 | - $sbuf .= $event->getThreadName(); |
|
| 165 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 163 | + $sbuf .= "<td title=\"" . $event->getThreadName() . " thread\">"; |
|
| 164 | + $sbuf .= $event->getThreadName(); |
|
| 165 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 166 | 166 | |
| 167 | - $sbuf .= "<td title=\"Level\">"; |
|
| 167 | + $sbuf .= "<td title=\"Level\">"; |
|
| 168 | 168 | |
| 169 | - $level = $event->getLevel(); |
|
| 169 | + $level = $event->getLevel(); |
|
| 170 | 170 | |
| 171 | - if ($level->equals(LoggerLevel::getLevelDebug())) { |
|
| 172 | - $sbuf .= "<font color=\"#339933\">"; |
|
| 173 | - $sbuf .= $level->toString(); |
|
| 174 | - $sbuf .= "</font>"; |
|
| 175 | - }elseif($level->equals(LoggerLevel::getLevelWarn())) { |
|
| 176 | - $sbuf .= "<font color=\"#993300\"><strong>"; |
|
| 177 | - $sbuf .= $level->toString(); |
|
| 178 | - $sbuf .= "</strong></font>"; |
|
| 179 | - } else { |
|
| 180 | - $sbuf .= $level->toString(); |
|
| 181 | - } |
|
| 182 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 171 | + if ($level->equals(LoggerLevel::getLevelDebug())) { |
|
| 172 | + $sbuf .= "<font color=\"#339933\">"; |
|
| 173 | + $sbuf .= $level->toString(); |
|
| 174 | + $sbuf .= "</font>"; |
|
| 175 | + }elseif($level->equals(LoggerLevel::getLevelWarn())) { |
|
| 176 | + $sbuf .= "<font color=\"#993300\"><strong>"; |
|
| 177 | + $sbuf .= $level->toString(); |
|
| 178 | + $sbuf .= "</strong></font>"; |
|
| 179 | + } else { |
|
| 180 | + $sbuf .= $level->toString(); |
|
| 181 | + } |
|
| 182 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 183 | 183 | |
| 184 | - $sbuf .= "<td title=\"" . htmlentities($event->getLoggerName(), ENT_QUOTES) . " category\">"; |
|
| 185 | - $sbuf .= htmlentities($event->getLoggerName(), ENT_QUOTES); |
|
| 186 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 184 | + $sbuf .= "<td title=\"" . htmlentities($event->getLoggerName(), ENT_QUOTES) . " category\">"; |
|
| 185 | + $sbuf .= htmlentities($event->getLoggerName(), ENT_QUOTES); |
|
| 186 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 187 | 187 | |
| 188 | - if ($this->locationInfo) { |
|
| 189 | - $locInfo = $event->getLocationInformation(); |
|
| 190 | - $sbuf .= "<td>"; |
|
| 191 | - $sbuf .= htmlentities($locInfo->getFileName(), ENT_QUOTES). ':' . $locInfo->getLineNumber(); |
|
| 192 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 193 | - } |
|
| 188 | + if ($this->locationInfo) { |
|
| 189 | + $locInfo = $event->getLocationInformation(); |
|
| 190 | + $sbuf .= "<td>"; |
|
| 191 | + $sbuf .= htmlentities($locInfo->getFileName(), ENT_QUOTES). ':' . $locInfo->getLineNumber(); |
|
| 192 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - $sbuf .= "<td title=\"Message\">"; |
|
| 196 | - $sbuf .= htmlentities($event->getRenderedMessage(), ENT_QUOTES); |
|
| 197 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 195 | + $sbuf .= "<td title=\"Message\">"; |
|
| 196 | + $sbuf .= htmlentities($event->getRenderedMessage(), ENT_QUOTES); |
|
| 197 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 198 | 198 | |
| 199 | - $sbuf .= "</tr>" . LOG4PHP_LINE_SEP; |
|
| 199 | + $sbuf .= "</tr>" . LOG4PHP_LINE_SEP; |
|
| 200 | 200 | |
| 201 | - if ($event->getNDC() != null) { |
|
| 202 | - $sbuf .= "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">"; |
|
| 203 | - $sbuf .= "NDC: " . htmlentities($event->getNDC(), ENT_QUOTES); |
|
| 204 | - $sbuf .= "</td></tr>" . LOG4PHP_LINE_SEP; |
|
| 205 | - } |
|
| 201 | + if ($event->getNDC() != null) { |
|
| 202 | + $sbuf .= "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">"; |
|
| 203 | + $sbuf .= "NDC: " . htmlentities($event->getNDC(), ENT_QUOTES); |
|
| 204 | + $sbuf .= "</td></tr>" . LOG4PHP_LINE_SEP; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - return $sbuf; |
|
| 208 | - } |
|
| 207 | + return $sbuf; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * @return string Returns appropriate HTML headers. |
|
| 212 | - */ |
|
| 213 | - public function getHeader() |
|
| 214 | - { |
|
| 215 | - $sbuf = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" . LOG4PHP_LINE_SEP; |
|
| 216 | - $sbuf .= "<html>" . LOG4PHP_LINE_SEP; |
|
| 217 | - $sbuf .= "<head>" . LOG4PHP_LINE_SEP; |
|
| 218 | - $sbuf .= "<title>" . $this->title . "</title>" . LOG4PHP_LINE_SEP; |
|
| 219 | - $sbuf .= "<style type=\"text/css\">" . LOG4PHP_LINE_SEP; |
|
| 220 | - $sbuf .= "<!--" . LOG4PHP_LINE_SEP; |
|
| 221 | - $sbuf .= "body, table {font-family: arial,sans-serif; font-size: x-small;}" . LOG4PHP_LINE_SEP; |
|
| 222 | - $sbuf .= "th {background: #336699; color: #FFFFFF; text-align: left;}" . LOG4PHP_LINE_SEP; |
|
| 223 | - $sbuf .= "-->" . LOG4PHP_LINE_SEP; |
|
| 224 | - $sbuf .= "</style>" . LOG4PHP_LINE_SEP; |
|
| 225 | - $sbuf .= "</head>" . LOG4PHP_LINE_SEP; |
|
| 226 | - $sbuf .= "<body bgcolor=\"#FFFFFF\" topmargin=\"6\" leftmargin=\"6\">" . LOG4PHP_LINE_SEP; |
|
| 227 | - $sbuf .= "<hr size=\"1\" noshade>" . LOG4PHP_LINE_SEP; |
|
| 228 | - $sbuf .= "Log session start time " . strftime('%c', time()) . "<br>" . LOG4PHP_LINE_SEP; |
|
| 229 | - $sbuf .= "<br>" . LOG4PHP_LINE_SEP; |
|
| 230 | - $sbuf .= "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" bordercolor=\"#224466\" width=\"100%\">" . LOG4PHP_LINE_SEP; |
|
| 231 | - $sbuf .= "<tr>" . LOG4PHP_LINE_SEP; |
|
| 232 | - $sbuf .= "<th>Time</th>" . LOG4PHP_LINE_SEP; |
|
| 233 | - $sbuf .= "<th>Thread</th>" . LOG4PHP_LINE_SEP; |
|
| 234 | - $sbuf .= "<th>Level</th>" . LOG4PHP_LINE_SEP; |
|
| 235 | - $sbuf .= "<th>Category</th>" . LOG4PHP_LINE_SEP; |
|
| 236 | - if ($this->locationInfo) |
|
| 237 | - $sbuf .= "<th>File:Line</th>" . LOG4PHP_LINE_SEP; |
|
| 238 | - $sbuf .= "<th>Message</th>" . LOG4PHP_LINE_SEP; |
|
| 239 | - $sbuf .= "</tr>" . LOG4PHP_LINE_SEP; |
|
| 210 | + /** |
|
| 211 | + * @return string Returns appropriate HTML headers. |
|
| 212 | + */ |
|
| 213 | + public function getHeader() |
|
| 214 | + { |
|
| 215 | + $sbuf = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" . LOG4PHP_LINE_SEP; |
|
| 216 | + $sbuf .= "<html>" . LOG4PHP_LINE_SEP; |
|
| 217 | + $sbuf .= "<head>" . LOG4PHP_LINE_SEP; |
|
| 218 | + $sbuf .= "<title>" . $this->title . "</title>" . LOG4PHP_LINE_SEP; |
|
| 219 | + $sbuf .= "<style type=\"text/css\">" . LOG4PHP_LINE_SEP; |
|
| 220 | + $sbuf .= "<!--" . LOG4PHP_LINE_SEP; |
|
| 221 | + $sbuf .= "body, table {font-family: arial,sans-serif; font-size: x-small;}" . LOG4PHP_LINE_SEP; |
|
| 222 | + $sbuf .= "th {background: #336699; color: #FFFFFF; text-align: left;}" . LOG4PHP_LINE_SEP; |
|
| 223 | + $sbuf .= "-->" . LOG4PHP_LINE_SEP; |
|
| 224 | + $sbuf .= "</style>" . LOG4PHP_LINE_SEP; |
|
| 225 | + $sbuf .= "</head>" . LOG4PHP_LINE_SEP; |
|
| 226 | + $sbuf .= "<body bgcolor=\"#FFFFFF\" topmargin=\"6\" leftmargin=\"6\">" . LOG4PHP_LINE_SEP; |
|
| 227 | + $sbuf .= "<hr size=\"1\" noshade>" . LOG4PHP_LINE_SEP; |
|
| 228 | + $sbuf .= "Log session start time " . strftime('%c', time()) . "<br>" . LOG4PHP_LINE_SEP; |
|
| 229 | + $sbuf .= "<br>" . LOG4PHP_LINE_SEP; |
|
| 230 | + $sbuf .= "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" bordercolor=\"#224466\" width=\"100%\">" . LOG4PHP_LINE_SEP; |
|
| 231 | + $sbuf .= "<tr>" . LOG4PHP_LINE_SEP; |
|
| 232 | + $sbuf .= "<th>Time</th>" . LOG4PHP_LINE_SEP; |
|
| 233 | + $sbuf .= "<th>Thread</th>" . LOG4PHP_LINE_SEP; |
|
| 234 | + $sbuf .= "<th>Level</th>" . LOG4PHP_LINE_SEP; |
|
| 235 | + $sbuf .= "<th>Category</th>" . LOG4PHP_LINE_SEP; |
|
| 236 | + if ($this->locationInfo) |
|
| 237 | + $sbuf .= "<th>File:Line</th>" . LOG4PHP_LINE_SEP; |
|
| 238 | + $sbuf .= "<th>Message</th>" . LOG4PHP_LINE_SEP; |
|
| 239 | + $sbuf .= "</tr>" . LOG4PHP_LINE_SEP; |
|
| 240 | 240 | |
| 241 | - return $sbuf; |
|
| 242 | - } |
|
| 241 | + return $sbuf; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * @return string Returns the appropriate HTML footers. |
|
| 246 | - */ |
|
| 247 | - public function getFooter() |
|
| 248 | - { |
|
| 249 | - $sbuf = "</table>" . LOG4PHP_LINE_SEP; |
|
| 250 | - $sbuf .= "<br>" . LOG4PHP_LINE_SEP; |
|
| 251 | - $sbuf .= "</body></html>"; |
|
| 244 | + /** |
|
| 245 | + * @return string Returns the appropriate HTML footers. |
|
| 246 | + */ |
|
| 247 | + public function getFooter() |
|
| 248 | + { |
|
| 249 | + $sbuf = "</table>" . LOG4PHP_LINE_SEP; |
|
| 250 | + $sbuf .= "<br>" . LOG4PHP_LINE_SEP; |
|
| 251 | + $sbuf .= "</body></html>"; |
|
| 252 | 252 | |
| 253 | - return $sbuf; |
|
| 254 | - } |
|
| 253 | + return $sbuf; |
|
| 254 | + } |
|
| 255 | 255 | } |
| 256 | 256 | ?> |
| 257 | 257 | \ No newline at end of file |
@@ -23,17 +23,17 @@ discard block |
||
| 23 | 23 | if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); |
| 24 | 24 | |
| 25 | 25 | if (!defined('LOG4PHP_LINE_SEP')) { |
| 26 | - if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 27 | - /** |
|
| 28 | - * @ignore |
|
| 29 | - */ |
|
| 30 | - define('LOG4PHP_LINE_SEP', "\r\n"); |
|
| 31 | - } else { |
|
| 32 | - /** |
|
| 33 | - * @ignore |
|
| 34 | - */ |
|
| 35 | - define('LOG4PHP_LINE_SEP', "\n"); |
|
| 36 | - } |
|
| 26 | + if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 27 | + /** |
|
| 28 | + * @ignore |
|
| 29 | + */ |
|
| 30 | + define('LOG4PHP_LINE_SEP', "\r\n"); |
|
| 31 | + } else { |
|
| 32 | + /** |
|
| 33 | + * @ignore |
|
| 34 | + */ |
|
| 35 | + define('LOG4PHP_LINE_SEP', "\n"); |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -76,165 +76,165 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | class LoggerLayoutTTCC extends LoggerLayout { |
| 78 | 78 | |
| 79 | - // Internal representation of options |
|
| 80 | - public $threadPrinting = true; |
|
| 81 | - public $categoryPrefixing = true; |
|
| 82 | - public $contextPrinting = true; |
|
| 83 | - public $microSecondsPrinting = true; |
|
| 79 | + // Internal representation of options |
|
| 80 | + public $threadPrinting = true; |
|
| 81 | + public $categoryPrefixing = true; |
|
| 82 | + public $contextPrinting = true; |
|
| 83 | + public $microSecondsPrinting = true; |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @var string date format. See {@link PHP_MANUAL#strftime} for details |
|
| 87 | - */ |
|
| 88 | - public $dateFormat = '%c'; |
|
| 85 | + /** |
|
| 86 | + * @var string date format. See {@link PHP_MANUAL#strftime} for details |
|
| 87 | + */ |
|
| 88 | + public $dateFormat = '%c'; |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Constructor |
|
| 92 | - * |
|
| 93 | - * @param string date format |
|
| 94 | - * @see dateFormat |
|
| 95 | - */ |
|
| 96 | - public function LoggerLayoutTTCC($dateFormat = '') |
|
| 97 | - { |
|
| 98 | - if (!empty($dateFormat)) |
|
| 99 | - $this->dateFormat = $dateFormat; |
|
| 100 | - return; |
|
| 101 | - } |
|
| 90 | + /** |
|
| 91 | + * Constructor |
|
| 92 | + * |
|
| 93 | + * @param string date format |
|
| 94 | + * @see dateFormat |
|
| 95 | + */ |
|
| 96 | + public function LoggerLayoutTTCC($dateFormat = '') |
|
| 97 | + { |
|
| 98 | + if (!empty($dateFormat)) |
|
| 99 | + $this->dateFormat = $dateFormat; |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * The <b>ThreadPrinting</b> option specifies whether the name of the |
|
| 105 | - * current thread is part of log output or not. This is true by default. |
|
| 106 | - */ |
|
| 107 | - public function setThreadPrinting($threadPrinting) |
|
| 108 | - { |
|
| 103 | + /** |
|
| 104 | + * The <b>ThreadPrinting</b> option specifies whether the name of the |
|
| 105 | + * current thread is part of log output or not. This is true by default. |
|
| 106 | + */ |
|
| 107 | + public function setThreadPrinting($threadPrinting) |
|
| 108 | + { |
|
| 109 | 109 | |
| 110 | - $this->threadPrinting = is_bool($threadPrinting) ? |
|
| 111 | - $threadPrinting : |
|
| 112 | - (bool)(strtolower($threadPrinting) == 'true'); |
|
| 113 | - } |
|
| 110 | + $this->threadPrinting = is_bool($threadPrinting) ? |
|
| 111 | + $threadPrinting : |
|
| 112 | + (bool)(strtolower($threadPrinting) == 'true'); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * @return boolean Returns value of the <b>ThreadPrinting</b> option. |
|
| 117 | - */ |
|
| 118 | - public function getThreadPrinting() { |
|
| 119 | - return $this->threadPrinting; |
|
| 120 | - } |
|
| 115 | + /** |
|
| 116 | + * @return boolean Returns value of the <b>ThreadPrinting</b> option. |
|
| 117 | + */ |
|
| 118 | + public function getThreadPrinting() { |
|
| 119 | + return $this->threadPrinting; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * The <b>CategoryPrefixing</b> option specifies whether {@link Category} |
|
| 124 | - * name is part of log output or not. This is true by default. |
|
| 125 | - */ |
|
| 126 | - public function setCategoryPrefixing($categoryPrefixing) |
|
| 127 | - { |
|
| 128 | - $this->categoryPrefixing = is_bool($categoryPrefixing) ? |
|
| 129 | - $categoryPrefixing : |
|
| 130 | - (bool)(strtolower($categoryPrefixing) == 'true'); |
|
| 131 | - } |
|
| 122 | + /** |
|
| 123 | + * The <b>CategoryPrefixing</b> option specifies whether {@link Category} |
|
| 124 | + * name is part of log output or not. This is true by default. |
|
| 125 | + */ |
|
| 126 | + public function setCategoryPrefixing($categoryPrefixing) |
|
| 127 | + { |
|
| 128 | + $this->categoryPrefixing = is_bool($categoryPrefixing) ? |
|
| 129 | + $categoryPrefixing : |
|
| 130 | + (bool)(strtolower($categoryPrefixing) == 'true'); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @return boolean Returns value of the <b>CategoryPrefixing</b> option. |
|
| 135 | - */ |
|
| 136 | - public function getCategoryPrefixing() { |
|
| 137 | - return $this->categoryPrefixing; |
|
| 138 | - } |
|
| 133 | + /** |
|
| 134 | + * @return boolean Returns value of the <b>CategoryPrefixing</b> option. |
|
| 135 | + */ |
|
| 136 | + public function getCategoryPrefixing() { |
|
| 137 | + return $this->categoryPrefixing; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * The <b>ContextPrinting</b> option specifies log output will include |
|
| 142 | - * the nested context information belonging to the current thread. |
|
| 143 | - * This is true by default. |
|
| 144 | - */ |
|
| 145 | - public function setContextPrinting($contextPrinting) { |
|
| 146 | - $this->contextPrinting = is_bool($contextPrinting) ? |
|
| 147 | - $contextPrinting : |
|
| 148 | - (bool)(strtolower($contextPrinting) == 'true'); |
|
| 149 | - } |
|
| 140 | + /** |
|
| 141 | + * The <b>ContextPrinting</b> option specifies log output will include |
|
| 142 | + * the nested context information belonging to the current thread. |
|
| 143 | + * This is true by default. |
|
| 144 | + */ |
|
| 145 | + public function setContextPrinting($contextPrinting) { |
|
| 146 | + $this->contextPrinting = is_bool($contextPrinting) ? |
|
| 147 | + $contextPrinting : |
|
| 148 | + (bool)(strtolower($contextPrinting) == 'true'); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * @return boolean Returns value of the <b>ContextPrinting</b> option. |
|
| 153 | - */ |
|
| 154 | - public function getContextPrinting() |
|
| 155 | - { |
|
| 156 | - return $this->contextPrinting; |
|
| 157 | - } |
|
| 151 | + /** |
|
| 152 | + * @return boolean Returns value of the <b>ContextPrinting</b> option. |
|
| 153 | + */ |
|
| 154 | + public function getContextPrinting() |
|
| 155 | + { |
|
| 156 | + return $this->contextPrinting; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * The <b>MicroSecondsPrinting</b> option specifies if microseconds infos |
|
| 161 | - * should be printed at the end of timestamp. |
|
| 162 | - * This is true by default. |
|
| 163 | - */ |
|
| 164 | - public function setMicroSecondsPrinting($microSecondsPrinting) { |
|
| 165 | - $this->microSecondsPrinting = is_bool($microSecondsPrinting) ? |
|
| 166 | - $microSecondsPrinting : |
|
| 167 | - (bool)(strtolower($microSecondsPrinting) == 'true'); |
|
| 168 | - } |
|
| 159 | + /** |
|
| 160 | + * The <b>MicroSecondsPrinting</b> option specifies if microseconds infos |
|
| 161 | + * should be printed at the end of timestamp. |
|
| 162 | + * This is true by default. |
|
| 163 | + */ |
|
| 164 | + public function setMicroSecondsPrinting($microSecondsPrinting) { |
|
| 165 | + $this->microSecondsPrinting = is_bool($microSecondsPrinting) ? |
|
| 166 | + $microSecondsPrinting : |
|
| 167 | + (bool)(strtolower($microSecondsPrinting) == 'true'); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * @return boolean Returns value of the <b>MicroSecondsPrinting</b> option. |
|
| 172 | - */ |
|
| 173 | - public function getMicroSecondsPrinting() |
|
| 174 | - { |
|
| 175 | - return $this->microSecondsPrinting; |
|
| 176 | - } |
|
| 170 | + /** |
|
| 171 | + * @return boolean Returns value of the <b>MicroSecondsPrinting</b> option. |
|
| 172 | + */ |
|
| 173 | + public function getMicroSecondsPrinting() |
|
| 174 | + { |
|
| 175 | + return $this->microSecondsPrinting; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | 178 | |
| 179 | - public function setDateFormat($dateFormat) |
|
| 180 | - { |
|
| 181 | - $this->dateFormat = $dateFormat; |
|
| 182 | - } |
|
| 179 | + public function setDateFormat($dateFormat) |
|
| 180 | + { |
|
| 181 | + $this->dateFormat = $dateFormat; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public function getDateFormat() |
|
| 188 | - { |
|
| 189 | - return $this->dateFormat; |
|
| 190 | - } |
|
| 184 | + /** |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public function getDateFormat() |
|
| 188 | + { |
|
| 189 | + return $this->dateFormat; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * In addition to the level of the statement and message, the |
|
| 194 | - * returned string includes time, thread, category. |
|
| 195 | - * <p>Time, thread, category are printed depending on options. |
|
| 196 | - * |
|
| 197 | - * @param LoggerLoggingEvent $event |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - public function format($event) |
|
| 201 | - { |
|
| 202 | - $timeStamp = (float)$event->getTimeStamp(); |
|
| 203 | - $format = strftime($this->dateFormat, (int)$timeStamp); |
|
| 192 | + /** |
|
| 193 | + * In addition to the level of the statement and message, the |
|
| 194 | + * returned string includes time, thread, category. |
|
| 195 | + * <p>Time, thread, category are printed depending on options. |
|
| 196 | + * |
|
| 197 | + * @param LoggerLoggingEvent $event |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + public function format($event) |
|
| 201 | + { |
|
| 202 | + $timeStamp = (float)$event->getTimeStamp(); |
|
| 203 | + $format = strftime($this->dateFormat, (int)$timeStamp); |
|
| 204 | 204 | |
| 205 | - if ($this->microSecondsPrinting) { |
|
| 206 | - $usecs = round(($timeStamp - (int)$timeStamp) * 1000); |
|
| 207 | - $format .= sprintf(',%03d', $usecs); |
|
| 208 | - } |
|
| 205 | + if ($this->microSecondsPrinting) { |
|
| 206 | + $usecs = round(($timeStamp - (int)$timeStamp) * 1000); |
|
| 207 | + $format .= sprintf(',%03d', $usecs); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - $format .= ' '; |
|
| 210 | + $format .= ' '; |
|
| 211 | 211 | |
| 212 | - if ($this->threadPrinting) |
|
| 213 | - $format .= '['.getmypid().'] '; |
|
| 212 | + if ($this->threadPrinting) |
|
| 213 | + $format .= '['.getmypid().'] '; |
|
| 214 | 214 | |
| 215 | - $level = $event->getLevel(); |
|
| 216 | - $format .= $level->toString().' '; |
|
| 215 | + $level = $event->getLevel(); |
|
| 216 | + $format .= $level->toString().' '; |
|
| 217 | 217 | |
| 218 | - if($this->categoryPrefixing) { |
|
| 219 | - $format .= $event->getLoggerName().' '; |
|
| 220 | - } |
|
| 218 | + if($this->categoryPrefixing) { |
|
| 219 | + $format .= $event->getLoggerName().' '; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - if($this->contextPrinting) { |
|
| 223 | - $ndc = $event->getNDC(); |
|
| 224 | - if($ndc != null) { |
|
| 225 | - $format .= $ndc.' '; |
|
| 226 | - } |
|
| 227 | - } |
|
| 222 | + if($this->contextPrinting) { |
|
| 223 | + $ndc = $event->getNDC(); |
|
| 224 | + if($ndc != null) { |
|
| 225 | + $format .= $ndc.' '; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - $format .= '- '.$event->getRenderedMessage(); |
|
| 230 | - $format .= LOG4PHP_LINE_SEP; |
|
| 229 | + $format .= '- '.$event->getRenderedMessage(); |
|
| 230 | + $format .= LOG4PHP_LINE_SEP; |
|
| 231 | 231 | |
| 232 | - return $format; |
|
| 233 | - } |
|
| 232 | + return $format; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - public function ignoresThrowable() |
|
| 236 | - { |
|
| 237 | - return true; |
|
| 238 | - } |
|
| 235 | + public function ignoresThrowable() |
|
| 236 | + { |
|
| 237 | + return true; |
|
| 238 | + } |
|
| 239 | 239 | } |
| 240 | 240 | ?> |
| 241 | 241 | \ No newline at end of file |
@@ -50,157 +50,157 @@ |
||
| 50 | 50 | */ |
| 51 | 51 | class LoggerXmlLayout extends LoggerLayout { |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * The <b>LocationInfo</b> option takes a boolean value. By default, |
|
| 55 | - * it is set to false which means there will be no location |
|
| 56 | - * information output by this layout. If the the option is set to |
|
| 57 | - * true, then the file name and line number of the statement at the |
|
| 58 | - * origin of the log statement will be output. |
|
| 59 | - * @var boolean |
|
| 60 | - */ |
|
| 61 | - public $locationInfo = true; |
|
| 53 | + /** |
|
| 54 | + * The <b>LocationInfo</b> option takes a boolean value. By default, |
|
| 55 | + * it is set to false which means there will be no location |
|
| 56 | + * information output by this layout. If the the option is set to |
|
| 57 | + * true, then the file name and line number of the statement at the |
|
| 58 | + * origin of the log statement will be output. |
|
| 59 | + * @var boolean |
|
| 60 | + */ |
|
| 61 | + public $locationInfo = true; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var boolean set the elements namespace |
|
| 65 | - */ |
|
| 66 | - public $log4jNamespace = false; |
|
| 63 | + /** |
|
| 64 | + * @var boolean set the elements namespace |
|
| 65 | + */ |
|
| 66 | + public $log4jNamespace = false; |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @var string namespace |
|
| 71 | - * @private |
|
| 72 | - */ |
|
| 73 | - public $_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS; |
|
| 69 | + /** |
|
| 70 | + * @var string namespace |
|
| 71 | + * @private |
|
| 72 | + */ |
|
| 73 | + public $_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @var string namespace prefix |
|
| 77 | - * @private |
|
| 78 | - */ |
|
| 79 | - public $_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX; |
|
| 75 | + /** |
|
| 76 | + * @var string namespace prefix |
|
| 77 | + * @private |
|
| 78 | + */ |
|
| 79 | + public $_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX; |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * No options to activate. |
|
| 83 | - */ |
|
| 84 | - public function activateOptions() |
|
| 85 | - { |
|
| 86 | - if ($this->getLog4jNamespace()) { |
|
| 87 | - $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS; |
|
| 88 | - $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS_PREFIX; |
|
| 89 | - } else { |
|
| 90 | - $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS; |
|
| 91 | - $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX; |
|
| 92 | - } |
|
| 93 | - } |
|
| 81 | + /** |
|
| 82 | + * No options to activate. |
|
| 83 | + */ |
|
| 84 | + public function activateOptions() |
|
| 85 | + { |
|
| 86 | + if ($this->getLog4jNamespace()) { |
|
| 87 | + $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS; |
|
| 88 | + $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS_PREFIX; |
|
| 89 | + } else { |
|
| 90 | + $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS; |
|
| 91 | + $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - public function getHeader() |
|
| 99 | - { |
|
| 100 | - return "<{$this->_namespacePrefix}:eventSet ". |
|
| 101 | - "xmlns:{$this->_namespacePrefix}=\"{$this->_namespace}\" ". |
|
| 102 | - "version=\"0.3\" ". |
|
| 103 | - "includesLocationInfo=\"".($this->getLocationInfo() ? "true" : "false")."\"". |
|
| 104 | - ">\r\n"; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Formats a {@link LoggerLoggingEvent} in conformance with the log4php.dtd. |
|
| 109 | - * |
|
| 110 | - * @param LoggerLoggingEvent $event |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - public function format($event) |
|
| 114 | - { |
|
| 115 | - $loggerName = $event->getLoggerName(); |
|
| 116 | - $timeStamp = number_format((float)($event->getTimeStamp() * 1000), 0, '', ''); |
|
| 117 | - $thread = $event->getThreadName(); |
|
| 118 | - $level = $event->getLevel(); |
|
| 119 | - $levelStr = $level->toString(); |
|
| 120 | - |
|
| 121 | - $buf = "<{$this->_namespacePrefix}:event logger=\"{$loggerName}\" level=\"{$levelStr}\" thread=\"{$thread}\" timestamp=\"{$timeStamp}\">\r\n"; |
|
| 122 | - $buf .= "<{$this->_namespacePrefix}:message><![CDATA["; |
|
| 123 | - LoggerTransform::appendEscapingCDATA($buf, $event->getRenderedMessage()); |
|
| 124 | - $buf .= "]]></{$this->_namespacePrefix}:message>\r\n"; |
|
| 125 | - |
|
| 126 | - $ndc = $event->getNDC(); |
|
| 127 | - if($ndc != null) { |
|
| 128 | - $buf .= "<{$this->_namespacePrefix}:NDC><![CDATA["; |
|
| 129 | - LoggerTransform::appendEscapingCDATA($buf, $ndc); |
|
| 130 | - $buf .= "]]></{$this->_namespacePrefix}:NDC>\r\n"; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if ($this->getLocationInfo()) { |
|
| 134 | - $locationInfo = $event->getLocationInformation(); |
|
| 135 | - $buf .= "<{$this->_namespacePrefix}:locationInfo ". |
|
| 136 | - "class=\"" . $locationInfo->getClassName() . "\" ". |
|
| 137 | - "file=\"" . htmlentities($locationInfo->getFileName(), ENT_QUOTES) . "\" ". |
|
| 138 | - "line=\"" . $locationInfo->getLineNumber() . "\" ". |
|
| 139 | - "method=\"" . $locationInfo->getMethodName() . "\" "; |
|
| 140 | - $buf .= "/>\r\n"; |
|
| 141 | - |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $buf .= "</{$this->_namespacePrefix}:event>\r\n\r\n"; |
|
| 95 | + /** |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + public function getHeader() |
|
| 99 | + { |
|
| 100 | + return "<{$this->_namespacePrefix}:eventSet ". |
|
| 101 | + "xmlns:{$this->_namespacePrefix}=\"{$this->_namespace}\" ". |
|
| 102 | + "version=\"0.3\" ". |
|
| 103 | + "includesLocationInfo=\"".($this->getLocationInfo() ? "true" : "false")."\"". |
|
| 104 | + ">\r\n"; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Formats a {@link LoggerLoggingEvent} in conformance with the log4php.dtd. |
|
| 109 | + * |
|
| 110 | + * @param LoggerLoggingEvent $event |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + public function format($event) |
|
| 114 | + { |
|
| 115 | + $loggerName = $event->getLoggerName(); |
|
| 116 | + $timeStamp = number_format((float)($event->getTimeStamp() * 1000), 0, '', ''); |
|
| 117 | + $thread = $event->getThreadName(); |
|
| 118 | + $level = $event->getLevel(); |
|
| 119 | + $levelStr = $level->toString(); |
|
| 120 | + |
|
| 121 | + $buf = "<{$this->_namespacePrefix}:event logger=\"{$loggerName}\" level=\"{$levelStr}\" thread=\"{$thread}\" timestamp=\"{$timeStamp}\">\r\n"; |
|
| 122 | + $buf .= "<{$this->_namespacePrefix}:message><![CDATA["; |
|
| 123 | + LoggerTransform::appendEscapingCDATA($buf, $event->getRenderedMessage()); |
|
| 124 | + $buf .= "]]></{$this->_namespacePrefix}:message>\r\n"; |
|
| 125 | + |
|
| 126 | + $ndc = $event->getNDC(); |
|
| 127 | + if($ndc != null) { |
|
| 128 | + $buf .= "<{$this->_namespacePrefix}:NDC><![CDATA["; |
|
| 129 | + LoggerTransform::appendEscapingCDATA($buf, $ndc); |
|
| 130 | + $buf .= "]]></{$this->_namespacePrefix}:NDC>\r\n"; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if ($this->getLocationInfo()) { |
|
| 134 | + $locationInfo = $event->getLocationInformation(); |
|
| 135 | + $buf .= "<{$this->_namespacePrefix}:locationInfo ". |
|
| 136 | + "class=\"" . $locationInfo->getClassName() . "\" ". |
|
| 137 | + "file=\"" . htmlentities($locationInfo->getFileName(), ENT_QUOTES) . "\" ". |
|
| 138 | + "line=\"" . $locationInfo->getLineNumber() . "\" ". |
|
| 139 | + "method=\"" . $locationInfo->getMethodName() . "\" "; |
|
| 140 | + $buf .= "/>\r\n"; |
|
| 141 | + |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $buf .= "</{$this->_namespacePrefix}:event>\r\n\r\n"; |
|
| 145 | 145 | |
| 146 | - return $buf; |
|
| 146 | + return $buf; |
|
| 147 | 147 | |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function getFooter() |
|
| 154 | - { |
|
| 155 | - |
|
| 156 | - return "</{$this->_namespacePrefix}:eventSet>\r\n"; |
|
| 157 | - } |
|
| 150 | + /** |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function getFooter() |
|
| 154 | + { |
|
| 155 | + |
|
| 156 | + return "</{$this->_namespacePrefix}:eventSet>\r\n"; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * @return boolean |
|
| 161 | - */ |
|
| 162 | - public function getLocationInfo() |
|
| 163 | - { |
|
| 164 | - return $this->locationInfo; |
|
| 165 | - } |
|
| 159 | + /** |
|
| 160 | + * @return boolean |
|
| 161 | + */ |
|
| 162 | + public function getLocationInfo() |
|
| 163 | + { |
|
| 164 | + return $this->locationInfo; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @return boolean |
|
| 169 | - */ |
|
| 170 | - public function getLog4jNamespace() |
|
| 171 | - { |
|
| 172 | - return $this->log4jNamespace; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * The XMLLayout prints and does not ignore exceptions. Hence the |
|
| 177 | - * return value <b>false</b>. |
|
| 178 | - * @return boolean |
|
| 179 | - */ |
|
| 180 | - public function ignoresThrowable() |
|
| 181 | - { |
|
| 182 | - return false; |
|
| 183 | - } |
|
| 167 | + /** |
|
| 168 | + * @return boolean |
|
| 169 | + */ |
|
| 170 | + public function getLog4jNamespace() |
|
| 171 | + { |
|
| 172 | + return $this->log4jNamespace; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * The XMLLayout prints and does not ignore exceptions. Hence the |
|
| 177 | + * return value <b>false</b>. |
|
| 178 | + * @return boolean |
|
| 179 | + */ |
|
| 180 | + public function ignoresThrowable() |
|
| 181 | + { |
|
| 182 | + return false; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * The {@link $locationInfo} option takes a boolean value. By default, |
|
| 187 | - * it is set to false which means there will be no location |
|
| 188 | - * information output by this layout. If the the option is set to |
|
| 189 | - * true, then the file name and line number of the statement at the |
|
| 190 | - * origin of the log statement will be output. |
|
| 191 | - */ |
|
| 192 | - public function setLocationInfo($flag) |
|
| 193 | - { |
|
| 194 | - $this->locationInfo = LoggerOptionConverter::toBoolean($flag, true); |
|
| 195 | - } |
|
| 185 | + /** |
|
| 186 | + * The {@link $locationInfo} option takes a boolean value. By default, |
|
| 187 | + * it is set to false which means there will be no location |
|
| 188 | + * information output by this layout. If the the option is set to |
|
| 189 | + * true, then the file name and line number of the statement at the |
|
| 190 | + * origin of the log statement will be output. |
|
| 191 | + */ |
|
| 192 | + public function setLocationInfo($flag) |
|
| 193 | + { |
|
| 194 | + $this->locationInfo = LoggerOptionConverter::toBoolean($flag, true); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * @param boolean |
|
| 199 | - */ |
|
| 200 | - public function setLog4jNamespace($flag) |
|
| 201 | - { |
|
| 202 | - $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, true); |
|
| 203 | - } |
|
| 197 | + /** |
|
| 198 | + * @param boolean |
|
| 199 | + */ |
|
| 200 | + public function setLog4jNamespace($flag) |
|
| 201 | + { |
|
| 202 | + $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, true); |
|
| 203 | + } |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | ?> |
| 207 | 207 | \ No newline at end of file |
@@ -41,315 +41,315 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class LoggerAppenderSkeleton extends LoggerAppender { |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var boolean closed appender flag |
|
| 46 | - */ |
|
| 47 | - public $closed; |
|
| 44 | + /** |
|
| 45 | + * @var boolean closed appender flag |
|
| 46 | + */ |
|
| 47 | + public $closed; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var object unused |
|
| 51 | - */ |
|
| 52 | - public $errorHandler; |
|
| 49 | + /** |
|
| 50 | + * @var object unused |
|
| 51 | + */ |
|
| 52 | + public $errorHandler; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * The first filter in the filter chain |
|
| 56 | - * @var LoggerFilter |
|
| 57 | - */ |
|
| 58 | - public $headFilter = null; |
|
| 54 | + /** |
|
| 55 | + * The first filter in the filter chain |
|
| 56 | + * @var LoggerFilter |
|
| 57 | + */ |
|
| 58 | + public $headFilter = null; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * LoggerLayout for this appender. It can be null if appender has its own layout |
|
| 62 | - * @var LoggerLayout |
|
| 63 | - */ |
|
| 64 | - public $layout = null; |
|
| 60 | + /** |
|
| 61 | + * LoggerLayout for this appender. It can be null if appender has its own layout |
|
| 62 | + * @var LoggerLayout |
|
| 63 | + */ |
|
| 64 | + public $layout = null; |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @var string Appender name |
|
| 68 | - */ |
|
| 69 | - public $name; |
|
| 66 | + /** |
|
| 67 | + * @var string Appender name |
|
| 68 | + */ |
|
| 69 | + public $name; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * The last filter in the filter chain |
|
| 73 | - * @var LoggerFilter |
|
| 74 | - */ |
|
| 75 | - public $tailFilter = null; |
|
| 71 | + /** |
|
| 72 | + * The last filter in the filter chain |
|
| 73 | + * @var LoggerFilter |
|
| 74 | + */ |
|
| 75 | + public $tailFilter = null; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @var LoggerLevel There is no level threshold filtering by default. |
|
| 79 | - */ |
|
| 80 | - public $threshold = null; |
|
| 77 | + /** |
|
| 78 | + * @var LoggerLevel There is no level threshold filtering by default. |
|
| 79 | + */ |
|
| 80 | + public $threshold = null; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @var boolean needs a layout formatting ? |
|
| 84 | - */ |
|
| 85 | - public $requiresLayout = false; |
|
| 82 | + /** |
|
| 83 | + * @var boolean needs a layout formatting ? |
|
| 84 | + */ |
|
| 85 | + public $requiresLayout = false; |
|
| 86 | 86 | |
| 87 | 87 | /* --------------------------------------------------------------------------*/ |
| 88 | 88 | /* --------------------------------------------------------------------------*/ |
| 89 | 89 | /* --------------------------------------------------------------------------*/ |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Constructor |
|
| 93 | - * |
|
| 94 | - * @param string $name appender name |
|
| 95 | - */ |
|
| 96 | - public function LoggerAppenderSkeleton($name) |
|
| 97 | - { |
|
| 98 | - $this->name = $name; |
|
| 99 | - $this->clearFilters(); |
|
| 100 | - } |
|
| 91 | + /** |
|
| 92 | + * Constructor |
|
| 93 | + * |
|
| 94 | + * @param string $name appender name |
|
| 95 | + */ |
|
| 96 | + public function LoggerAppenderSkeleton($name) |
|
| 97 | + { |
|
| 98 | + $this->name = $name; |
|
| 99 | + $this->clearFilters(); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * @param LoggerFilter $newFilter add a new LoggerFilter |
|
| 104 | - * @see LoggerAppender::addFilter() |
|
| 105 | - */ |
|
| 106 | - public function addFilter($newFilter) |
|
| 107 | - { |
|
| 108 | - if($this->headFilter === null) { |
|
| 109 | - $this->headFilter = $newFilter; |
|
| 110 | - $this->tailFilter =& $this->headFilter; |
|
| 111 | - } else { |
|
| 112 | - $this->tailFilter->next = $newFilter; |
|
| 113 | - $this->tailFilter =& $this->tailFilter->next; |
|
| 114 | - } |
|
| 115 | - } |
|
| 102 | + /** |
|
| 103 | + * @param LoggerFilter $newFilter add a new LoggerFilter |
|
| 104 | + * @see LoggerAppender::addFilter() |
|
| 105 | + */ |
|
| 106 | + public function addFilter($newFilter) |
|
| 107 | + { |
|
| 108 | + if($this->headFilter === null) { |
|
| 109 | + $this->headFilter = $newFilter; |
|
| 110 | + $this->tailFilter =& $this->headFilter; |
|
| 111 | + } else { |
|
| 112 | + $this->tailFilter->next = $newFilter; |
|
| 113 | + $this->tailFilter =& $this->tailFilter->next; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Derived appenders should override this method if option structure |
|
| 119 | - * requires it. |
|
| 120 | - */ |
|
| 121 | - public function activateOptions() |
|
| 122 | - { |
|
| 117 | + /** |
|
| 118 | + * Derived appenders should override this method if option structure |
|
| 119 | + * requires it. |
|
| 120 | + */ |
|
| 121 | + public function activateOptions() |
|
| 122 | + { |
|
| 123 | 123 | |
| 124 | - } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * Subclasses of {@link LoggerAppenderSkeleton} should implement |
|
| 128 | - * this method to perform actual logging. |
|
| 129 | - * |
|
| 130 | - * @param LoggerLoggingEvent $event |
|
| 131 | - * @see doAppend() |
|
| 132 | - * @abstract |
|
| 133 | - */ |
|
| 134 | - public function append($event) |
|
| 135 | - { |
|
| 136 | - // override me |
|
| 137 | - } |
|
| 126 | + /** |
|
| 127 | + * Subclasses of {@link LoggerAppenderSkeleton} should implement |
|
| 128 | + * this method to perform actual logging. |
|
| 129 | + * |
|
| 130 | + * @param LoggerLoggingEvent $event |
|
| 131 | + * @see doAppend() |
|
| 132 | + * @abstract |
|
| 133 | + */ |
|
| 134 | + public function append($event) |
|
| 135 | + { |
|
| 136 | + // override me |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * @see LoggerAppender::clearFilters() |
|
| 141 | - */ |
|
| 142 | - public function clearFilters() |
|
| 143 | - { |
|
| 144 | - unset($this->headFilter); |
|
| 145 | - unset($this->tailFilter); |
|
| 146 | - $this->headFilter = null; |
|
| 147 | - $this->tailFilter = null; |
|
| 148 | - } |
|
| 139 | + /** |
|
| 140 | + * @see LoggerAppender::clearFilters() |
|
| 141 | + */ |
|
| 142 | + public function clearFilters() |
|
| 143 | + { |
|
| 144 | + unset($this->headFilter); |
|
| 145 | + unset($this->tailFilter); |
|
| 146 | + $this->headFilter = null; |
|
| 147 | + $this->tailFilter = null; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * @see LoggerAppender::close() |
|
| 152 | - */ |
|
| 153 | - public function close() |
|
| 154 | - { |
|
| 155 | - //override me |
|
| 156 | - } |
|
| 150 | + /** |
|
| 151 | + * @see LoggerAppender::close() |
|
| 152 | + */ |
|
| 153 | + public function close() |
|
| 154 | + { |
|
| 155 | + //override me |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Finalize this appender by calling the derived class' <i>close()</i> method. |
|
| 160 | - */ |
|
| 161 | - public function finalize() |
|
| 162 | - { |
|
| 163 | - // An appender might be closed then garbage collected. There is no |
|
| 164 | - // point in closing twice. |
|
| 165 | - if ($this->closed) return; |
|
| 158 | + /** |
|
| 159 | + * Finalize this appender by calling the derived class' <i>close()</i> method. |
|
| 160 | + */ |
|
| 161 | + public function finalize() |
|
| 162 | + { |
|
| 163 | + // An appender might be closed then garbage collected. There is no |
|
| 164 | + // point in closing twice. |
|
| 165 | + if ($this->closed) return; |
|
| 166 | 166 | |
| 167 | - LoggerLog::debug("LoggerAppenderSkeleton::finalize():name=[{$this->name}]."); |
|
| 167 | + LoggerLog::debug("LoggerAppenderSkeleton::finalize():name=[{$this->name}]."); |
|
| 168 | 168 | |
| 169 | - $this->close(); |
|
| 170 | - } |
|
| 169 | + $this->close(); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Do not use this method. |
|
| 174 | - * @see LoggerAppender::getErrorHandler() |
|
| 175 | - * @return object |
|
| 176 | - */ |
|
| 177 | - public function &getErrorHandler() |
|
| 178 | - { |
|
| 179 | - return $this->errorHandler; |
|
| 180 | - } |
|
| 172 | + /** |
|
| 173 | + * Do not use this method. |
|
| 174 | + * @see LoggerAppender::getErrorHandler() |
|
| 175 | + * @return object |
|
| 176 | + */ |
|
| 177 | + public function &getErrorHandler() |
|
| 178 | + { |
|
| 179 | + return $this->errorHandler; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * @see LoggerAppender::getFilter() |
|
| 184 | - * @return Filter |
|
| 185 | - */ |
|
| 186 | - public function &getFilter() |
|
| 187 | - { |
|
| 188 | - return $this->headFilter; |
|
| 189 | - } |
|
| 182 | + /** |
|
| 183 | + * @see LoggerAppender::getFilter() |
|
| 184 | + * @return Filter |
|
| 185 | + */ |
|
| 186 | + public function &getFilter() |
|
| 187 | + { |
|
| 188 | + return $this->headFilter; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - /** |
|
| 192 | - * Return the first filter in the filter chain for this Appender. |
|
| 193 | - * The return value may be <i>null</i> if no is filter is set. |
|
| 194 | - * @return Filter |
|
| 195 | - */ |
|
| 196 | - public function &getFirstFilter() |
|
| 197 | - { |
|
| 198 | - return $this->headFilter; |
|
| 199 | - } |
|
| 191 | + /** |
|
| 192 | + * Return the first filter in the filter chain for this Appender. |
|
| 193 | + * The return value may be <i>null</i> if no is filter is set. |
|
| 194 | + * @return Filter |
|
| 195 | + */ |
|
| 196 | + public function &getFirstFilter() |
|
| 197 | + { |
|
| 198 | + return $this->headFilter; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * @see LoggerAppender::getLayout() |
|
| 203 | - * @return LoggerLayout |
|
| 204 | - */ |
|
| 205 | - public function &getLayout() |
|
| 206 | - { |
|
| 207 | - return $this->layout; |
|
| 208 | - } |
|
| 201 | + /** |
|
| 202 | + * @see LoggerAppender::getLayout() |
|
| 203 | + * @return LoggerLayout |
|
| 204 | + */ |
|
| 205 | + public function &getLayout() |
|
| 206 | + { |
|
| 207 | + return $this->layout; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * @see LoggerAppender::getName() |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - public function getName() |
|
| 215 | - { |
|
| 216 | - return $this->name; |
|
| 217 | - } |
|
| 210 | + /** |
|
| 211 | + * @see LoggerAppender::getName() |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + public function getName() |
|
| 215 | + { |
|
| 216 | + return $this->name; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * Returns this appenders threshold level. |
|
| 221 | - * See the {@link setThreshold()} method for the meaning of this option. |
|
| 222 | - * @return LoggerLevel |
|
| 223 | - */ |
|
| 224 | - public function &getThreshold() |
|
| 225 | - { |
|
| 226 | - return $this->threshold; |
|
| 227 | - } |
|
| 219 | + /** |
|
| 220 | + * Returns this appenders threshold level. |
|
| 221 | + * See the {@link setThreshold()} method for the meaning of this option. |
|
| 222 | + * @return LoggerLevel |
|
| 223 | + */ |
|
| 224 | + public function &getThreshold() |
|
| 225 | + { |
|
| 226 | + return $this->threshold; |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * Check whether the message level is below the appender's threshold. |
|
| 231 | - * |
|
| 232 | - * |
|
| 233 | - * If there is no threshold set, then the return value is always <i>true</i>. |
|
| 234 | - * @param LoggerLevel $priority |
|
| 235 | - * @return boolean true if priority is greater or equal than threshold |
|
| 236 | - */ |
|
| 237 | - public function isAsSevereAsThreshold($priority) |
|
| 238 | - { |
|
| 239 | - if ($this->threshold === null) |
|
| 240 | - return true; |
|
| 229 | + /** |
|
| 230 | + * Check whether the message level is below the appender's threshold. |
|
| 231 | + * |
|
| 232 | + * |
|
| 233 | + * If there is no threshold set, then the return value is always <i>true</i>. |
|
| 234 | + * @param LoggerLevel $priority |
|
| 235 | + * @return boolean true if priority is greater or equal than threshold |
|
| 236 | + */ |
|
| 237 | + public function isAsSevereAsThreshold($priority) |
|
| 238 | + { |
|
| 239 | + if ($this->threshold === null) |
|
| 240 | + return true; |
|
| 241 | 241 | |
| 242 | - return $priority->isGreaterOrEqual($this->getThreshold()); |
|
| 243 | - } |
|
| 242 | + return $priority->isGreaterOrEqual($this->getThreshold()); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * @see LoggerAppender::doAppend() |
|
| 247 | - * @param LoggerLoggingEvent $event |
|
| 248 | - */ |
|
| 249 | - public function doAppend($event) |
|
| 250 | - { |
|
| 251 | - LoggerLog::debug("LoggerAppenderSkeleton::doAppend()"); |
|
| 245 | + /** |
|
| 246 | + * @see LoggerAppender::doAppend() |
|
| 247 | + * @param LoggerLoggingEvent $event |
|
| 248 | + */ |
|
| 249 | + public function doAppend($event) |
|
| 250 | + { |
|
| 251 | + LoggerLog::debug("LoggerAppenderSkeleton::doAppend()"); |
|
| 252 | 252 | |
| 253 | - if ($this->closed) { |
|
| 254 | - LoggerLog::debug("LoggerAppenderSkeleton::doAppend() Attempted to append to closed appender named [{$this->name}]."); |
|
| 255 | - return; |
|
| 256 | - } |
|
| 257 | - if(!$this->isAsSevereAsThreshold($event->getLevel())) { |
|
| 258 | - LoggerLog::debug("LoggerAppenderSkeleton::doAppend() event level is less severe than threshold."); |
|
| 259 | - return; |
|
| 260 | - } |
|
| 253 | + if ($this->closed) { |
|
| 254 | + LoggerLog::debug("LoggerAppenderSkeleton::doAppend() Attempted to append to closed appender named [{$this->name}]."); |
|
| 255 | + return; |
|
| 256 | + } |
|
| 257 | + if(!$this->isAsSevereAsThreshold($event->getLevel())) { |
|
| 258 | + LoggerLog::debug("LoggerAppenderSkeleton::doAppend() event level is less severe than threshold."); |
|
| 259 | + return; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - $f = $this->getFirstFilter(); |
|
| 262 | + $f = $this->getFirstFilter(); |
|
| 263 | 263 | |
| 264 | - while($f !== null) { |
|
| 265 | - switch ($f->decide($event)) { |
|
| 266 | - case LOG4PHP_LOGGER_FILTER_DENY: return; |
|
| 267 | - case LOG4PHP_LOGGER_FILTER_ACCEPT: return $this->append($event); |
|
| 268 | - case LOG4PHP_LOGGER_FILTER_NEUTRAL: $f = $f->next; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - $this->append($event); |
|
| 272 | - } |
|
| 264 | + while($f !== null) { |
|
| 265 | + switch ($f->decide($event)) { |
|
| 266 | + case LOG4PHP_LOGGER_FILTER_DENY: return; |
|
| 267 | + case LOG4PHP_LOGGER_FILTER_ACCEPT: return $this->append($event); |
|
| 268 | + case LOG4PHP_LOGGER_FILTER_NEUTRAL: $f = $f->next; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + $this->append($event); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * @see LoggerAppender::requiresLayout() |
|
| 277 | - * @return boolean |
|
| 278 | - */ |
|
| 279 | - public function requiresLayout() |
|
| 280 | - { |
|
| 281 | - return $this->requiresLayout; |
|
| 282 | - } |
|
| 275 | + /** |
|
| 276 | + * @see LoggerAppender::requiresLayout() |
|
| 277 | + * @return boolean |
|
| 278 | + */ |
|
| 279 | + public function requiresLayout() |
|
| 280 | + { |
|
| 281 | + return $this->requiresLayout; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * @see LoggerAppender::setErrorHandler() |
|
| 286 | - * @param object |
|
| 287 | - */ |
|
| 288 | - public function setErrorHandler($errorHandler) |
|
| 289 | - { |
|
| 290 | - if($errorHandler == null) { |
|
| 291 | - // We do not throw exception here since the cause is probably a |
|
| 292 | - // bad config file. |
|
| 293 | - LoggerLog::warn("You have tried to set a null error-handler."); |
|
| 294 | - } else { |
|
| 295 | - $this->errorHandler = $errorHandler; |
|
| 296 | - } |
|
| 297 | - } |
|
| 284 | + /** |
|
| 285 | + * @see LoggerAppender::setErrorHandler() |
|
| 286 | + * @param object |
|
| 287 | + */ |
|
| 288 | + public function setErrorHandler($errorHandler) |
|
| 289 | + { |
|
| 290 | + if($errorHandler == null) { |
|
| 291 | + // We do not throw exception here since the cause is probably a |
|
| 292 | + // bad config file. |
|
| 293 | + LoggerLog::warn("You have tried to set a null error-handler."); |
|
| 294 | + } else { |
|
| 295 | + $this->errorHandler = $errorHandler; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * @see LoggerAppender::setLayout() |
|
| 301 | - * @param LoggerLayout $layout |
|
| 302 | - */ |
|
| 303 | - public function setLayout($layout) |
|
| 304 | - { |
|
| 305 | - if ($this->requiresLayout()) |
|
| 306 | - $this->layout = $layout; |
|
| 307 | - } |
|
| 299 | + /** |
|
| 300 | + * @see LoggerAppender::setLayout() |
|
| 301 | + * @param LoggerLayout $layout |
|
| 302 | + */ |
|
| 303 | + public function setLayout($layout) |
|
| 304 | + { |
|
| 305 | + if ($this->requiresLayout()) |
|
| 306 | + $this->layout = $layout; |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * @see LoggerAppender::setName() |
|
| 311 | - * @param string $name |
|
| 312 | - */ |
|
| 313 | - public function setName($name) |
|
| 314 | - { |
|
| 315 | - $this->name = $name; |
|
| 316 | - } |
|
| 309 | + /** |
|
| 310 | + * @see LoggerAppender::setName() |
|
| 311 | + * @param string $name |
|
| 312 | + */ |
|
| 313 | + public function setName($name) |
|
| 314 | + { |
|
| 315 | + $this->name = $name; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - /** |
|
| 319 | - * Set the threshold level of this appender. |
|
| 320 | - * |
|
| 321 | - * @param mixed $threshold can be a {@link LoggerLevel} object or a string. |
|
| 322 | - * @see LoggerOptionConverter::toLevel() |
|
| 323 | - */ |
|
| 324 | - public function setThreshold($threshold) |
|
| 325 | - { |
|
| 326 | - if (is_string($threshold)) { |
|
| 327 | - $this->threshold = LoggerOptionConverter::toLevel($threshold, null); |
|
| 328 | - }elseif (is_a($threshold, 'loggerlevel')) { |
|
| 329 | - $this->threshold = $threshold; |
|
| 330 | - } |
|
| 331 | - } |
|
| 318 | + /** |
|
| 319 | + * Set the threshold level of this appender. |
|
| 320 | + * |
|
| 321 | + * @param mixed $threshold can be a {@link LoggerLevel} object or a string. |
|
| 322 | + * @see LoggerOptionConverter::toLevel() |
|
| 323 | + */ |
|
| 324 | + public function setThreshold($threshold) |
|
| 325 | + { |
|
| 326 | + if (is_string($threshold)) { |
|
| 327 | + $this->threshold = LoggerOptionConverter::toLevel($threshold, null); |
|
| 328 | + }elseif (is_a($threshold, 'loggerlevel')) { |
|
| 329 | + $this->threshold = $threshold; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - /** |
|
| 334 | - * Perform actions before object serialization. |
|
| 335 | - * |
|
| 336 | - * Call {@link finalize()} to properly close the appender. |
|
| 337 | - */ |
|
| 338 | - public function __sleep() |
|
| 339 | - { |
|
| 340 | - $this->finalize(); |
|
| 341 | - return array_keys(get_object_vars($this)); |
|
| 342 | - } |
|
| 333 | + /** |
|
| 334 | + * Perform actions before object serialization. |
|
| 335 | + * |
|
| 336 | + * Call {@link finalize()} to properly close the appender. |
|
| 337 | + */ |
|
| 338 | + public function __sleep() |
|
| 339 | + { |
|
| 340 | + $this->finalize(); |
|
| 341 | + return array_keys(get_object_vars($this)); |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - /** |
|
| 345 | - * Perform actions after object deserialization. |
|
| 346 | - * |
|
| 347 | - * Call {@link activateOptions()} to properly setup the appender. |
|
| 348 | - */ |
|
| 349 | - public function __wakeup() |
|
| 350 | - { |
|
| 351 | - $this->activateOptions(); |
|
| 352 | - } |
|
| 344 | + /** |
|
| 345 | + * Perform actions after object deserialization. |
|
| 346 | + * |
|
| 347 | + * Call {@link activateOptions()} to properly setup the appender. |
|
| 348 | + */ |
|
| 349 | + public function __wakeup() |
|
| 350 | + { |
|
| 351 | + $this->activateOptions(); |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | 354 | } |
| 355 | 355 | ?> |
| 356 | 356 | \ No newline at end of file |