mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 01:04:12 +02:00
ObjectController: refactor initalization
This commit is contained in:
parent
34d5e445b2
commit
13c09855fa
@ -63,47 +63,56 @@ abstract class ObjectController extends ActionController
|
|||||||
{
|
{
|
||||||
parent::init();
|
parent::init();
|
||||||
$this->enableStaticObjectLoader($this->getTableName());
|
$this->enableStaticObjectLoader($this->getTableName());
|
||||||
|
|
||||||
if ($this->getRequest()->isApiRequest()) {
|
if ($this->getRequest()->isApiRequest()) {
|
||||||
$handler = new IcingaObjectHandler($this->getRequest(), $this->getResponse(), $this->db());
|
$this->initializeRestApi();
|
||||||
try {
|
|
||||||
$this->loadOptionalObject();
|
|
||||||
} catch (NotFoundError $e) {
|
|
||||||
// Silently ignore the error, the handler will complain
|
|
||||||
$handler->sendJsonError($e, 404);
|
|
||||||
// TODO: nice shutdown
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$handler->setApi($this->api());
|
|
||||||
if ($this->object) {
|
|
||||||
$handler->setObject($this->object);
|
|
||||||
}
|
|
||||||
$handler->dispatch();
|
|
||||||
// Hint: also here, hard exit. There is too much magic going on.
|
|
||||||
// Letting this bubble up smoothly would be "correct", but proved
|
|
||||||
// to be too fragile. Web 2, all kinds of pre/postDispatch magic,
|
|
||||||
// different view renderers - hard exit is the only safe bet right
|
|
||||||
// now.
|
|
||||||
exit;
|
|
||||||
} else {
|
} else {
|
||||||
|
$this->initializeWebRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initializeRestApi()
|
||||||
|
{
|
||||||
|
$handler = new IcingaObjectHandler($this->getRequest(), $this->getResponse(), $this->db());
|
||||||
|
try {
|
||||||
$this->loadOptionalObject();
|
$this->loadOptionalObject();
|
||||||
if ($this->getRequest()->getActionName() === 'add') {
|
} catch (NotFoundError $e) {
|
||||||
$this->addSingleTab(
|
// Silently ignore the error, the handler will complain
|
||||||
sprintf($this->translate('Add %s'), ucfirst($this->getType())),
|
$handler->sendJsonError($e, 404);
|
||||||
null,
|
// TODO: nice shutdown
|
||||||
'add'
|
exit;
|
||||||
);
|
}
|
||||||
} else {
|
|
||||||
$this->tabs(new ObjectTabs(
|
$handler->setApi($this->api());
|
||||||
$this->getRequest()->getControllerName(),
|
if ($this->object) {
|
||||||
$this->getAuth(),
|
$handler->setObject($this->object);
|
||||||
$this->object
|
}
|
||||||
));
|
$handler->dispatch();
|
||||||
}
|
// Hint: also here, hard exit. There is too much magic going on.
|
||||||
if ($this->object !== null) {
|
// Letting this bubble up smoothly would be "correct", but proved
|
||||||
$this->addDeploymentLink();
|
// to be too fragile. Web 2, all kinds of pre/postDispatch magic,
|
||||||
}
|
// different view renderers - hard exit is the only safe bet right
|
||||||
|
// now.
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initializeWebRequest()
|
||||||
|
{
|
||||||
|
$this->loadOptionalObject();
|
||||||
|
if ($this->getRequest()->getActionName() === 'add') {
|
||||||
|
$this->addSingleTab(
|
||||||
|
sprintf($this->translate('Add %s'), ucfirst($this->getType())),
|
||||||
|
null,
|
||||||
|
'add'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->tabs(new ObjectTabs(
|
||||||
|
$this->getRequest()->getControllerName(),
|
||||||
|
$this->getAuth(),
|
||||||
|
$this->object
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if ($this->object !== null) {
|
||||||
|
$this->addDeploymentLink();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user