PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1

CHAPTER 13 ■ DATABASE PATTERNS


Figure 13–10. Selection and update factories


Selection and update factories are, once again, typically organized so that they parallel the domain
objects in a system (possibly mediated via identity objects). Because of this, they are also candidates for
my PersistenceFactory: the Abstract Factory I maintain as a one-stop shop for domain object
persistence tools. Here is an implementation of a base class for update factories:


namespace woo\mapper;


abstract class UpdateFactory {


abstract function newUpdate( \woo\domain\DomainObject $obj );


protected function buildStatement( $table, array $fields, array $conditions=null ) {
$terms = array();
if (! is_null( $conditions ) ) {
$query = "UPDATE {$table} SET ";

Free download pdf