|
|
@@ -1049,4 +1049,53 @@ interface CollectionInterface extends Iterator, JsonSerializable
|
|
|
* @return \Cake\Collection\CollectionInterface
|
|
|
*/
|
|
|
public function transpose();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns the amount of elements in the collection.
|
|
|
+ *
|
|
|
+ * ## WARNINGS:
|
|
|
+ *
|
|
|
+ * ### Consumes all elements for NoRewindIterator collections:
|
|
|
+ *
|
|
|
+ * On certain type of collections, calling this method may render unusable afterwards.
|
|
|
+ * That is, you may not be able to get elements out of it, or to iterate on it anymore.
|
|
|
+ *
|
|
|
+ * Specifically any collection wrapping a Generator (a function with a yield statement)
|
|
|
+ * or a unbuffered database cursor will not accept any other function calls after calling
|
|
|
+ * `count()` on it.
|
|
|
+ *
|
|
|
+ * Create a new collection with `buffered()` method to overcome this problem.
|
|
|
+ *
|
|
|
+ * ### Can report more elements than unique keys:
|
|
|
+ *
|
|
|
+ * Any collection constructed by appending collections together, or by having internal iterators
|
|
|
+ * returning duplicate keys, will report a larger amount of elements using this functions than
|
|
|
+ * the final amount of elements when converting the collections to a keyed array. This is because
|
|
|
+ * duplicate keys will be collapsed into a single one in the final array, whereas this count method
|
|
|
+ * is only concerned by the amount of elements after converting it to a plain list.
|
|
|
+ *
|
|
|
+ * If you need the count of elements after taking the keys in consideration
|
|
|
+ * (the count of unique keys), you can call `countKeys()`
|
|
|
+ *
|
|
|
+ * ### Will change the current position of the iterator:
|
|
|
+ *
|
|
|
+ * Calling this method at the same time that you are iterating this collections, for example in
|
|
|
+ * a foreach, will result in undefined behavior. Avoid doing this.
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function count();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns the number of unique keys in this iterator. This is, the number of
|
|
|
+ * elements the collection will contain after calling `toArray()`
|
|
|
+ *
|
|
|
+ * This method comes with a number of caveats. Please refer to `CollectionInterface::count()`
|
|
|
+ * for details.
|
|
|
+ *
|
|
|
+ * @see \Cake\Collection\CollectionInterface::count()
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function countKeys();
|
|
|
}
|