public function getResponse($type = '', $useOriginal = false)
{
if ($type == '') {
$type = $this->defaultResponseType;
}
if ($useOriginal) {
$responses =& App::config()->_coreResponses;
} else {
$responses =& App::config()->responses;
}
$coord = App::router();
if (!isset($responses[$type])) {
if ($coord->action) {
$action = $coord->action->resource;
$path = $coord->action->getPath();
} else {
$action = $coord->moduleName . '~' . $coord->actionName;
$path = '';
}
if ($type == $this->defaultResponseType) {
throw new \jException('jelix~errors.default.response.type.unknown', array($action, $type));
} else {
throw new \jException('jelix~errors.ad.response.type.unknown', array($action, $type, $path));
}
}
$respclass = $responses[$type];
$path = $responses[$type . '.path'];
if (!class_exists($respclass, false)) {
require $path;
}
$response = new $respclass();
if (!$this->isAllowedResponse($response)) {
throw new \jException('jelix~errors.ad.response.type.notallowed', array($coord->action->resource, $type, $coord->action->getPath()));
}
$coord->response = $response;
return $response;
}