Created
July 23, 2019 10:12
-
-
Save romaninsh/479539677cea1b183d8ab6b9b46d6166 to your computer and use it in GitHub Desktop.
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 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