From 5dfcb2e4da5bff319a3941eb55e803b359a2aad0 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Wed, 22 Dec 2010 00:33:48 +0100 Subject: [PATCH] Implement Serializable. --- .../Share/lib/Horde/Share/Object/Datatree.php | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/framework/Share/lib/Horde/Share/Object/Datatree.php b/framework/Share/lib/Horde/Share/Object/Datatree.php index 69671b506..b6bb8526e 100644 --- a/framework/Share/lib/Horde/Share/Object/Datatree.php +++ b/framework/Share/lib/Horde/Share/Object/Datatree.php @@ -11,6 +11,11 @@ class Horde_Share_Object_Datatree extends Horde_Share_Object { /** + * Serializable version. + */ + const VERSION = 1; + + /** * The actual storage object that holds the data. * * @var mixed @@ -29,6 +34,41 @@ class Horde_Share_Object_Datatree extends Horde_Share_Object } /** + * Serialize this object. + * + * @return string The serialized data. + */ + public function serialize() + { + return serialize(array( + self::VERSION, + $this->datatreeObject, + $this->_shareCallback, + )); + } + + /** + * Reconstruct the object from serialized data. + * + * @param string $data The serialized data. + */ + 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->datatreeObject = $data[1]; + if (empty($data[2])) { + throw new Exception('Missing callback for Horde_Share_Object unserializing'); + } + $this->_shareCallback = $data[2]; + } + + /** * Sets an attribute value in this object. * * @param string $attribute The attribute to set. -- 2.11.0