53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Picea\Exception;
|
||
|
|
||
|
use Picea\Picea;
|
||
|
|
||
|
/**
|
||
|
* Whenever an error occured rendering a view, this is the exception that will show up.
|
||
|
*
|
||
|
*/
|
||
|
class RenderHtmlException extends \Exception
|
||
|
{
|
||
|
protected Picea $picea;
|
||
|
|
||
|
public function __construct(object $compiledObject, Picea $picea, string $message, int $code, \Throwable $previous)
|
||
|
{
|
||
|
parent::__construct($message, $code, $previous);
|
||
|
|
||
|
$this->picea = $picea;
|
||
|
|
||
|
$this->defineError($previous, $compiledObject);
|
||
|
}
|
||
|
|
||
|
protected function defineError(\Throwable $previous, object $compiledObject) : void
|
||
|
{
|
||
|
$loadedTemplates = array_flip($this->picea->loadedTemplateFile);
|
||
|
|
||
|
foreach($previous->getTrace() as $trace) {
|
||
|
if ( isset($trace['file'], $loadedTemplates[$trace['file']]) ) {
|
||
|
$class = $loadedTemplates[ $trace['file'] ];
|
||
|
|
||
|
$content = include($trace['file']);
|
||
|
|
||
|
$this->file = $content['view'];
|
||
|
$this->line = $class::getSourceLineFromException($trace['line']);
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected function getTemplateFile(string $filePath) : ? array
|
||
|
{
|
||
|
$content = null;
|
||
|
|
||
|
if ( is_array($content) && isset($content['classname'], $content['namespace'], $content['view'], $content['extends']) ) {
|
||
|
return $content;
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
}
|