_contactsById = array(); $this->_contactsByUsername = array(); foreach ($data->contacts as $contact) { $contact = new Zend_Service_RememberTheMilk_Contact($contact); $this->_contactsById[$contact->getId()] = $contact; $this->_contactsByUsername[$contact->getUsername()] = $contact; } } /** * Implementation of IteratorAggregate::getIterator(). * * @return ArrayIterator */ public function getIterator() { return new ArrayIterator($this->_contactsById); } /** * Implementation of IteratorAggregate::getLength(). * * @return int */ public function getLength() { return count($this->_contactsById); } /** * Returns the contact instance with the specified identifier. * * @param int $id Identifier for the contact * @return Zend_Service_RememberTheMilk_Contact */ public function getContactById($id) { if (isset($this->_contactsById[$id])) { return $this->_contactsById[$id]; } return null; } /** * Returns the contact instance with the specified username. * * @param string $username Username for the contact * @return Zend_Service_RememberTheMilk_Contact */ public function getContactByUsername($username) { if (isset($this->_contactsByUsername[$username])) { return $this->_contactsByUsername[$username]; } return null; } }