Last active
October 12, 2016 08:42
-
-
Save adammbalogh/10cf761f764e8b7122a4c2fbfb0bbcde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ProjectMysqlRepository implements ProjectRepository | |
{ | |
/** | |
* @param Project $project | |
* | |
* @return Project | |
*/ | |
public function save(Project $project) | |
{ | |
# Build an array from $project | |
# If $project->getId() is null then insert, else update based on the key(s) | |
$dbTasks = []; | |
try { | |
foreach ($project->getTaskCollection() as $task) { | |
$dbTasks[] = $this->taskRepsitory->save($task); | |
} | |
} catch (TasksAreNotAccessibleException $e) { | |
# nothing to do | |
} | |
# We could use UUID as well | |
# If we use regular id we can get the last inserted id ($id) | |
return new DbProject($id, $project->getName(), $dbTasks); | |
} | |
/** | |
* @param int $projectId | |
* | |
* @return Project | |
*/ | |
public function findById($projectId) | |
{ | |
# Project select statement | |
# If project is not found thrown an exception | |
return new DbProject($id, $name, null); | |
} | |
/** | |
* @param int $projectId | |
* | |
* @return Project | |
*/ | |
public function findByIdWithTasks($projectId) | |
{ | |
# Project select statement | |
# If project is not found thrown an exception | |
$dbTasks = $this->taskRepository->findByProjectId($projectId); | |
return new DbProject($id, $name, $dbTasks); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment