parent
2ec4cc5cbe
commit
92214eaf37
6 changed files with 141 additions and 12 deletions
|
@ -30,7 +30,7 @@ use \Closure, \ArrayIterator;
|
|||
* @author Roman S. Borschel <roman@code-factory.org>
|
||||
* @since 2.0
|
||||
*/
|
||||
class ArrayCollection implements ICollection
|
||||
class ArrayCollection implements Collection
|
||||
{
|
||||
/**
|
||||
* An array containing the entries of this collection.
|
||||
|
|
129
lib/Doctrine/Common/Collections/Collection.php
Normal file
129
lib/Doctrine/Common/Collections/Collection.php
Normal file
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
/**
|
||||
* The missing (SPL) Collection/Array 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
|
||||
* like a list.
|
||||
*
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @since 2.0
|
||||
*/
|
||||
interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Adds an element to the collection.
|
||||
*
|
||||
* @param mixed $element The element to add.
|
||||
* @return boolean Always TRUE.
|
||||
*/
|
||||
function add($element);
|
||||
|
||||
/**
|
||||
* Clears the collection.
|
||||
*/
|
||||
function clear();
|
||||
|
||||
/**
|
||||
* Checks whether an element is contained in the collection.
|
||||
* This is an O(n) operation.
|
||||
*
|
||||
* @param mixed $element The element to check for.
|
||||
* @return boolean TRUE if the collection contains the element, FALSE otherwise.
|
||||
*/
|
||||
function contains($element);
|
||||
|
||||
/**
|
||||
* Checks whether the collection is empty.
|
||||
*
|
||||
* @return boolean TRUE if the collection is empty, FALSE otherwise.
|
||||
*/
|
||||
function isEmpty();
|
||||
|
||||
/**
|
||||
* Removes the element with the specified key/index from the collection.
|
||||
*
|
||||
* @param string|integer $key The key/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.
|
||||
*
|
||||
* @param mixed $element The element to remove.
|
||||
* @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.
|
||||
*
|
||||
* @param string|integer $key The key/index to check for.
|
||||
* @return boolean TRUE if the collection contains an element with the specified key/index,
|
||||
* FALSE otherwise.
|
||||
*/
|
||||
function containsKey($key);
|
||||
|
||||
/**
|
||||
* Gets an element with a specified key / at a specified 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.
|
||||
*
|
||||
* @return array The keys/indices of the collection, in the order of the corresponding
|
||||
* elements in the collection.
|
||||
*/
|
||||
function getKeys();
|
||||
|
||||
/**
|
||||
* Gets all values of the collection.
|
||||
*
|
||||
* @return array The values of all elements in the collection, in the order they
|
||||
* appear in the collection.
|
||||
*/
|
||||
function getValues();
|
||||
|
||||
/**
|
||||
* Sets an element in the collection at the specified key/index.
|
||||
*
|
||||
* @param string|integer $key The key/index of the element to set.
|
||||
* @param mixed $value The element to set.
|
||||
*/
|
||||
function set($key, $value);
|
||||
|
||||
/**
|
||||
* Counts the elements in the collection.
|
||||
*
|
||||
* @return integer The number of elements in the collection.
|
||||
*/
|
||||
//function count();
|
||||
|
||||
/**
|
||||
* Gets a plain PHP array representation of the collection.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function toArray();
|
||||
|
||||
/**
|
||||
* Gets the first element of the collection.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function first();
|
||||
|
||||
/**
|
||||
* Gets the last element of the collection.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function last();
|
||||
}
|
|
@ -25,7 +25,7 @@ use Doctrine\DBAL\Connection,
|
|||
Doctrine\ORM\PersistentCollection,
|
||||
Doctrine\ORM\Query,
|
||||
Doctrine\Common\Collections\ArrayCollection,
|
||||
Doctrine\Common\Collections\ICollection;
|
||||
Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* The ObjectHydrator constructs an object graph out of an SQL result set.
|
||||
|
@ -147,7 +147,7 @@ class ObjectHydrator extends AbstractHydrator
|
|||
if ( ! is_object($coll)) {
|
||||
end($coll);
|
||||
$this->_resultPointers[$dqlAlias] =& $coll[key($coll)];
|
||||
} else if ($coll instanceof ICollection) {
|
||||
} else if ($coll instanceof Collection) {
|
||||
if (count($coll) > 0) {
|
||||
$this->_resultPointers[$dqlAlias] = $coll->last();
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ use Doctrine\Common\DoctrineException,
|
|||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
|
||||
*/
|
||||
final class PersistentCollection implements \Doctrine\Common\Collections\ICollection
|
||||
final class PersistentCollection implements \Doctrine\Common\Collections\Collection
|
||||
{
|
||||
/**
|
||||
* A snapshot of the collection at the moment it was fetched from the database.
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
namespace Doctrine\ORM;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection,
|
||||
Doctrine\Common\Collections\ICollection,
|
||||
Doctrine\Common\Collections\Collection,
|
||||
Doctrine\Common\DoctrineException,
|
||||
Doctrine\Common\PropertyChangedListener,
|
||||
Doctrine\ORM\Event\LifecycleEventArgs,
|
||||
|
@ -1455,7 +1455,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||
continue;
|
||||
}
|
||||
$relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity);
|
||||
if ($relatedEntities instanceof ICollection) {
|
||||
if ($relatedEntities instanceof Collection) {
|
||||
foreach ($relatedEntities as $relatedEntity) {
|
||||
$this->_doRefresh($relatedEntity, $visited);
|
||||
}
|
||||
|
@ -1479,7 +1479,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||
continue;
|
||||
}
|
||||
$relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity);
|
||||
if ($relatedEntities instanceof ICollection) {
|
||||
if ($relatedEntities instanceof Collection) {
|
||||
foreach ($relatedEntities as $relatedEntity) {
|
||||
$this->_doDetach($relatedEntity, $visited);
|
||||
}
|
||||
|
@ -1504,7 +1504,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||
continue;
|
||||
}
|
||||
$relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity);
|
||||
if ($relatedEntities instanceof ICollection) {
|
||||
if ($relatedEntities instanceof Collection) {
|
||||
foreach ($relatedEntities as $relatedEntity) {
|
||||
$this->_doMerge($relatedEntity, $visited, $managedCopy, $assocMapping);
|
||||
}
|
||||
|
@ -1529,7 +1529,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||
continue;
|
||||
}
|
||||
$relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity);
|
||||
if (($relatedEntities instanceof ICollection || is_array($relatedEntities))) {
|
||||
if (($relatedEntities instanceof Collection || is_array($relatedEntities))) {
|
||||
foreach ($relatedEntities as $relatedEntity) {
|
||||
$this->_doPersist($relatedEntity, $visited);
|
||||
}
|
||||
|
@ -1554,7 +1554,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||
}
|
||||
$relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]
|
||||
->getValue($entity);
|
||||
if ($relatedEntities instanceof ICollection || is_array($relatedEntities)) {
|
||||
if ($relatedEntities instanceof Collection || is_array($relatedEntities)) {
|
||||
foreach ($relatedEntities as $relatedEntity) {
|
||||
$this->_doRemove($relatedEntity, $visited);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\Common\Collections\ICollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
|
@ -36,7 +36,7 @@ class AbstractManyToManyAssociationTestCase extends \Doctrine\Tests\OrmFunctiona
|
|||
->fetchAll());
|
||||
}
|
||||
|
||||
public function assertCollectionEquals(ICollection $first, ICollection $second)
|
||||
public function assertCollectionEquals(Collection $first, Collection $second)
|
||||
{
|
||||
return $first->forAll(function($k, $e) use($second) { return $second->contains($e); });
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue