config = $backendConfig; $this->resource = ResourceFactory::createResource($resourceConfig); } /** * Set backend configs * * @param Zend_Config $backendConfigs */ public static function setConfig($backendConfigs) { foreach ($backendConfigs as $name => $config) { self::$backendConfigs[$name] = $config; } } /** * Backend entry point * * return self */ public function select() { return $this; } /** * Create query to retrieve columns and rows from the the given table * * @param string $table * @param array $columns * * @return Query */ public function from($table, array $columns = null) { $queryClass = '\\Icinga\\Module\\Monitoring\\Backend\\' . ucfirst($this->config->type) . '\\Query\\' . ucfirst($table) . 'Query'; if (!class_exists($queryClass)) { throw new UnsupportedBackendException('Query ' . ucfirst($table) . ' Is Not Available For Backend ' . ucfirst($this->config->type) ); } return new $queryClass($this->resource, $columns); } /** * Get the resource which was created in the constructor * * @return mixed */ public function getResource() { return $this->resource; } /** * Get backend configs * * @return Zend_Config */ public static function getBackendConfigs() { if (empty(self::$backendConfigs)) { self::setConfig(IcingaConfig::module('monitoring', 'backends')); } return self::$backendConfigs; } /** * Retrieve the name of the default backend which is the INI's first entry * * @return string * @throws ConfigurationError When no backend has been configured */ public static function getDefaultBackendName() { $configs = self::getBackendConfigs(); if (empty($configs)) { throw new ConfigurationError( 'Cannot get default backend as no backend has been configured' ); } reset($configs); return key($configs); } /** * Create the backend with the given name * * @param $name * * @return Backend */ public static function createBackend($name) { if (array_key_exists($name, self::$backendInstances)) { return self::$backendInstances[$name]; } if ($name === null) { $name = self::getDefaultBackendName(); } $config = self::$backendConfigs[$name]; self::$backendInstances[$name] = $backend = new self($config, ResourceFactory::getResourceConfig($config->resource)); switch (strtolower($config->type)) { case 'ido': if ($backend->getResource()->getDbType() !== 'oracle') { $backend->getResource()->setTablePrefix('icinga_'); } break; } return $backend; } }