Skip to content

Instantly share code, notes, and snippets.

@Moccine
Created July 21, 2016 08:03
Show Gist options
  • Save Moccine/6df769262d4528174dfe5a51f19fcfaa to your computer and use it in GitHub Desktop.
Save Moccine/6df769262d4528174dfe5a51f19fcfaa to your computer and use it in GitHub Desktop.
MVC Services
<?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