From 0a81ae773da0b1c530dbe80f4dc9f5716eb84d64 Mon Sep 17 00:00:00 2001 From: romanb Date: Thu, 7 May 2009 17:56:09 +0000 Subject: [PATCH] [2.0] Ensuring that PersistentCollection instances that are injected by Doctrine can be transparently serialized. --- lib/Doctrine/ORM/PersistentCollection.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index a45b8bf08..f5e75a19c 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -117,6 +117,8 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection */ private $_isDirty = false; + private $_isSerializing = false; + /** * Creates a new persistent collection. */ @@ -427,4 +429,18 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection { $this->_isDirty = $dirty; } + + /* Serializable implementation */ + + /** + * Called by PHP when this collection is serialized. Ensures that only the + * elements are properly serialized. + * + * @internal Tried to implement Serializable first but that did not work well + * with circular references. This solution seems simpler and works well. + */ + public function __sleep() + { + return array('_elements'); + } } \ No newline at end of file