Hi Toby,
your question may be an additional use case for an
ezcPersistentObjectCollection class, which I've started just thursday.
My use case was, to get an array of a specific property of all
persistent objects in the collection. You could add a method to get an
array of the objects with the idProperty as keys.
<?php
class ezcPersistentObjectCollection
{
/**
* The class of the objects in this collection
*
* @var string
*/
private $class;
/**
* The objects of this collection, all of type $this->class
*
* @var mixed
*/
private $objects = array();
/**
* Persistent Session instance for the given objects.
*
* @var ezcPersistentSession
*/
private $pos;
public function __construct( ezcPersistentSession $pos, Array $objects =
array() )
{
$this->pos = $pos;
if( !empty( $objects ) )
{
$class = $this->class = get_class( $objects[0] );
foreach( $objects as $object )
{
if( !get_class( $object ) === $class )
{
throw new Exception( 'Collection has been initialized for
class '.$class.' but got object of class '.get_class( $object ) );
}
$this->objects[] = $object;
}
}
}
public function getPropertyValues( $property )
{
$values = array();
foreach( $this->objects as $object )
{
$values[] = $object->$property;
}
return $values;
}
}
Best regards,
--
Thomas Koch, http://www.koch.ro
YMC AG, http://www.ymc.ch
--
Components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/components