UserGroupBackend: Add missing and fix existing method documentation

This commit is contained in:
Johannes Meyer 2015-04-22 09:35:06 +02:00
parent 847c02ed8e
commit c9dcddb134

View File

@ -6,7 +6,6 @@ namespace Icinga\Authentication\UserGroup;
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory; use Icinga\Data\ResourceFactory;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
use Icinga\Exception\IcingaException;
use Icinga\User; use Icinga\User;
/** /**
@ -15,14 +14,14 @@ use Icinga\User;
abstract class UserGroupBackend abstract class UserGroupBackend
{ {
/** /**
* Name of the backend * The name of this backend
* *
* @var string * @var string
*/ */
protected $name; protected $name;
/** /**
* Set the backend name * Set this backend's name
* *
* @param string $name * @param string $name
* *
@ -35,7 +34,7 @@ abstract class UserGroupBackend
} }
/** /**
* Get the backend name * Return this backend's name
* *
* @return string * @return string
*/ */
@ -45,42 +44,36 @@ abstract class UserGroupBackend
} }
/** /**
* Create a user group backend * Create and return a UserGroupBackend with the given name and given configuration applied to it
* *
* @param string $name * @param string $name
* @param ConfigObject $backendConfig * @param ConfigObject $backendConfig
* *
* @return DbUserGroupBackend|IniUserGroupBackend * @return UserGroupBackend
* @throws ConfigurationError If the backend configuration is invalid *
* @throws ConfigurationError
*/ */
public static function create($name, ConfigObject $backendConfig) public static function create($name, ConfigObject $backendConfig)
{ {
if ($backendConfig->name !== null) { if ($backendConfig->name !== null) {
$name = $backendConfig->name; $name = $backendConfig->name;
} }
if (($backendType = $backendConfig->backend) === null) {
if (! ($backendType = strtolower($backendConfig->backend))) {
throw new ConfigurationError( throw new ConfigurationError(
'Configuration for user group backend \'%s\' is missing the \'backend\' directive', 'Configuration for user group backend "%s" is missing the \'backend\' directive',
$name $name
); );
} }
$backendType = strtolower($backendType);
if (($resourceName = $backendConfig->resource) === null) { if ($backendConfig->resource === null) {
throw new ConfigurationError( throw new ConfigurationError(
'Configuration for user group backend \'%s\' is missing the \'resource\' directive', 'Configuration for user group backend "%s" is missing the \'resource\' directive',
$name $name
); );
} }
$resourceName = strtolower($resourceName); $resource = ResourceFactory::create($backendConfig->resource);
try {
$resource = ResourceFactory::create($resourceName);
} catch (IcingaException $e) {
throw new ConfigurationError(
'Can\'t create user group backend \'%s\'. An exception was thrown: %s',
$resourceName,
$e
);
}
switch ($backendType) { switch ($backendType) {
case 'db': case 'db':
$backend = new DbUserGroupBackend($resource); $backend = new DbUserGroupBackend($resource);
@ -90,11 +83,13 @@ abstract class UserGroupBackend
break; break;
default: default:
throw new ConfigurationError( throw new ConfigurationError(
'Can\'t create user group backend \'%s\'. Invalid backend type \'%s\'.', 'Configuration for user group backend "%s" defines an invalid backend type.'
. ' Backend type "%s" is not supported',
$name, $name,
$backendType $backendType
); );
} }
$backend->setName($name); $backend->setName($name);
return $backend; return $backend;
} }