tags:

views:

13

answers:

0

Hi all,

I'm trying to design and build a flexible user repository (as an extension to Zend Framework) that I can easily drop in new projects.

What I have in mind are the following classes:

UserRepository
UserRepository_Adapter_Interface
UserRepository_Adapter_DbTable implements UserRepository_Adapter_Interface
UserRepository_Adapter_Test implements UserRepository_Adapter_Interface
..etc

UserList implements SeekableIterator, Countable

Model_User
Model_User_Adapter_Interface
Model_User_Adapter_DbTableRow implements Model_User_Adapter_Interface
Model_User_Adapter_Test implements Model_User_Adapter_Interface
..etc

Now, obviously, I want the repository to give me a single Model_User object with

UserRepository::getUserById( $id )

and a UserList of Model_User objects with methods like

UserRepository::getUsersByRole( $role )

I provide the UserRepository with a mandatory adapter in it's constructor, especially with future use of DI in mind.

But now comes the tricky part: A Model_User object should be provided with an adapter (maybe adapter is not the correct term, datamapper maybe?) as well. This adapter wraps around the provided data object of the backend (and will be able to map fields to fields that the Model_User expects by providing the adapter with a optional transformMap).

How would you go about letting this choice of Model_User_Adapter_Interface trickle through from the UserRepository object, to the generated UserList, which needs to provide it's Model_User objects with the data wrapped in the Model_User_Adapter_Interface as well?

I'm getting kind of stuck in that UserList at first expected an array of data so far and based on this creates Model_User objects on the fly when iterated through. But the Model_User_Adapter_Interface expects data dependent on what the adapter is for.

Should I perhaps create the Model_User objects in the UserRepository already and not in the UserList?

I'm curious on your thoughts about this. If something is not clear enough, feel free to ask and I will elaborate (even more ;-) )