2008-12-18 17:08:11 +03:00
|
|
|
<?php
|
2009-02-07 20:02:13 +03:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.doctrine-project.org>.
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\Common\Collections;
|
2008-12-18 17:08:11 +03:00
|
|
|
|
2009-07-29 15:57:27 +04:00
|
|
|
use \Closure, \ArrayIterator;
|
2008-12-18 17:08:11 +03:00
|
|
|
|
|
|
|
/**
|
2009-08-03 17:25:56 +04:00
|
|
|
* An ArrayCollection is a Collection implementation that uses a regular PHP array
|
|
|
|
* internally.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
2009-08-11 01:36:57 +04:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @link www.doctrine-project.org
|
|
|
|
* @since 2.0
|
|
|
|
* @version $Revision: 3938 $
|
|
|
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
|
|
* @author Jonathan Wage <jonwage@gmail.com>
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
2009-07-29 16:00:08 +04:00
|
|
|
class ArrayCollection implements Collection
|
2009-01-14 00:56:43 +03:00
|
|
|
{
|
2008-12-18 17:08:11 +03:00
|
|
|
/**
|
|
|
|
* An array containing the entries of this collection.
|
2009-08-03 17:25:56 +04:00
|
|
|
* This is the internal php array.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2009-07-29 15:57:27 +04:00
|
|
|
private $_elements;
|
2008-12-18 17:08:11 +03:00
|
|
|
|
|
|
|
/**
|
2009-07-29 15:57:27 +04:00
|
|
|
* Initializes a new ArrayCollection.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
2009-02-18 00:18:13 +03:00
|
|
|
* @param array $elements
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
2009-01-12 16:34:41 +03:00
|
|
|
public function __construct(array $elements = array())
|
2008-12-18 17:08:11 +03:00
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
$this->_elements = $elements;
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
2009-08-03 17:25:56 +04:00
|
|
|
|
2008-12-18 17:08:11 +03:00
|
|
|
/**
|
2009-08-03 17:25:56 +04:00
|
|
|
* Gets the PHP array representation of this collection.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
2009-08-03 17:25:56 +04:00
|
|
|
* @return array The PHP array representation of this collection.
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
2009-07-29 15:57:27 +04:00
|
|
|
public function toArray()
|
|
|
|
{
|
|
|
|
return $this->_elements;
|
|
|
|
}
|
2008-12-18 17:08:11 +03:00
|
|
|
|
|
|
|
/**
|
2009-08-03 17:25:56 +04:00
|
|
|
* Sets the internal iterator to the first element in the collection and
|
|
|
|
* returns this element.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2009-01-12 16:34:41 +03:00
|
|
|
public function first()
|
2008-12-18 17:08:11 +03:00
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
return reset($this->_elements);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 17:25:56 +04:00
|
|
|
* Sets the internal iterator to the last element in the collection and
|
|
|
|
* returns this element.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2009-01-12 16:34:41 +03:00
|
|
|
public function last()
|
2008-12-18 17:08:11 +03:00
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
return end($this->_elements);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-03 17:25:56 +04:00
|
|
|
* Gets the current key/index at the current internal iterator position.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function key()
|
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
return key($this->_elements);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
2009-08-03 17:25:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves the internal iterator position to the next element.
|
2009-08-11 01:36:57 +04:00
|
|
|
*
|
|
|
|
* @return mixed
|
2009-08-03 17:25:56 +04:00
|
|
|
*/
|
|
|
|
public function next()
|
|
|
|
{
|
|
|
|
next($this->_elements);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the element of the collection at the current internal iterator position.
|
2009-08-11 01:36:57 +04:00
|
|
|
*
|
|
|
|
* @return mixed
|
2009-08-03 17:25:56 +04:00
|
|
|
*/
|
|
|
|
public function current()
|
|
|
|
{
|
|
|
|
return current($this->_elements);
|
|
|
|
}
|
2008-12-18 17:08:11 +03:00
|
|
|
|
|
|
|
/**
|
2009-05-17 23:27:12 +04:00
|
|
|
* Removes an element with a specific key/index from the collection.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
|
|
|
* @param mixed $key
|
2009-01-12 16:34:41 +03:00
|
|
|
* @return mixed
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function remove($key)
|
|
|
|
{
|
2009-05-17 23:27:12 +04:00
|
|
|
if (isset($this->_elements[$key])) {
|
|
|
|
$removed = $this->_elements[$key];
|
|
|
|
unset($this->_elements[$key]);
|
2009-08-11 01:36:57 +04:00
|
|
|
|
2009-05-17 23:27:12 +04:00
|
|
|
return $removed;
|
|
|
|
}
|
2009-08-11 01:36:57 +04:00
|
|
|
|
2009-05-17 23:27:12 +04:00
|
|
|
return null;
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
2009-01-29 20:00:44 +03:00
|
|
|
/**
|
|
|
|
* Removes the specified element from the collection, if it is found.
|
|
|
|
*
|
|
|
|
* @param mixed $element
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function removeElement($element)
|
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
$key = array_search($element, $this->_elements, true);
|
2009-08-11 01:36:57 +04:00
|
|
|
|
2009-01-29 20:00:44 +03:00
|
|
|
if ($key !== false) {
|
2009-07-01 17:31:11 +04:00
|
|
|
$removed = $this->_elements[$key];
|
2009-02-07 20:02:13 +03:00
|
|
|
unset($this->_elements[$key]);
|
2009-08-11 01:36:57 +04:00
|
|
|
|
2009-07-01 17:31:11 +04:00
|
|
|
return $removed;
|
2009-01-29 20:00:44 +03:00
|
|
|
}
|
2009-08-11 01:36:57 +04:00
|
|
|
|
2009-07-01 17:31:11 +04:00
|
|
|
return null;
|
2009-01-29 20:00:44 +03:00
|
|
|
}
|
|
|
|
|
2008-12-18 17:08:11 +03:00
|
|
|
/**
|
2009-08-11 01:36:57 +04:00
|
|
|
* ArrayAccess implementation of offsetExists()
|
|
|
|
*
|
2009-01-14 00:56:43 +03:00
|
|
|
* @see containsKey()
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function offsetExists($offset)
|
|
|
|
{
|
|
|
|
return $this->containsKey($offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-11 01:36:57 +04:00
|
|
|
* ArrayAccess implementation of offsetGet()
|
|
|
|
*
|
2009-01-14 00:56:43 +03:00
|
|
|
* @see get()
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function offsetGet($offset)
|
|
|
|
{
|
|
|
|
return $this->get($offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-11 01:36:57 +04:00
|
|
|
* ArrayAccess implementation of offsetGet()
|
|
|
|
*
|
2009-01-14 00:56:43 +03:00
|
|
|
* @see add()
|
|
|
|
* @see set()
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function offsetSet($offset, $value)
|
|
|
|
{
|
|
|
|
if ( ! isset($offset)) {
|
|
|
|
return $this->add($value);
|
|
|
|
}
|
|
|
|
return $this->set($offset, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-11 01:36:57 +04:00
|
|
|
* ArrayAccess implementation of offsetUnset()
|
|
|
|
*
|
2009-01-14 00:56:43 +03:00
|
|
|
* @see remove()
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function offsetUnset($offset)
|
|
|
|
{
|
|
|
|
return $this->remove($offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-12 16:34:41 +03:00
|
|
|
* Checks whether the collection contains a specific key/index.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
2009-01-12 16:34:41 +03:00
|
|
|
* @param mixed $key The key to check for.
|
2009-01-14 00:56:43 +03:00
|
|
|
* @return boolean TRUE if the given key/index exists, FALSE otherwise.
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function containsKey($key)
|
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
return isset($this->_elements[$key]);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-12 16:34:41 +03:00
|
|
|
* Checks whether the given element is contained in the collection.
|
|
|
|
* Only element values are compared, not keys. 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.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
2009-01-12 16:34:41 +03:00
|
|
|
* @param mixed $element
|
2009-01-14 00:56:43 +03:00
|
|
|
* @return boolean TRUE if the given element is contained in the collection,
|
|
|
|
* FALSE otherwise.
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
2009-01-12 16:34:41 +03:00
|
|
|
public function contains($element)
|
2008-12-18 17:08:11 +03:00
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
return in_array($element, $this->_elements, true);
|
2009-01-12 16:34:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for the existance of an element that satisfies the given predicate.
|
|
|
|
*
|
2009-02-07 20:02:13 +03:00
|
|
|
* @param Closure $p The predicate.
|
2009-01-29 20:00:44 +03:00
|
|
|
* @return boolean TRUE if the predicate is TRUE for at least one element, FALSE otherwise.
|
2009-01-12 16:34:41 +03:00
|
|
|
*/
|
2009-02-18 00:18:13 +03:00
|
|
|
public function exists(Closure $p)
|
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
foreach ($this->_elements as $key => $element)
|
|
|
|
if ($p($key, $element)) return true;
|
2009-01-12 16:34:41 +03:00
|
|
|
return false;
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-12 16:34:41 +03:00
|
|
|
* Searches for a given element and, if found, returns the corresponding key/index
|
|
|
|
* of that 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.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
2009-01-12 16:34:41 +03:00
|
|
|
* @param mixed $element The element to search for.
|
|
|
|
* @return mixed The key/index of the element or FALSE if the element was not found.
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
2009-01-12 16:34:41 +03:00
|
|
|
public function search($element)
|
2008-12-18 17:08:11 +03:00
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
return array_search($element, $this->_elements, true);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-12 16:34:41 +03:00
|
|
|
* Gets the element with the given key/index.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
2009-01-12 16:34:41 +03:00
|
|
|
* @param mixed $key The key.
|
|
|
|
* @return mixed The element or NULL, if no element exists for the given key.
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function get($key)
|
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
if (isset($this->_elements[$key])) {
|
|
|
|
return $this->_elements[$key];
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-07 20:02:13 +03:00
|
|
|
* Gets all keys/indexes of the collection elements.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getKeys()
|
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
return array_keys($this->_elements);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-12 16:34:41 +03:00
|
|
|
* Gets all elements.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-07-29 15:57:27 +04:00
|
|
|
public function getValues()
|
2008-12-18 17:08:11 +03:00
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
return array_values($this->_elements);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-12 16:34:41 +03:00
|
|
|
* Returns the number of elements in the collection.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
|
|
|
* Implementation of the Countable interface.
|
|
|
|
*
|
2009-08-11 01:36:57 +04:00
|
|
|
* @return integer The number of elements in the collection.
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function count()
|
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
return count($this->_elements);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-12 16:34:41 +03:00
|
|
|
* Adds/sets an element in the collection at the index / with the specified key.
|
|
|
|
*
|
2008-12-18 17:08:11 +03:00
|
|
|
* When the collection is a Map this is like put(key,value)/add(key,value).
|
|
|
|
* When the collection is a List this is like add(position,value).
|
|
|
|
*
|
2009-02-07 20:02:13 +03:00
|
|
|
* @param mixed $key
|
2008-12-18 17:08:11 +03:00
|
|
|
* @param mixed $value
|
|
|
|
*/
|
|
|
|
public function set($key, $value)
|
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
$this->_elements[$key] = $value;
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-12 16:34:41 +03:00
|
|
|
* Adds an element to the collection.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
|
|
|
* @param mixed $value
|
2009-02-07 20:02:13 +03:00
|
|
|
* @return boolean Always TRUE.
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
2009-01-12 16:34:41 +03:00
|
|
|
public function add($value)
|
2008-12-18 17:08:11 +03:00
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
$this->_elements[] = $value;
|
2008-12-18 17:08:11 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the collection is empty.
|
2009-06-14 21:34:28 +04:00
|
|
|
*
|
2009-01-12 16:34:41 +03:00
|
|
|
* Note: This is preferrable over count() == 0.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
|
|
|
* @return boolean TRUE if the collection is empty, FALSE otherwise.
|
|
|
|
*/
|
|
|
|
public function isEmpty()
|
|
|
|
{
|
2009-07-30 19:16:02 +04:00
|
|
|
return ! $this->_elements;
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-07 20:02:13 +03:00
|
|
|
* Gets an iterator for iterating over the elements in the collection.
|
2008-12-18 17:08:11 +03:00
|
|
|
*
|
2009-01-12 16:34:41 +03:00
|
|
|
* @return ArrayIterator
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function getIterator()
|
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
return new ArrayIterator($this->_elements);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
2009-01-04 19:15:32 +03:00
|
|
|
/**
|
2009-01-12 16:34:41 +03:00
|
|
|
* Applies the given function to each element in the collection and returns
|
2009-02-07 20:02:13 +03:00
|
|
|
* a new collection with the elements returned by the function.
|
2009-01-04 19:15:32 +03:00
|
|
|
*
|
2009-02-07 20:02:13 +03:00
|
|
|
* @param Closure $func
|
2009-08-11 01:36:57 +04:00
|
|
|
* @return Collection
|
2009-01-12 16:34:41 +03:00
|
|
|
*/
|
2009-01-14 00:56:43 +03:00
|
|
|
public function map(Closure $func)
|
2009-01-12 16:34:41 +03:00
|
|
|
{
|
2009-07-29 15:57:27 +04:00
|
|
|
return new ArrayCollection(array_map($func, $this->_elements));
|
2009-01-12 16:34:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-07 20:02:13 +03:00
|
|
|
* Returns all the elements of this collection that satisfy the predicate p.
|
|
|
|
* The order of the elements is preserved.
|
2009-01-04 19:15:32 +03:00
|
|
|
*
|
2009-02-07 20:02:13 +03:00
|
|
|
* @param Closure $p The predicate used for filtering.
|
|
|
|
* @return Collection A collection with the results of the filter operation.
|
2009-01-04 19:15:32 +03:00
|
|
|
*/
|
2009-02-07 20:02:13 +03:00
|
|
|
public function filter(Closure $p)
|
2009-01-12 16:34:41 +03:00
|
|
|
{
|
2009-07-29 15:57:27 +04:00
|
|
|
return new ArrayCollection(array_filter($this->_elements, $p));
|
2009-01-04 19:15:32 +03:00
|
|
|
}
|
|
|
|
|
2008-12-18 17:08:11 +03:00
|
|
|
/**
|
2009-02-07 20:02:13 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
2009-02-18 00:18:13 +03:00
|
|
|
public function forAll(Closure $p)
|
2009-02-07 20:02:13 +03:00
|
|
|
{
|
2009-02-18 00:18:13 +03:00
|
|
|
foreach ($this->_elements as $key => $element) {
|
|
|
|
if ( ! $p($key, $element)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-08-11 01:36:57 +04:00
|
|
|
|
2009-02-07 20:02:13 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
$coll1 = $coll2 = array();
|
|
|
|
foreach ($this->_elements as $key => $element) {
|
|
|
|
if ($p($key, $element)) {
|
|
|
|
$coll1[$key] = $element;
|
|
|
|
} else {
|
|
|
|
$coll2[$key] = $element;
|
|
|
|
}
|
|
|
|
}
|
2009-07-29 15:57:27 +04:00
|
|
|
return array(new ArrayCollection($coll1), new ArrayCollection($coll2));
|
2009-02-07 20:02:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string representation of this object.
|
2009-08-11 01:36:57 +04:00
|
|
|
*
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
2009-01-04 19:15:32 +03:00
|
|
|
return __CLASS__ . '@' . spl_object_hash($this);
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the collection.
|
2009-08-11 01:36:57 +04:00
|
|
|
*
|
2008-12-18 17:08:11 +03:00
|
|
|
*/
|
|
|
|
public function clear()
|
|
|
|
{
|
2009-02-07 20:02:13 +03:00
|
|
|
$this->_elements = array();
|
2008-12-18 17:08:11 +03:00
|
|
|
}
|
2009-07-28 15:43:42 +04:00
|
|
|
}
|