I currently have this client code in my PHP MVC web application:
try { BookMapper::insert($book); } catch (DbUniqueConstraintViolationException $e) { $errorList->addMessage($book . " already exists!"); }
I am wondering if it is not bad to use links to low-level Db * frameworks for my client code? If so, should I change my model code as follows:
class BookAlreadyExistsException extends Exception { } class BookMapper { public static function insert($book) { try {
and then use this new client code ...
try { BookMapper::insert($book); } catch (BookAlreadyExistsException $e) { $errorList->addMessage($book . " already exists!"); }
Or something else? Or is it an original method?
Thanks!
EDIT: I just want to add, the last method reads the best IMO, but it is related to the creation / reorganization of the object and, more importantly, it requires duplication of the reorganization code in each mapper insert () method. The first method is easy to implement and catch and works for any model, but I remember reading somewhere that you should not do this?
Doublej
source share