From: Michael M Slusarz Date: Mon, 6 Sep 2010 20:31:02 +0000 (-0600) Subject: Have Horde_Log_Logger implement Serializable X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0893a2dad3d60673547d4f139c102220b7ffbe3e;p=horde.git Have Horde_Log_Logger implement Serializable --- diff --git a/framework/Log/lib/Horde/Log/Logger.php b/framework/Log/lib/Horde/Log/Logger.php index dd27d166c..466735bf6 100644 --- a/framework/Log/lib/Horde/Log/Logger.php +++ b/framework/Log/lib/Horde/Log/Logger.php @@ -30,8 +30,11 @@ * @method void info() info($event) Log an event at the INFO log level * @method void debug() debug($event) Log an event at the DEBUG log level */ -class Horde_Log_Logger +class Horde_Log_Logger implements Serializable { + /* Serialize version. */ + const VERSION = 1; + /** * Log levels where the keys are the level priorities and the values are * the level names. @@ -61,12 +64,56 @@ class Horde_Log_Logger */ public function __construct($handler = null) { - $r = new ReflectionClass('Horde_Log'); - $this->_levels = array_flip($r->getConstants()); - if (!is_null($handler)) { $this->addHandler($handler); } + + $this->_init(); + } + + /** + * Serialize. + * + * @return string Serialized representation of this object. + */ + public function serialize() + { + return serialize(array( + self::VERSION, + $this->_filters, + $this->_handlers + )); + } + + /** + * Unserialize. + * + * @param string $data Serialized data. + * + * @throws Exception + */ + public function unserialize($data) + { + $data = @unserialize($data); + if (!is_array($data) || + !isset($data[0]) || + ($data[0] != self::VERSION)) { + throw new Exception('Cache version change'); + } + + $this->_filters = $data[1]; + $this->_handlers = $data[2]; + + $this->_init(); + } + + /** + * Initialization tasks. + */ + protected function _init() + { + $r = new ReflectionClass('Horde_Log'); + $this->_levels = array_flip($r->getConstants()); } /**