Commit 62e7146d authored by romanb's avatar romanb

[2.0][DDC-423] Fixed.

parent 354ede1e
......@@ -247,7 +247,7 @@ class ArrayCollection implements Collection
* @param mixed $element The element to search for.
* @return mixed The key/index of the element or FALSE if the element was not found.
*/
public function search($element)
public function indexOf($element)
{
return array_search($element, $this->_elements, true);
}
......
......@@ -21,20 +21,21 @@
namespace Doctrine\Common\Collections;
use Closure, Countable, IteratorAggregate, ArrayAccess;
/**
* The missing (SPL) Collection/Array/OrderedMap interface.
*
* A Collection resembles the nature of a regular PHP array. That is,
* it is essentially an ordered map that can syntactically also be used
* it is essentially an <b>ordered map</b> that can also be used
* like a list.
*
* A Collection has an internal iterator just like a PHP array. In addition
* A Collection has an internal iterator just like a PHP array. In addition,
* a Collection can be iterated with external iterators, which is preferrable.
* To use an external iterator simply use the foreach language construct to
* iterate over the collection (which calls getIterator() internally) or
* explicitly retrieve an iterator though getIterator() which can then be
* iterate over the collection (which calls {@link getIterator()} internally) or
* explicitly retrieve an iterator though {@link getIterator()} which can then be
* used to iterate over the collection.
*
* You can not rely on the internal iterator of the collection being at a certain
* position unless you explicitly positioned it before. Prefer iteration with
* external iterators.
......@@ -47,10 +48,10 @@ namespace Doctrine\Common\Collections;
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
interface Collection extends Countable, IteratorAggregate, ArrayAccess
{
/**
* Adds an element to the collection.
* Adds an element at the end of the collection.
*
* @param mixed $element The element to add.
* @return boolean Always TRUE.
......@@ -64,24 +65,24 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
/**
* Checks whether an element is contained in the collection.
* This is an O(n) operation.
* This is an O(n) operation, where n is the size of the collection.
*
* @param mixed $element The element to check for.
* @param mixed $element The element to search for.
* @return boolean TRUE if the collection contains the element, FALSE otherwise.
*/
function contains($element);
/**
* Checks whether the collection is empty.
* Checks whether the collection is empty (contains no elements).
*
* @return boolean TRUE if the collection is empty, FALSE otherwise.
*/
function isEmpty();
/**
* Removes the element with the specified key/index from the collection.
* Removes the element at the specified index from the collection.
*
* @param string|integer $key The key/index of the element to remove.
* @param string|integer $key The kex/index of the element to remove.
* @return mixed The removed element or NULL, if the collection did not contain the element.
*/
function remove($key);
......@@ -104,7 +105,7 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
function containsKey($key);
/**
* Gets an element with a specified key / at a specified index.
* Gets the element at the specified key/index.
*
* @param string|integer $key The key/index of the element to retrieve.
* @return mixed
......@@ -136,7 +137,7 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
function set($key, $value);
/**
* Gets a plain PHP array representation of the collection.
* Gets a native PHP array representation of the collection.
*
* @return array
*/
......@@ -175,4 +176,60 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
*
*/
function next();
/**
* 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.
*/
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.
*/
function filter(Closure $p);
/**
* Applies the given predicate p to all elements of this collection,
* returning true, if the predicate yields true for all elements.
*
* @param Closure $p The predicate.
* @return boolean TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.
*/
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
*/
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.
*/
function partition(Closure $p);
/**
* Gets the index/key of a given element. The comparison of two elements is strict,
* that means not only the value but also the type must match.
* For objects this means reference equality.
*
* @param mixed $element The element to search for.
* @return mixed The key/index of the element or FALSE if the element was not found.
*/
function indexOf($element);
}
\ No newline at end of file
......@@ -22,7 +22,8 @@
namespace Doctrine\ORM;
use Doctrine\ORM\Mapping\AssociationMapping,
\Closure;
Doctrine\Common\Collections\Collection,
Closure;
/**
* A PersistentCollection represents a collection of elements that have persistent state.
......@@ -40,7 +41,7 @@ use Doctrine\ORM\Mapping\AssociationMapping,
* @author Roman Borschel <roman@code-factory.org>
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
*/
final class PersistentCollection implements \Doctrine\Common\Collections\Collection
final class PersistentCollection implements Collection
{
/**
* A snapshot of the collection at the moment it was fetched from the database.
......@@ -443,10 +444,10 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
/**
* {@inheritdoc}
*/
public function search($element)
public function indexOf($element)
{
$this->_initialize();
return $this->_coll->search($element);
return $this->_coll->indexOf($element);
}
/**
......
......@@ -98,7 +98,7 @@ class CollectionTest extends \Doctrine\Tests\DoctrineTestCase
public function testSearch()
{
$this->_coll[0] = 'test';
$this->assertEquals(0, $this->_coll->search('test'));
$this->assertEquals(0, $this->_coll->indexOf('test'));
}
public function testGet()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment