ZF-Commons / ZfcUser

A generic user registration and authentication module for ZF2. Supports Zend\Db and Doctrine2. (Formerly EdpUser)
BSD 3-Clause "New" or "Revised" License
497 stars 343 forks source link

[RFC] Simplifying the mapper layer #559

Open adamlundrigan opened 9 years ago

adamlundrigan commented 9 years ago

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.

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 commented 9 years ago

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.