From d6d57158109e8d4b9e7c41c7b5422d4aca6a9a6f Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sun, 5 Sep 2010 21:01:44 -0600 Subject: [PATCH] Implement Serializable for Horde_Imap_Client_DateTime --- .../Imap_Client/lib/Horde/Imap/Client/DateTime.php | 37 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) 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]; } /** -- 2.11.0