X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdoctrine%2Fcollections%2Flib%2FDoctrine%2FCommon%2FCollections%2FArrayCollection.php;h=7ddd068e56264f73e8a2e492c5c7e9b71daf8876;hp=bce575120ea794a29004b51749252c8a63e6cc8c;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae diff --git a/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php b/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php index bce575120..7ddd068e5 100644 --- a/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php +++ b/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php @@ -26,6 +26,11 @@ use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor; /** * An ArrayCollection is a Collection implementation that wraps a regular PHP array. * + * Warning: Using (un-)serialize() on a collection is not a supported use-case + * and may break when we change the internals in the future. If you need to + * serialize a collection use {@link toArray()} and reconstruct the collection + * manually. + * * @since 2.0 * @author Guilherme Blanco * @author Jonathan Wage @@ -50,6 +55,21 @@ class ArrayCollection implements Collection, Selectable $this->elements = $elements; } + /** + * Creates a new instance from the specified elements. + * + * This method is provided for derived classes to specify how a new + * instance should be created when constructor semantics have changed. + * + * @param array $elements Elements. + * + * @return static + */ + protected function createFrom(array $elements) + { + return new static($elements); + } + /** * {@inheritDoc} */ @@ -254,9 +274,9 @@ class ArrayCollection implements Collection, Selectable /** * {@inheritDoc} */ - public function add($value) + public function add($element) { - $this->elements[] = $value; + $this->elements[] = $element; return true; } @@ -284,7 +304,7 @@ class ArrayCollection implements Collection, Selectable */ public function map(Closure $func) { - return new static(array_map($func, $this->elements)); + return $this->createFrom(array_map($func, $this->elements)); } /** @@ -292,7 +312,7 @@ class ArrayCollection implements Collection, Selectable */ public function filter(Closure $p) { - return new static(array_filter($this->elements, $p)); + return $this->createFrom(array_filter($this->elements, $p)); } /** @@ -324,7 +344,7 @@ class ArrayCollection implements Collection, Selectable } } - return array(new static($matches), new static($noMatches)); + return array($this->createFrom($matches), $this->createFrom($noMatches)); } /** @@ -368,8 +388,9 @@ class ArrayCollection implements Collection, Selectable } if ($orderings = $criteria->getOrderings()) { + $next = null; foreach (array_reverse($orderings) as $field => $ordering) { - $next = ClosureExpressionVisitor::sortByField($field, $ordering == Criteria::DESC ? -1 : 1); + $next = ClosureExpressionVisitor::sortByField($field, $ordering == Criteria::DESC ? -1 : 1, $next); } uasort($filtered, $next); @@ -382,6 +403,6 @@ class ArrayCollection implements Collection, Selectable $filtered = array_slice($filtered, (int)$offset, $length); } - return new static($filtered); + return $this->createFrom($filtered); } }