ActionController: provide response-helper for all

...controllers
This commit is contained in:
Thomas Gelf 2020-10-26 16:39:36 +01:00
parent db8a14e854
commit 24a5411a93
2 changed files with 11 additions and 19 deletions

View File

@ -11,20 +11,6 @@ class ImportsourcesController extends ActionController
{ {
protected $isApified = true; protected $isApified = true;
protected function sendUnsupportedMethod()
{
$method = strtoupper($this->getRequest()->getMethod()) ;
$response = $this->getResponse();
$this->sendJsonError($response, sprintf(
'Method %s is not supported',
$method
), 422); // TODO: check response code
}
/**
* @throws \Icinga\Exception\ConfigurationError
* @throws \Icinga\Exception\Http\HttpNotFoundException
*/
public function indexAction() public function indexAction()
{ {
if ($this->getRequest()->isApiRequest()) { if ($this->getRequest()->isApiRequest()) {
@ -55,16 +41,12 @@ class ImportsourcesController extends ActionController
/** /**
* @param $raw * @param $raw
* @throws \Icinga\Exception\ConfigurationError
*/ */
protected function acceptImport(&$raw) protected function acceptImport($raw)
{ {
(new ImportExport($this->db()))->unserializeImportSources(json_decode($raw)); (new ImportExport($this->db()))->unserializeImportSources(json_decode($raw));
} }
/**
* @throws \Icinga\Exception\ConfigurationError
*/
protected function sendExport() protected function sendExport()
{ {
$this->sendJson( $this->sendJson(

View File

@ -188,6 +188,16 @@ abstract class ActionController extends Controller implements ControlsAndContent
return $this; return $this;
} }
protected function sendUnsupportedMethod()
{
$method = strtoupper($this->getRequest()->getMethod()) ;
$response = $this->getResponse();
$this->sendJsonError($response, sprintf(
'Method %s is not supported',
$method
), 422); // TODO: check response code
}
/** /**
* @param string $permission * @param string $permission
* @return $this * @return $this