Commit 92214eaf authored by romanb's avatar romanb

[2.0] Part II for ticket #2352. Fixed #2352.

parent 2ec4cc5c
...@@ -30,7 +30,7 @@ use \Closure, \ArrayIterator; ...@@ -30,7 +30,7 @@ use \Closure, \ArrayIterator;
* @author Roman S. Borschel <roman@code-factory.org> * @author Roman S. Borschel <roman@code-factory.org>
* @since 2.0 * @since 2.0
*/ */
class ArrayCollection implements ICollection class ArrayCollection implements Collection
{ {
/** /**
* An array containing the entries of this collection. * An array containing the entries of this collection.
......
<?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();
}
\ No newline at end of file
...@@ -25,7 +25,7 @@ use Doctrine\DBAL\Connection, ...@@ -25,7 +25,7 @@ use Doctrine\DBAL\Connection,
Doctrine\ORM\PersistentCollection, Doctrine\ORM\PersistentCollection,
Doctrine\ORM\Query, Doctrine\ORM\Query,
Doctrine\Common\Collections\ArrayCollection, Doctrine\Common\Collections\ArrayCollection,
Doctrine\Common\Collections\ICollection; Doctrine\Common\Collections\Collection;
/** /**
* The ObjectHydrator constructs an object graph out of an SQL result set. * The ObjectHydrator constructs an object graph out of an SQL result set.
...@@ -147,7 +147,7 @@ class ObjectHydrator extends AbstractHydrator ...@@ -147,7 +147,7 @@ class ObjectHydrator extends AbstractHydrator
if ( ! is_object($coll)) { if ( ! is_object($coll)) {
end($coll); end($coll);
$this->_resultPointers[$dqlAlias] =& $coll[key($coll)]; $this->_resultPointers[$dqlAlias] =& $coll[key($coll)];
} else if ($coll instanceof ICollection) { } else if ($coll instanceof Collection) {
if (count($coll) > 0) { if (count($coll) > 0) {
$this->_resultPointers[$dqlAlias] = $coll->last(); $this->_resultPointers[$dqlAlias] = $coll->last();
} }
......
...@@ -44,7 +44,7 @@ use Doctrine\Common\DoctrineException, ...@@ -44,7 +44,7 @@ use Doctrine\Common\DoctrineException,
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com> * @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. * A snapshot of the collection at the moment it was fetched from the database.
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
namespace Doctrine\ORM; namespace Doctrine\ORM;
use Doctrine\Common\Collections\ArrayCollection, use Doctrine\Common\Collections\ArrayCollection,
Doctrine\Common\Collections\ICollection, Doctrine\Common\Collections\Collection,
Doctrine\Common\DoctrineException, Doctrine\Common\DoctrineException,
Doctrine\Common\PropertyChangedListener, Doctrine\Common\PropertyChangedListener,
Doctrine\ORM\Event\LifecycleEventArgs, Doctrine\ORM\Event\LifecycleEventArgs,
...@@ -1455,7 +1455,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1455,7 +1455,7 @@ class UnitOfWork implements PropertyChangedListener
continue; continue;
} }
$relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity); $relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity);
if ($relatedEntities instanceof ICollection) { if ($relatedEntities instanceof Collection) {
foreach ($relatedEntities as $relatedEntity) { foreach ($relatedEntities as $relatedEntity) {
$this->_doRefresh($relatedEntity, $visited); $this->_doRefresh($relatedEntity, $visited);
} }
...@@ -1479,7 +1479,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1479,7 +1479,7 @@ class UnitOfWork implements PropertyChangedListener
continue; continue;
} }
$relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity); $relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity);
if ($relatedEntities instanceof ICollection) { if ($relatedEntities instanceof Collection) {
foreach ($relatedEntities as $relatedEntity) { foreach ($relatedEntities as $relatedEntity) {
$this->_doDetach($relatedEntity, $visited); $this->_doDetach($relatedEntity, $visited);
} }
...@@ -1504,7 +1504,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1504,7 +1504,7 @@ class UnitOfWork implements PropertyChangedListener
continue; continue;
} }
$relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity); $relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity);
if ($relatedEntities instanceof ICollection) { if ($relatedEntities instanceof Collection) {
foreach ($relatedEntities as $relatedEntity) { foreach ($relatedEntities as $relatedEntity) {
$this->_doMerge($relatedEntity, $visited, $managedCopy, $assocMapping); $this->_doMerge($relatedEntity, $visited, $managedCopy, $assocMapping);
} }
...@@ -1529,7 +1529,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1529,7 +1529,7 @@ class UnitOfWork implements PropertyChangedListener
continue; continue;
} }
$relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity); $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) { foreach ($relatedEntities as $relatedEntity) {
$this->_doPersist($relatedEntity, $visited); $this->_doPersist($relatedEntity, $visited);
} }
...@@ -1554,7 +1554,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1554,7 +1554,7 @@ class UnitOfWork implements PropertyChangedListener
} }
$relatedEntities = $class->reflFields[$assocMapping->sourceFieldName] $relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]
->getValue($entity); ->getValue($entity);
if ($relatedEntities instanceof ICollection || is_array($relatedEntities)) { if ($relatedEntities instanceof Collection || is_array($relatedEntities)) {
foreach ($relatedEntities as $relatedEntity) { foreach ($relatedEntities as $relatedEntity) {
$this->_doRemove($relatedEntity, $visited); $this->_doRemove($relatedEntity, $visited);
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace Doctrine\Tests\ORM\Functional; namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Common\Collections\ICollection; use Doctrine\Common\Collections\Collection;
require_once __DIR__ . '/../../TestInit.php'; require_once __DIR__ . '/../../TestInit.php';
...@@ -36,7 +36,7 @@ class AbstractManyToManyAssociationTestCase extends \Doctrine\Tests\OrmFunctiona ...@@ -36,7 +36,7 @@ class AbstractManyToManyAssociationTestCase extends \Doctrine\Tests\OrmFunctiona
->fetchAll()); ->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); }); return $first->forAll(function($k, $e) use($second) { return $second->contains($e); });
} }
......
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