SimpleAuth Group

As said in the introduction of the Auth package, an authentication system comes with three different drivers, each dealing with a part of the system.

The SimpleAuth group driver stores it's group definitions in the simpleauth configuration file. It provides the logic for checking if a user is a member of a group, and for retrieving group information, or the roles defined to to a group.

Configuration

The SimpleAuth group driver stores it's group definitions in the simpleauth configuration file. The groups are defined as a multi-dimensional array, which must have the following structure:

array(
	<id> => array(				// where <id> is a number that identifies the group
		'name' => 'name-of-this-group',		// the name that identifies this group, like 'Administrators' or 'Guests'
		'roles' => array('role', 'otherrole'),	// list of roles assigned to this group
	),
),

The simpleauth config file supplied with the Auth package contains some examples that you can use.

Class methods

member($group, $user = null)

The member method allows you to check if a user is member of a given group.

Static No
Parameters
Param Default Description
$group required The id of the group you want to check for membership
$user
null
A specific user, identified by the result of get_user_id(), or null for the currently logged-in user.
Returns boolean. true if the user is member of the group, or false if not.

get_name($group = null)

The get_name method allows you to fetch the name of a given group id.

Static No
Parameters
Param Default Description
$group
null
The id of the group you want to get the name of
Returns mixed. false if the group id does not exist, or the defined name of the group.

If no group id is given, the name of the first defined group is returned.

get_roles($group = null)

The get_name method allows you to fetch the roles defined for a given group id.

Static No
Parameters
Param Default Description
$group
null
The id of the group you want to get the roles of
Returns array. If the group id does not exist, an empty array is returned. If no group id is given, the roles of the first group are returned.