mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-06 06:57:25 +02:00
don't repeat yourself
This commit is contained in:
@@ -74,12 +74,7 @@ class UserMapper
|
|||||||
}
|
}
|
||||||
$row = $result->current();
|
$row = $result->current();
|
||||||
|
|
||||||
$user = new User();
|
return $this->mapObject($row);
|
||||||
$user->setUserID($row['userid']);
|
|
||||||
$user->setUsername($row['username']);
|
|
||||||
$user->setEmail($row['email']);
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,15 +89,26 @@ class UserMapper
|
|||||||
$entries = array();
|
$entries = array();
|
||||||
|
|
||||||
foreach ($resultSet as $row) {
|
foreach ($resultSet as $row) {
|
||||||
|
$entries[] = $this->mapObject($row);
|
||||||
$entry = new User();
|
|
||||||
$entry->setUserID($row['userid']);
|
|
||||||
$entry->setUsername($row['username']);
|
|
||||||
$entry->setEmail($row['email']);
|
|
||||||
|
|
||||||
$entries[] = $entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Maps a table row to an object
|
||||||
|
*
|
||||||
|
* @param array $row
|
||||||
|
*
|
||||||
|
* @return \DesignPatterns\DataMapper\User
|
||||||
|
*/
|
||||||
|
protected function mapObject(array $row)
|
||||||
|
{
|
||||||
|
$entry = new User();
|
||||||
|
$entry->setUserID($row['userid']);
|
||||||
|
$entry->setUsername($row['username']);
|
||||||
|
$entry->setEmail($row['email']);
|
||||||
|
|
||||||
|
return $entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user