Skip to content

Instantly share code, notes, and snippets.

@romaninsh
Created July 23, 2019 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romaninsh/479539677cea1b183d8ab6b9b46d6166 to your computer and use it in GitHub Desktop.
Save romaninsh/479539677cea1b183d8ab6b9b46d6166 to your computer and use it in GitHub Desktop.
<?php
namespace saasty\View;
/**
* A very basic view which may contain other elements that are likely to throw exception during render. In which case,
* the exception will be contained within the view and won't break any of the other UI.
*/
class Volatile extends \atk4\ui\View
{
public $fx = null;
function set($cb = null, $arg2 = null) {
$this->fx = $cb;
return $this;
}
function recursiveRender() {
try {
parent::recursiveRender();
} catch(\Throwable $e) {
//$this->output('ouch');
//$v = $this->add(['Message', 'We have a problem', 'error']);
if ($e instanceof \atk4\core\Exception) {
$msg = $e->getMessage();
$content = $e->getHTML();
} elseif ($e instanceof \Error) {
$msg = get_class($e).': '.$e->getMessage().' (in '.$e->getFile().':'.$e->getLine().')';
$content = nl2br($e->getTraceAsString());
} else {
$msg = get_class($e).': '.$e->getMessage();
$content = null;
}
if ($this->fx) {
$v = $this->add('View');
call_user_func($this->fx, $v, $msg, $content);
$this->template->appendHTML('Content', $v->getHTML());
$this->app->html->template->appendHTML('HEAD', $v->getJS());
} else {
$this->template->appendHTML('Content', $content);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment