From 241e4d2f538fdeb35ce7280026a13b5632b954d6 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 24 Aug 2010 21:56:29 +0200 Subject: [PATCH] DDC-737 - Implemented slice() on PersistentCollection for fowards compatibility reasons. The method will be required on Collection interface with the next Doctrine\Common release --- lib/Doctrine/ORM/PersistentCollection.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 34437d570..6c09e9697 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -661,4 +661,21 @@ final class PersistentCollection implements Collection { return $this->coll; } + + /** + * Extract a slice of $length elements starting at position $offset from the Collection. + * + * If $length is null it returns all elements from $offset to the end of the Collection. + * Keys have to be preserved by this method. Calling this method will only return the + * selected slice and NOT change the elements contained in the collection slice is called on. + * + * @param int $offset + * @param int $length + * @return array + */ + public function slice($offset, $length = null) + { + $this->initialize(); + return $this->coll->slice($offset, $length); + } }