From: Michael M Slusarz Date: Fri, 10 Sep 2010 20:50:05 +0000 (-0600) Subject: Have Horde_Imap_Client_Search_Query implement Serializable X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=bc5227e55cd937aaec26c2b49781f8a3cec1c26e;p=horde.git Have Horde_Imap_Client_Search_Query implement Serializable --- diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Search/Query.php b/framework/Imap_Client/lib/Horde/Imap/Client/Search/Query.php index 31ac8dc60..699e9c89f 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Search/Query.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Search/Query.php @@ -15,8 +15,11 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @package Imap_Client */ -class Horde_Imap_Client_Search_Query +class Horde_Imap_Client_Search_Query implements Serializable { + /* Serialized version. */ + const VERSION = 1; + /* Constants for dateSearch() */ const DATE_BEFORE = 'BEFORE'; const DATE_ON = 'ON'; @@ -581,4 +584,48 @@ class Horde_Imap_Client_Search_Query $this->_search['prevsearch'] = $not; } + /* Serializable methods. */ + + /** + * Serialization. + * + * @return string Serialized data. + */ + public function serialize() + { + $data = array( + // Serialized data ID. + self::VERSION, + $this->_search + ); + + if (!is_null($this->_charset)) { + $data[] = $this->_charset; + } + + return serialize($data); + } + + /** + * Unserialization. + * + * @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->_search = $data[1]; + if (isset($data[2])) { + $this->_charset = $data[2]; + } + } + } diff --git a/framework/Mime/lib/Horde/Mime/Headers.php b/framework/Mime/lib/Horde/Mime/Headers.php index c202df983..d53839511 100644 --- a/framework/Mime/lib/Horde/Mime/Headers.php +++ b/framework/Mime/lib/Horde/Mime/Headers.php @@ -636,13 +636,18 @@ class Horde_Mime_Headers implements Serializable */ public function serialize() { - return serialize(array( + $data = array( // Serialized data ID. self::VERSION, $this->_headers, - $this->_eol, - $this->_agent - )); + $this->_eol + ); + + if (!is_null($this->_agent)) { + $data[] = $this->_agent; + } + + return serialize($data); } /** @@ -663,7 +668,9 @@ class Horde_Mime_Headers implements Serializable $this->_headers = $data[1]; $this->_eol = $data[2]; - $this->_agent = $data[3]; + if (isset($data[3])) { + $this->_agent = $data[3]; + } } }