/** * Callback after walking over the results. * Returns everything to its original state. * @return Void */ protected function _afterWalk() { // return the pointer of a Rowset to 0 if ($this->_result instanceof Garp_Db_Table_Rowset) { $this->_result->rewind(); } else { // also, return results to the original format if it was no Rowset to begin with. $this->_result = $this->_result[0]; } }
public function testShouldMap() { $things = new Garp_Db_Table_Rowset(array('data' => array(array('id' => 3, 'name' => 'hendrik', 'intro' => 'lorem ipsum dolor sit amet'), array('id' => 2, 'name' => 'klaas', 'intro' => 'lorem ipsum dolor sit amet'), array('id' => 1, 'name' => 'henk', 'intro' => 'lorem ipsum dolor sit amet')), 'rowClass' => 'Garp_Db_Table_Row')); $mappedThings = $things->map(function ($item) { $item['name'] = strtoupper($item['name']); return $item; }); $this->assertEquals('Garp_Db_Table_Rowset', get_class($mappedThings)); $this->assertEquals('HENK', $mappedThings[2]['name']); $this->assertEquals('HENDRIK', $mappedThings[0]['name']); // $things should be unchanged $this->assertFalse($mappedThings === $things); $this->assertEquals('hendrik', $things[0]['name']); // can callback use local vars? $start = 0; $end = 1; $initials = $mappedThings->map(function ($item) use($start, $end) { $item['name'] = substr($item['name'], $start, $end); return $item; }); $this->assertEquals('H', $initials[0]['name']); $this->assertEquals('K', $initials[1]['name']); }