icingaweb2/library/Icinga/Data/ResourceFactory.php

49 lines
1.2 KiB
PHP
Raw Normal View History

<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Data;
2013-10-07 16:46:20 +02:00
use Zend_Config;
use Icinga\Util\ConfigAwareFactory;
use Icinga\Exception\ConfigurationError;
use Icinga\Data\Db\Connection as DbConnection;
2013-10-07 16:46:20 +02:00
use Icinga\Protocol\Statusdat\Reader as StatusdatReader;
class ResourceFactory implements ConfigAwareFactory
{
/**
* @var Zend_Config
*/
private static $resources;
public static function setConfig($config)
{
self::$resources = $config;
}
2013-10-07 16:46:20 +02:00
public static function getResourceConfig($resourceName)
{
if (($resourceConfig = self::$resources->get($resourceName)) === null) {
throw new ConfigurationError('BLUBB?!');
}
2013-10-07 16:46:20 +02:00
return $resourceConfig;
}
public static function createResource(Zend_Config $config)
{
switch (strtolower($config->type)) {
case 'db':
2013-10-07 16:46:20 +02:00
$resource = new DbConnection($config);
break;
case 'statusdat':
$resource = new StatusdatReader($config);
break;
default:
throw new ConfigurationError('BLUBB2?!');
}
return $resource;
}
}