Sağlıksız Dünyamız

Page 253

The Table Data Gateway Pattern

require_once ‘adodb/adodb-iterator.inc.php’; class AdoResultSetIteratorDecorator implements Iterator { protected $rs; public function __construct($rs) { $this->rs = new ADODB_Iterator($rs); } public function current() { return $this-> >rs-> >fetchObj(); } public function next() { return $this->rs->next(); } public function key() { return $this->rs->key(); } public function valid() { return $this->rs->valid(); } public function rewind() { return $this->rs->rewind(); } }

Here, most of the Iterator interface method is proxied to the decorated result set, but the current() method is overridden to return the result of the fetchObj() method. Back to the Table Data Gateway, you should now understand how findByTag() works.

class BookmarkGateway { // ... public function findByTag($tag) { $rs = $this->conn->execute( ‘select * from bookmark where tag like ?’ ,array($tag.’%’)); return new AdoResultSetIteratorDecorator($rs); } }

Updating Rows Next, let’s tackle the “update” of CRUD. Conceptually, you need to populate the table, find an object, change it, store it, and then find it again to verify that the change has been persisted. Returning to the TableDataGatewayTestCase, here’s the code to find a record...

255


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.