Last active
December 14, 2015 17:09
-
-
Save stephenmelrose/5120759 to your computer and use it in GitHub Desktop.
MVP design/approach.
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 | |
$repository = new Repository(); | |
$data = new Data($repository); | |
$controller = new Controller($data); | |
$controller->executeAction($_GET['something']); |
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 Repository | |
{ | |
public function getEntities() { | |
// Do database query and return results | |
} | |
} | |
class Data | |
{ | |
protected $repository; | |
public function __construct(Repository $repository) { | |
$this->repository = $repository; | |
} | |
public function getData($requestParam) { | |
$entities = $this->repository->getEntities(); | |
// Do some logic on said entities | |
return array( | |
'entities' => $entities, | |
'otherData' => $otherData | |
); | |
} | |
} | |
class Presenter | |
{ | |
public function setData(array $data) { | |
// Store data internally | |
} | |
public function render() { | |
// Convert set data into view data and render HTML using it | |
return $html; | |
} | |
} | |
class Controller | |
{ | |
protected $data; | |
public function __construct(Data $data) { | |
$this->data = $data; | |
} | |
public function executeAction($requestParam) { | |
$rawData = $data->getData($requestParam); | |
$presenter = new Presenter(); | |
$presenter->setData($rawData); | |
return $presenter->render(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment