mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-29 16:54:06 +02:00
DirectorDb: new controller extension
This commit is contained in:
parent
7502706284
commit
e88c13663f
34
library/Director/Web/Controller/Extension/DirectorDb.php
Normal file
34
library/Director/Web/Controller/Extension/DirectorDb.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Web\Controller\Extension;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Db;
|
||||||
|
|
||||||
|
trait DirectorDb
|
||||||
|
{
|
||||||
|
/** @var Db */
|
||||||
|
private $db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Icinga\Exception\ConfigurationError
|
||||||
|
*
|
||||||
|
* @return Db
|
||||||
|
*/
|
||||||
|
public function db()
|
||||||
|
{
|
||||||
|
if ($this->db === null) {
|
||||||
|
$resourceName = $this->Config()->get('db', 'resource');
|
||||||
|
if ($resourceName) {
|
||||||
|
$this->db = Db::fromResourceName($resourceName);
|
||||||
|
} else {
|
||||||
|
if ($this->getRequest()->isApiRequest()) {
|
||||||
|
throw new ConfigurationError('Icinga Director is not correctly configured');
|
||||||
|
} else {
|
||||||
|
$this->redirectNow('director');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->db;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user