Created error model and view

pull/1/head
Jonah Lawrence 3 years ago
parent 4d5cf33d32
commit 5b91fadef2

@ -10,10 +10,8 @@ try {
// create renderer model
$model = new RendererModel("templates/main.php", $_REQUEST);
} catch (InvalidArgumentException $error) {
// display error svg
$message = $error->getMessage();
require_once "templates/error.php";
exit;
// create error rendering model
$model = new RendererModel("templates/error.php", $error->getMessage());
}
// create renderer view

@ -0,0 +1,22 @@
<?php declare (strict_types = 1);
/**
* Model for error messages
*/
class ErrorModel
{
/** @var string $message text to display */
public $message;
/**
* Construct ErrorModel
*
* @param string $message text to display
* @param string $template path to the template file
*/
public function __construct($template, $message)
{
$this->message = $message;
$this->template = $template;
}
}

@ -0,0 +1,38 @@
<?php declare (strict_types = 1);
/**
* View for rendering error messages
*/
class ErrorView
{
/**
* @var ErrorModel $model
*/
private $model;
/**
* Constructor for Error View
* @param ErrorModel $model
*/
public function __construct($model)
{
$this->model = $model;
}
/**
* Render SVG Output
* @return string
*/
public function output()
{
// import variables into symbol table
extract(["message" => $this->model->lines]);
// render SVG with output buffering
ob_start();
require_once $this->model->template;
$output = ob_get_contents();
ob_end_clean();
// return rendered output
return $output;
}
}
Loading…
Cancel
Save