Created
July 21, 2016 08:03
-
-
Save Moccine/6df769262d4528174dfe5a51f19fcfaa to your computer and use it in GitHub Desktop.
MVC Services
This file contains hidden or 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 | |
namespace project\Services; | |
class Viewer | |
{ | |
public $viewpath; | |
public $parameters; | |
public $viewParameters; | |
public $controllerParameters; | |
public $dynamizer; | |
public function __construct() | |
{ | |
$this->dynamizer = new Dynamizer(); | |
} | |
/** | |
* @param $parameters | |
* @return $this | |
*/ | |
public function setParameters($parameters) | |
{ | |
$this->parameters = $parameters; | |
return $this; | |
} | |
/** | |
* @param $parameters | |
* @return $this | |
*/ | |
public function sethelper($helper) | |
{ | |
$helper = strtolower($helper); | |
$this->dynamizer->setHelper($helper); | |
return $this; | |
} | |
/** | |
* @param mixed $viewParameters | |
* @return Viewer | |
*/ | |
public function setViewParameters($viewParameters) | |
{ | |
$this->viewParameters = $viewParameters; | |
return $this; | |
} | |
/** | |
* @param mixed $controllerParameters | |
* @return Viewer | |
*/ | |
public function setControllerParameters($controllerParameters) | |
{ | |
$this->controllerParameters = $controllerParameters; | |
return $this; | |
} | |
/** | |
* create | |
* rend la vue | |
* @throws \Exception | |
*/ | |
public function render() | |
{ | |
$view = file_get_contents($this->createPath()); | |
echo $this->dynamizer->setParameters($this->controllerParameters)->setView($view)->dynamise(); | |
} | |
function createPath() | |
{ | |
list($controller, $action) = $this->parameters; | |
$path = sprintf('../Src/project/Views/%sViews/%s.html', lcfirst($controller), $action); | |
if (!file_exists($path)) { | |
throw new \Exception("$path not found"); | |
} | |
return $this->viewpath = $path; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment