Yaffs site version 1.1
[yaffs-website] / vendor / doctrine / collections / lib / Doctrine / Common / Collections / ArrayCollection.php
index bce575120ea794a29004b51749252c8a63e6cc8c..7ddd068e56264f73e8a2e492c5c7e9b71daf8876 100644 (file)
@@ -26,6 +26,11 @@ use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
 /**
  * An ArrayCollection is a Collection implementation that wraps a regular PHP array.
  *
 /**
  * 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 <guilhermeblanco@hotmail.com>
  * @author Jonathan Wage <jonwage@gmail.com>
  * @since  2.0
  * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  * @author Jonathan Wage <jonwage@gmail.com>
@@ -50,6 +55,21 @@ class ArrayCollection implements Collection, Selectable
         $this->elements = $elements;
     }
 
         $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}
      */
     /**
      * {@inheritDoc}
      */
@@ -254,9 +274,9 @@ class ArrayCollection implements Collection, Selectable
     /**
      * {@inheritDoc}
      */
     /**
      * {@inheritDoc}
      */
-    public function add($value)
+    public function add($element)
     {
     {
-        $this->elements[] = $value;
+        $this->elements[] = $element;
 
         return true;
     }
 
         return true;
     }
@@ -284,7 +304,7 @@ class ArrayCollection implements Collection, Selectable
      */
     public function map(Closure $func)
     {
      */
     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)
     {
      */
     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()) {
         }
 
         if ($orderings = $criteria->getOrderings()) {
+            $next = null;
             foreach (array_reverse($orderings) as $field => $ordering) {
             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);
             }
 
             uasort($filtered, $next);
@@ -382,6 +403,6 @@ class ArrayCollection implements Collection, Selectable
             $filtered = array_slice($filtered, (int)$offset, $length);
         }
 
             $filtered = array_slice($filtered, (int)$offset, $length);
         }
 
-        return new static($filtered);
+        return $this->createFrom($filtered);
     }
 }
     }
 }