From: Michael M Slusarz Date: Mon, 6 Sep 2010 03:01:44 +0000 (-0600) Subject: Implement Serializable for Horde_Imap_Client_DateTime X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d6d57158109e8d4b9e7c41c7b5422d4aca6a9a6f;p=horde.git Implement Serializable for Horde_Imap_Client_DateTime --- diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/DateTime.php b/framework/Imap_Client/lib/Horde/Imap/Client/DateTime.php index 464498916..c27de2dec 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/DateTime.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/DateTime.php @@ -14,8 +14,11 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @package Imap_Client */ -class Horde_Imap_Client_DateTime +class Horde_Imap_Client_DateTime implements Serializable { + /* Serialized version. */ + const VERSION = 1; + /** * The datetime string. * @@ -52,11 +55,37 @@ class Horde_Imap_Client_DateTime } /** - * Called on serialize(). + * Serialize. + * + * @return string Serialized representation of this object. */ - public function __sleep() + public function serialize() { - return array('_string', '_tz'); + return serialize(array( + self::VERSION, + $this->_string, + $this->_tz + )); + } + + /** + * 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->_string = $data[1]; + $this->_tz = $data[2]; } /**