Project

General

Profile

Actions

Feature #81840

open

Make ObjectStorage implement Doctrine\Common\Collections\Collection Interface

Added by Cedric Ziel over 7 years ago. Updated almost 5 years ago.

Status:
Accepted
Priority:
Should have
Assignee:
-
Category:
Extbase
Start date:
2017-07-12
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

The `doctrine/collections` package is already a implicit dependency (through `doctrine/common` -> `doctrine/dbal`) and contains the `ArrayCollection` class, which is the most basic type of collection which sits on an array.

This would enhance the ObjectStorage with some useful new capabilities, most notably:

/**
 * Tests for the existence of an element that satisfies the given predicate.
 *
 * @param Closure $p The predicate.
 *
 * @return boolean TRUE if the predicate is TRUE for at least one element, FALSE otherwise.
*/
public function exists(Closure $p);
/**
 * Returns all the elements of this collection that satisfy the predicate p.
 * The order of the elements is preserved.
 *
 * @param Closure $p The predicate used for filtering.
 *
 * @return Collection A collection with the results of the filter operation.
*/
public function filter(Closure $p);
/**
 * Tests whether the given predicate p holds for all elements of this collection.
 *
 * @param Closure $p The predicate.
 *
 * @return boolean TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.
*/
public function forAll(Closure $p);
/**
 * Applies the given function to each element in the collection and returns
 * a new collection with the elements returned by the function.
 *
 * @param Closure $func
 *
 * @return Collection
*/
public function map(Closure $func);
/**
 * Partitions this collection in two collections according to a predicate.
 * Keys are preserved in the resulting collections.
 *
 * @param Closure $p The predicate on which to partition.
 *
 * @return array An array with two elements. The first element contains the collection
 *               of elements where the predicate returned TRUE, the second element
 *               contains the collection of elements where the predicate returned FALSE.
*/
public function partition(Closure $p);
/**
 * Extracts 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 The offset to start from.
 * @param int|null $length The maximum number of elements to return, or null for no limit.
 *
 * @return array
*/
public function slice($offset, $length = null);

Implementing those methods would cut off a bunch of post-processing we do on ObjectStorages.

The Interface itself can be found here: https://github.com/doctrine/collections/blob/master/lib/Doctrine/Common/Collections/Collection.php

I have a draft implementation lined up and will push it to gerrit soon.

Actions #1

Updated by Susanne Moog almost 7 years ago

  • Target version deleted (9.0)
Actions #2

Updated by Christian Eßl about 5 years ago

  • Category set to Extbase
Actions #3

Updated by Alexander Schnitzler almost 5 years ago

  • Status changed from New to Accepted
  • Target version set to Candidate for Major Version

I like the idea and have even more here. I want to replace the ObjectStorage completely. But that's a different and more complex topic.

Actions

Also available in: Atom PDF