icingaweb2-module-director/library/Director/Cli/Command.php

44 lines
1.0 KiB
PHP

<?php
namespace Icinga\Module\Director\Cli;
use Icinga\Cli\Command as CliCommand;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\IcingaEndpoint;
class Command extends CliCommand
{
protected $db;
private $api;
protected function api($endpointName = null)
{
if ($this->api === null) {
if ($endpointName === null) {
$endpoint = $this->db()->getDeploymentEndpoint();
} else {
$endpoint = IcingaEndpoint::load($endpointName, $this->db());
}
$this->api = $endpoint->api();
}
return $this->api;
}
protected function db()
{
if ($this->db === null) {
$resourceName = $this->Config()->get('db', 'resource');
if ($resourceName) {
$this->db = Db::fromResourceName($resourceName);
} else {
$this->fail('Director is not configured correctly');
}
}
return $this->db;
}
}