add Kernel option to return raw content

This commit is contained in:
Thomas Rubini 2023-01-23 19:12:34 +01:00
parent a4fcfb08e3
commit 0446757cbb
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
3 changed files with 19 additions and 4 deletions

View File

@ -64,15 +64,21 @@ final class controller
}
$B_called = call_user_func_array(array(
$called = call_user_func_array(array(
new $this->_A_urlParts['controller'],
$this->_A_urlParts['action']),
array($this->_A_urlParams, $this->_A_postParams, $this->_A_getParams)
);
if (false === $B_called) {
if (false === $called) {
throw new ControllerException("Action " . $this->_A_urlParts['action'] .
" of controller " . $this->_A_urlParts['controller'] . " failed.");
}
if(Utils::RETURN_RAW === $called){
return Utils::RETURN_RAW;
}else{
return Utils::RETURN_HTML;
}
}
}

View File

@ -3,6 +3,9 @@
final class Utils
{
public const RETURN_HTML = 2;
public const RETURN_RAW = 3;
public static function getOrDie($DICT, $key)
{
if (isset($DICT[$key])) return $DICT[$key];

View File

@ -19,7 +19,7 @@
try
{
$O_controller = new Controller($S_url, $A_postParams, $A_getParams);
$O_controller->execute();
$ret = $O_controller->execute();
}
catch (ControleurException $O_exception)
{
@ -29,4 +29,10 @@
$content = View::closeBuffer();
View::show('html', array('body' => $content));
if($ret === Utils::RETURN_HTML){
View::show('html', array('body' => $content));
}else if($ret === Utils::RETURN_RAW){
echo $content;
}else{
throw new Exception("Invalid return value: $ret");
}