/** * @param object|array|null $row * @param string $prefix * @return object|null */ function hydrateObject($row, $prefix = '') { $result = null; if ($row) { $class = $this->_getClassName(); $result = new $class(); ObjectHelper::copyExistingProperties($row, $result, $prefix); } return $result; }
function testPrefixTreeFromObject() { $from = (object) array('id' => 1, 'name' => 'name', 'email' => 'email', 'g_id' => 2, 'g_name' => 'group_name', 'r_id' => 3, 'r_name' => 'role_name'); $user = new User(); $group = new Group(); $role = new Role(); ObjectHelper::copyExistingProperties($from, $user); ObjectHelper::copyExistingProperties($from, $group, 'g_'); ObjectHelper::copyExistingProperties($from, $role, 'r_'); $this->assertEquals($from->id, $user->id); $this->assertEquals($from->name, $user->name); $this->assertEquals($from->email, $user->email); $this->assertEquals($from->g_id, $group->id); $this->assertEquals($from->g_name, $group->name); $this->assertEquals($from->r_id, $role->id); $this->assertEquals($from->r_name, $role->name); }