Skip to content
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] Simplifying the mapper layer #559

Open
adamlundrigan opened this issue Jan 26, 2015 · 1 comment
Open

[RFC] Simplifying the mapper layer #559

adamlundrigan opened this issue Jan 26, 2015 · 1 comment

Comments

@adamlundrigan
Copy link
Contributor

The AbstractDbMapper provided by ZfcBase, and by extension ZfcUser's UserMapper, duplicate a ton of work that can easily be handed off to ZF2's built-in TableGateway system.

  • Building and executing SQL queries
  • Hydrating result of select() calls
  • Master/Slave adapter support

Utilizing TableGateway would strip ZfcUser's mapper down from ~400 lines (including AbstractDbMapper) to ~125 and remove the hard dependency on ZfcBase\Mapper\AbstractDbMapper, leaving ZfcUser's mapper as a just a thin wrapper around TableGateway that provides convenience methods (findBy*) and extracts entities passed to insert/update/delete methods.

An initial prototype of the refactoring can be diffed here. The modifications build on the result of #554, so I will submit a PR for this changeset once that PR has been completed.

@adamlundrigan
Copy link
Contributor Author

One issue I've had with the previous mapper is with custom queries on the user table. AbstractDbMapper exposes getAdapter so you could do queries directly against that, but I found it better to just extend the mapper class and add a custom method for my query...which works fine until you get two modules that want a custom query each.

IMO the most straightforward solution would be to expose the TableGateway's selectWith method, though I'm not a fan of the encapsulation leak of having to know the database column names to build the query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant