New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RfC / DevCon 2015: Repository layer #81

chriskapp opened this Issue Oct 27, 2015 · 2 comments


None yet
2 participants

chriskapp commented Oct 27, 2015

The model classes have at the moment many tasks. At first they represent a row from the database.
Then they have static methods for data retrieval i.e. getObjectList, getObjectCount and in most
cases they have also methods which contain business logic. It would be great to simplify theses
objects (SRP). So a first step could be to create another "repository" layer which handles all
data retrieval and manipulation. In an action this could look like this:

public function actionList()
    $repository = $this->repository->getRepository('class_module_news_news');

    // get all objects
    $news = $repository->getObjectList();

    // get count
    $count = $repository->getObjectCount();

    // get an specific object with the id
    $news = $repository->get($id);

    // update object

    // delete object

    // copy object
    $newObject = $repository->copyObject($oldNews, $strNewPrevid);

Since the repository would have the same API as the model it would be probably easier to refactor.
Through this we could move a hole bunch of methods from the model into the repository and make the model more like a simple value object. Also we should unify the filter options in each getObjectList/getObjectCount method with a filter object instead of having many arguments.


This comment has been minimized.


sidler commented Oct 27, 2015

The repository could be the current orm layer, or do you think of another layer? but separating the models to different objects makes totally sense.
And the unification of getObjectList(Count) is a good idea


This comment has been minimized.


chriskapp commented Oct 28, 2015

Yes thats true and I think we should use the current orm layer. With "another layer" I meant that it should be possible to create a custom repository class which can provide a custom getObjectList/getObjectCount implementation. Maybe we should add a new annotation to the model class which reference the repository class of the model. Doctrine has the same approach to define a custom repository class for the model:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment