Skip to content

Instantly share code, notes, and snippets.

@Zvax

Zvax/mapper.php Secret

Created April 18, 2018 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zvax/5d4341ea99adf5205d2f72ac7d23bb5a to your computer and use it in GitHub Desktop.
Save Zvax/5d4341ea99adf5205d2f72ac7d23bb5a to your computer and use it in GitHub Desktop.
some entity collection shit
private function fetchSomeCollection(SomeCollection $collection): bool
{
if (($condition = $collection->getCondition()) && ($id = $condition->getId())) {
$stmt = $this->pdo->prepare('
SELECT manyShits
FROM aTable
JOIN someShit
JOIN someMoreShit
WHERE anCondition=:id
ORDER BY suchOrder
');
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
$stmt->execute();
foreach ($stmt->fetchAll() as $row) {
$collection[] = (new SomeEntity)
->setProperty($row['property']); // many times
}
return true;
}
throw new \LogicException('you tried to fetch a collection without recognized condition you fucktard');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment