name = (string) $name; return $this; } /** * Return this backend's name * * @return string */ public function getName() { return $this->name; } /** * Create and return a UserGroupBackend with the given name and given configuration applied to it * * @param string $name * @param ConfigObject $backendConfig * * @return UserGroupBackend * * @throws ConfigurationError */ public static function create($name, ConfigObject $backendConfig) { if ($backendConfig->name !== null) { $name = $backendConfig->name; } if (! ($backendType = strtolower($backendConfig->backend))) { throw new ConfigurationError( 'Configuration for user group backend "%s" is missing the \'backend\' directive', $name ); } if ($backendConfig->resource === null) { throw new ConfigurationError( 'Configuration for user group backend "%s" is missing the \'resource\' directive', $name ); } $resource = ResourceFactory::create($backendConfig->resource); switch ($backendType) { case 'db': $backend = new DbUserGroupBackend($resource); break; case 'ini': $backend = new IniUserGroupBackend($resource); break; default: throw new ConfigurationError( 'Configuration for user group backend "%s" defines an invalid backend type.' . ' Backend type "%s" is not supported', $name, $backendType ); } $backend->setName($name); return $backend; } /** * Get the groups the given user is a member of * * @param User $user * * @return array */ abstract public function getMemberships(User $user); }