Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
62e7146d
Commit
62e7146d
authored
Mar 29, 2010
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-423] Fixed.
parent
354ede1e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
35 deletions
+93
-35
ArrayCollection.php
lib/Doctrine/Common/Collections/ArrayCollection.php
+1
-1
Collection.php
lib/Doctrine/Common/Collections/Collection.php
+86
-29
PersistentCollection.php
lib/Doctrine/ORM/PersistentCollection.php
+5
-4
CollectionTest.php
tests/Doctrine/Tests/Common/Collections/CollectionTest.php
+1
-1
No files found.
lib/Doctrine/Common/Collections/ArrayCollection.php
View file @
62e7146d
...
...
@@ -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
);
}
...
...
lib/Doctrine/Common/Collections/Collection.php
View file @
62e7146d
...
...
@@ -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.
...
...
@@ -61,31 +62,31 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
* Clears the collection, removing all elements.
*/
function
clear
();
/**
* 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 ke
y
/index of the element to remove.
* @param string|integer $key The ke
x
/index of the element to remove.
* @return mixed The removed element or NULL, if the collection did not contain the element.
*/
function
remove
(
$key
);
/**
* Removes an element from the collection.
*
...
...
@@ -93,7 +94,7 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
* @return mixed The removed element or NULL, if the collection did not contain the element.
*/
function
removeElement
(
$element
);
/**
* Checks whether the collection contains an element with the specified key/index.
*
...
...
@@ -102,15 +103,15 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
* FALSE otherwise.
*/
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
*/
function
get
(
$key
);
/**
* Gets all keys/indices of the collection.
*
...
...
@@ -118,7 +119,7 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
* elements in the collection.
*/
function
getKeys
();
/**
* Gets all values of the collection.
*
...
...
@@ -126,7 +127,7 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
* appear in the collection.
*/
function
getValues
();
/**
* Sets an element in the collection at the specified key/index.
*
...
...
@@ -134,14 +135,14 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
* @param mixed $value The element to set.
*/
function
set
(
$key
,
$value
);
/**
* Gets a
plain
PHP array representation of the collection.
* Gets a
native
PHP array representation of the collection.
*
* @return array
*/
function
toArray
();
/**
* Sets the internal iterator to the first element in the collection and
* returns this element.
...
...
@@ -149,7 +150,7 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
* @return mixed
*/
function
first
();
/**
* Sets the internal iterator to the last element in the collection and
* returns this element.
...
...
@@ -157,22 +158,78 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
* @return mixed
*/
function
last
();
/**
* Gets the key/index of the element at the current iterator position.
*
*/
function
key
();
/**
* Gets the element of the collection at the current iterator position.
*
*/
function
current
();
/**
* Moves the internal iterator position to the next element.
*
*/
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
lib/Doctrine/ORM/PersistentCollection.php
View file @
62e7146d
...
...
@@ -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
);
}
/**
...
...
tests/Doctrine/Tests/Common/Collections/CollectionTest.php
View file @
62e7146d
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment