class Manager extends BaseObject

Manages configured external authentication sources

External auth sources are stored in their own database tables and are their own classes but all belong to a common Manager class (this one) that manages them and provides a way to enumerate them efficiently.

Constants

IDLength

The length of the ID used to identify the object

ENABLED_EXIST

ENABLED_FULL

Only allow users that already exist in the DB to sign in

ENABLED_TYPES

Allow auto-creating new accounts for all external signins

Properties

protected $database

The object's primary reference to the database

from  BaseObject
protected Scalar> $scalars from  BaseObject
protected ObjectRef> $objects from  BaseObject
protected ObjectRefs> $objectrefs from  BaseObject
private $modified

whether or not this object has been modified

from  BaseObject
private $deleted

whether or not this object has been deleted

from  BaseObject
private $dbDeleted

whether or not this object has been deleted by DB

from  BaseObject
private $deleteLater from  BaseObject
private $created

True if this object has been created and not yet saved to DB

from  BaseObject

Methods

static array
GetFieldTemplate()

Gets a template array of the object's properties (columns).

static string
GetDBClass()

Returns the name of the class that should be used in the database for the table name (cast down at save)

static string
GetObjClass(array $row)

No description

static int
CountByQuery(ObjectDatabase $database, QueryBuilder $query)

Counts objects in the DB matching the given query

static array
LoadByQuery(ObjectDatabase $database, QueryBuilder $query)

Loads an array of objects from the DB matching the given query

static int
DeleteByQuery(ObjectDatabase $database, QueryBuilder $query)

Deletes objects from the DB matching the given query

static BaseObject|null
TryLoadUniqueByQuery(ObjectDatabase $database, QueryBuilder $query)

Loads a unique object matching the given query

static BaseObject
NotNull(BaseObject|null $obj)

Asserts that the given object is not null

static BaseObject|null
TryLoadByID(ObjectDatabase $database, string $id)

Loads a unique object by its ID

static void
DeleteByID(ObjectDatabase $database, string $id)

Deletes a unique object by its ID

static array
LoadAll(ObjectDatabase $database, int|null $limit = null, int|null $offset = null)

Loads all objects of this type from the database

static int
DeleteAll(ObjectDatabase $database)

Deletes all objects of this type from the database

static array
LoadByObjectID(ObjectDatabase $database, string $field, string $id, string|null $class = null)

Loads objects from the database with the given object ID as the value of the given field

static int
DeleteByObjectID(ObjectDatabase $database, string $field, string $id, string|null $class = null)

Deletes objects from the database with the given object ID as the value of the given field

static BaseObject|null
TryLoadUniqueByKey(ObjectDatabase $database, string $field, string $key)

Loads a unique object matching the given field

static bool
TryDeleteByUniqueKey(ObjectDatabase $database, string $field, string $key)

Deletes a unique object matching the given field

static array
LoadByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Loads objects from the database with the given object referenced by the given field

static int
DeleteByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Deletes objects from the database with the given object referenced by the given field

static BaseObject|null
TryLoadUniqueByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Loads a unique object from the database with the given object referenced by the given field

static bool
TryDeleteByUniqueObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Deletes a unique object from the database with the given object referenced by the given field

string
ID()

Returns the unique ID of the object

string
__toString()

Returns the string "id:class" where id is the object ID and class is its short class name

static string|null
toString(BaseObject|null $obj)

Returns the given object's as a string if not null, else null

mixed
GetScalar(string $field, bool $allowTemp = true)

Gets a scalar field

TryGetScalar(string $field, bool $allowTemp = true)

Same as GetScalar() but returns null instead of throwing exceptions

int
GetScalarDelta(string $field)

Returns the delta of the given scalar (non-zero if modified)

GetObject(string $field)

Gets a single object reference

BaseObject|null
TryGetObject(string $field)

Same as GetObject() but returns null instead of throwing exceptions

bool
HasObject(string $field)

Checks if the object reference is not-null without actually loading it (faster)

string
GetObjectID(string $field)

Gets the ID of a referenced object without actually loading it (faster)

string|null
TryGetObjectID(string $field)

Same as GetObjectID() but returns null instead of throwing exceptions

string
GetObjectType(string $field)

Gets the class name of a referenced object without actually loading it (faster)

string|null
TryGetObjectType(string $field)

Gets the class name of a referenced object without actually loading it (faster)

DeleteObject(string $field)

Deletes the object referenced in the field

array
GetObjectRefs(string $field, int|null $limit = null, int|null $offset = null)

Gets an array of objects that reference this object

int
CountObjectRefs(string $field)

Gets the counter of objects referencing this object

GetJoinObject(string $field, BaseObject $obj)

Loads the object that joins together two classes using a FieldTypes\ObjectJoin

StandardObject|null
TryGetJoinObject(string $field, BaseObject $obj)

Same as GetJoinObject() but returns null instead of throwing exceptions

DeleteObjects(string $field)

Deletes all objects that reference this object

SetScalar(string $field, mixed $value, bool $temp = false)

Sets a scalar field to the given value

DeltaCounter(string $field, int $delta)

Increments a counter field by the given delta (thread safe)

bool
BoolSetObject(string $field, BaseObject|null $object, bool $notification = false)

Sets a field to reference the given object

SetObject(string $field, BaseObject|null $object, bool $notification = false)

Same as BoolSetObject() but returns $this

bool
AddObjectRef(string $field, BaseObject $object, bool $notification = false)

Adds the given object to a collection of referenced objects

bool
RemoveObjectRef(string $field, BaseObject $object, bool $notification = false)

Removes the given object from a collection of referenced objects

__construct(ObjectDatabase $database, array $data)

Constructs the object by initializing its field template with values from the database

AddField(string $key, Scalar $field)

Adds the given field object to the correct internal array

void
SubConstruct()

Function to allow subclasses to do something after being constructed without overriding the constructor

Save(bool $onlyMandatory = false)

Collects fields that have changed and saves them to the database

bool
isDeleted()

whether or not this object has been, or should be considered, deleted

void
NotifyDBDeleted()

Deletes this object without sending to the DB

void
Delete()

Deletes the external authentication source and all accounts created by it

void
DeleteLater()

Schedules the object to be deleted when Save() is called

bool
isCreated()

True if this object has been created and not yet saved to DB (should not be overriden)

static BaseObject
BaseCreate(ObjectDatabase $database)

Creates a new object of this type in the database and returns it

static array
getAuthClasses()

Returns a map of all external Auth classes as $name=>$class

static string
GetPropUsage()

Returns basic command usage for Create() and Edit()

static array
GetPropUsages()

Gets command usage specific to external authentication backends

static Manager
Create(ObjectDatabase $database, Input $input)

Creates and tests a new external authentication backend, creating a manager and optionally, a default group for it

Edit(Input $input)

Edits properties of an existing external auth backend

Group|null
GetDefaultGroup()

Returns the group that all accounts from this auth source are implicitly part of

string|null
GetDefaultGroupID()

Returns the ID of the default group for this auth source

CreateDefaultGroup()

Creates a new default group whose implicit members are all accounts of this auth source

GetAuthSource()

Returns the actual auth source interface for this manager

string
GetAuthSourceType()

Returns the type of auth source for this manager, without actually loading it

string
GetShortSourceType()

Returns the class-only (no namespace) of the auth source

int
GetEnabled()

Returns the enum of how/if this is enabled

string
GetDescription()

Returns the description set for this auth source, or the class name if none is set

array
GetClientObject(bool $admin)

Returns a printable client object for this manager and auth source

Details

at line 28
static array GetFieldTemplate()

Gets a template array of the object's properties (columns).

This template will be copied into the object when it is constructed. If a field maps to null, a basic Scalar fieldtype will be used.

Return Value

array

array of FieldTypes indexed by field names

in BaseObject at line 52
static string GetDBClass()

Returns the name of the class that should be used in the database for the table name (cast down at save)

Defaults to the actual class used. Can be overriden e.g. if multiple classes need to use the same table.

Return Value

string

in BaseObject at line 60
static string GetObjClass(array $row)

No description

Parameters

array $row

Return Value

string

in BaseObject at line 68
static int CountByQuery(ObjectDatabase $database, QueryBuilder $query)

Counts objects in the DB matching the given query

Parameters

ObjectDatabase $database

Reference to the database

QueryBuilder $query

The query to use for matching objects

Return Value

int

count of matched objects

in BaseObject at line 79
static array LoadByQuery(ObjectDatabase $database, QueryBuilder $query)

Loads an array of objects from the DB matching the given query

Parameters

ObjectDatabase $database

Reference to the database

QueryBuilder $query

The query to use for matching objects

Return Value

array

array of objects indexed by their IDs

in BaseObject at line 92
static int DeleteByQuery(ObjectDatabase $database, QueryBuilder $query)

Deletes objects from the DB matching the given query

The objects are loaded when they are deleted and their Delete()s are run

Parameters

ObjectDatabase $database

Reference to the database

QueryBuilder $query

The query to use for matching objects

Return Value

int

number of objects deleted

in BaseObject at line 103
static BaseObject|null TryLoadUniqueByQuery(ObjectDatabase $database, QueryBuilder $query)

Loads a unique object matching the given query

Parameters

ObjectDatabase $database

Reference to the database

QueryBuilder $query

the query to uniquely identify the object

Return Value

BaseObject|null

in BaseObject at line 116
static BaseObject NotNull(BaseObject|null $obj)

Asserts that the given object is not null

Parameters

BaseObject|null $obj

the object to check for null

Return Value

BaseObject

object if not null

Exceptions

ObjectNotFoundException

if the object is null

in BaseObject at line 127
static BaseObject|null TryLoadByID(ObjectDatabase $database, string $id)

Loads a unique object by its ID

Parameters

ObjectDatabase $database

Reference to the database

string $id

the ID of the object

Return Value

BaseObject|null

object or null if not found

in BaseObject at line 137
static void DeleteByID(ObjectDatabase $database, string $id)

Deletes a unique object by its ID

Parameters

ObjectDatabase $database

Reference to the database

string $id

the ID of the object

Return Value

void

in BaseObject at line 150
static array LoadAll(ObjectDatabase $database, int|null $limit = null, int|null $offset = null)

Loads all objects of this type from the database

Parameters

ObjectDatabase $database

Reference to the database

int|null $limit

the maximum number of objects to load

int|null $offset

the number of objects to skip loading

Return Value

array

array of objects indexed by their IDs

in BaseObject at line 160
static int DeleteAll(ObjectDatabase $database)

Deletes all objects of this type from the database

Parameters

ObjectDatabase $database

Reference to the database

Return Value

int

number of deleted objects

in BaseObject at line 176
static array LoadByObjectID(ObjectDatabase $database, string $field, string $id, string|null $class = null)

Loads objects from the database with the given object ID as the value of the given field

Can be used as an alternative to LoadByObject() to avoid actually loading the object

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

string $id

The ID of the object referenced

string|null $class

optionally, the class to match if this column is polymorphic

Return Value

array

array of objects indexed by their IDs

in BaseObject at line 193
static int DeleteByObjectID(ObjectDatabase $database, string $field, string $id, string|null $class = null)

Deletes objects from the database with the given object ID as the value of the given field

Can be used as an alternative to DeleteByObject() to avoid actually loading the object

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

string $id

The ID of the object referenced

string|null $class

optionally, the class to match if this column is polymorphic

Return Value

int

number of rows deleted

in BaseObject at line 206
static protected BaseObject|null TryLoadUniqueByKey(ObjectDatabase $database, string $field, string $key)

Loads a unique object matching the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

the name of the field to check

string $key

the value of the field that uniquely identifies the object

Return Value

BaseObject|null

in BaseObject at line 218
static protected bool TryDeleteByUniqueKey(ObjectDatabase $database, string $field, string $key)

Deletes a unique object matching the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

the name of the field to check

string $key

the value of the field that uniquely identifies the object

Return Value

bool

true if an object was deleted

in BaseObject at line 233
static array LoadByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Loads objects from the database with the given object referenced by the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

BaseObject $object

the object referenced by the field

bool $isPoly

whether or not this field is polymorphic

Return Value

array

array of objects indexed by their IDs

in BaseObject at line 247
static int DeleteByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Deletes objects from the database with the given object referenced by the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

BaseObject $object

the object referenced by the field

bool $isPoly

whether or not this field is polymorphic

Return Value

int

number of deleted objects

in BaseObject at line 261
static BaseObject|null TryLoadUniqueByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Loads a unique object from the database with the given object referenced by the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

BaseObject $object

the object referenced by the field

bool $isPoly

whether or not this field is polymorphic

Return Value

BaseObject|null

in BaseObject at line 275
static bool TryDeleteByUniqueObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)

Deletes a unique object from the database with the given object referenced by the given field

Parameters

ObjectDatabase $database

Reference to the database

string $field

The name of the field to check

BaseObject $object

the object referenced by the field

bool $isPoly

whether or not this field is polymorphic

Return Value

bool

true if an object was deleted

in BaseObject at line 284
string ID()

Returns the unique ID of the object

Return Value

string

in BaseObject at line 287
string __toString()

Returns the string "id:class" where id is the object ID and class is its short class name

Return Value

string

in BaseObject at line 290
static string|null toString(BaseObject|null $obj)

Returns the given object's as a string if not null, else null

Parameters

BaseObject|null $obj

Return Value

string|null

in BaseObject at line 309
protected mixed GetScalar(string $field, bool $allowTemp = true)

Gets a scalar field

Parameters

string $field

the field name of the scalar

bool $allowTemp

whether to allow returning a value that was set as temporary

Return Value

mixed

any non-null scalar value

Exceptions

KeyNotFoundException

if the field name is invalid

NullValueException

if the field value is null

in BaseObject at line 322
protected TryGetScalar(string $field, bool $allowTemp = true)

Same as GetScalar() but returns null instead of throwing exceptions

Parameters

string $field
bool $allowTemp

See also

BaseObject::GetScalar

in BaseObject at line 336
protected int GetScalarDelta(string $field)

Returns the delta of the given scalar (non-zero if modified)

Parameters

string $field

the field name of the scalar

Return Value

int

of times modified for scalars, delta for counters

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 351
protected BaseObject GetObject(string $field)

Gets a single object reference

Parameters

string $field

the field name holding the reference

Return Value

BaseObject

any object value

Exceptions

KeyNotFoundException

if the field name is invalid

NullValueException

if the field value is null

in BaseObject at line 365
protected BaseObject|null TryGetObject(string $field)

Same as GetObject() but returns null instead of throwing exceptions

Parameters

string $field

Return Value

BaseObject|null

See also

BaseObject::GetObject

in BaseObject at line 379
protected bool HasObject(string $field)

Checks if the object reference is not-null without actually loading it (faster)

Parameters

string $field

the field name holding the reference

Return Value

bool

true if the object reference is not null

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 394
protected string GetObjectID(string $field)

Gets the ID of a referenced object without actually loading it (faster)

Parameters

string $field

the field name holding the reference

Return Value

string

the ID of the referenced object

Exceptions

KeyNotFoundException

if the field name is invalid

NullValueException

if the field value is null

in BaseObject at line 408
protected string|null TryGetObjectID(string $field)

Same as GetObjectID() but returns null instead of throwing exceptions

Parameters

string $field

Return Value

string|null

See also

BaseObject::GetObjectID

in BaseObject at line 422
protected string GetObjectType(string $field)

Gets the class name of a referenced object without actually loading it (faster)

Parameters

string $field

the field name holding the reference

Return Value

string

the class name of the referenced object

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 438
protected string|null TryGetObjectType(string $field)

Gets the class name of a referenced object without actually loading it (faster)

Parameters

string $field

the field name holding the reference

Return Value

string|null

the class name of the referenced object

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 451
protected BaseObject DeleteObject(string $field)

Deletes the object referenced in the field

Parameters

string $field

the field name holding the reference

Return Value

BaseObject

in BaseObject at line 467
protected array GetObjectRefs(string $field, int|null $limit = null, int|null $offset = null)

Gets an array of objects that reference this object

Parameters

string $field

the field name of the collection

int|null $limit

the maximum number of objects to load

int|null $offset

the number of objects to skip loading

Return Value

array

array of objects indexed by their IDs

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 481
protected int CountObjectRefs(string $field)

Gets the counter of objects referencing this object

Parameters

string $field

the field name of the collection

Return Value

int

the number of objects

Exceptions

KeyNotFoundException

if the field name is invalid

in BaseObject at line 497
protected StandardObject GetJoinObject(string $field, BaseObject $obj)

Loads the object that joins together two classes using a FieldTypes\ObjectJoin

Parameters

string $field

the field name using the join reference

BaseObject $obj

the object that is joined together with this one

Return Value

StandardObject

the join object that connects us to $obj

Exceptions

KeyNotFoundException

if the field name is invalid

NullValueException

if the given object is not joined to us

in BaseObject at line 514
protected StandardObject|null TryGetJoinObject(string $field, BaseObject $obj)

Same as GetJoinObject() but returns null instead of throwing exceptions

Parameters

string $field
BaseObject $obj

Return Value

StandardObject|null

See also

BaseObject::GetJoinObject

in BaseObject at line 530
protected BaseObject DeleteObjects(string $field)

Deletes all objects that reference this object

Parameters

string $field

the field name of the collection

Return Value

BaseObject

in BaseObject at line 546
protected BaseObject SetScalar(string $field, mixed $value, bool $temp = false)

Sets a scalar field to the given value

Parameters

string $field

the name of the field

mixed $value

the value of the scalar to set

bool $temp

if true, the value is temporary and will not be saved

Return Value

BaseObject

Exceptions

KeyNotFoundException

if the property name is invalid

in BaseObject at line 571
protected BaseObject DeltaCounter(string $field, int $delta)

Increments a counter field by the given delta (thread safe)

Parameters

string $field

the name of the counter field

int $delta

the value to increment by

Return Value

BaseObject

Exceptions

KeyNotFoundException

if the property name is invalid

FieldTypeException

if the field is not a counter

in BaseObject at line 598
protected bool BoolSetObject(string $field, BaseObject|null $object, bool $notification = false)

Sets a field to reference the given object

Will also call SetObject or AddObjectRef on the given object as appropriate for two-way references

Parameters

string $field

the name of the reference field

BaseObject|null $object

the object for the field to reference

bool $notification

true if this is a notification from another object that cross-references this one (internal only!)

Return Value

bool

true if this object was modified

Exceptions

KeyNotFoundException

if the property name is invalid

in BaseObject at line 649
protected BaseObject SetObject(string $field, BaseObject|null $object, bool $notification = false)

Same as BoolSetObject() but returns $this

Parameters

string $field
BaseObject|null $object
bool $notification

Return Value

BaseObject

See also

BaseObject::BoolSetObject

in BaseObject at line 664
protected bool AddObjectRef(string $field, BaseObject $object, bool $notification = false)

Adds the given object to a collection of referenced objects

Will also call SetObject on the given object to actually create the reference

Parameters

string $field

the name of the field of the collection

BaseObject $object

the object to add to the collection

bool $notification

true if this is a notification from another object that cross-references this one (internal only!)

Return Value

bool

true if this object was modified

Exceptions

KeyNotFoundException

if the property name is invalid

in BaseObject at line 696
protected bool RemoveObjectRef(string $field, BaseObject $object, bool $notification = false)

Removes the given object from a collection of referenced objects

Parameters

string $field

the name of the field of the collection

BaseObject $object

the object to add to the collection

bool $notification

true if this is a notification from another object that cross-references this one (internal only!)

Return Value

bool

true if this object was modified

Exceptions

KeyNotFoundException

if the property name is invalid

in BaseObject at line 727
__construct(ObjectDatabase $database, array $data)

Constructs the object by initializing its field template with values from the database

Parameters

ObjectDatabase $database

Reference to the database

array $data

array of columns from the DB in the form of name=>value

in BaseObject at line 750
private AddField(string $key, Scalar $field)

Adds the given field object to the correct internal array

Parameters

string $key
Scalar $field

in BaseObject at line 763
protected void SubConstruct()

Function to allow subclasses to do something after being constructed without overriding the constructor

Return Value

void

in BaseObject at line 771
BaseObject Save(bool $onlyMandatory = false)

Collects fields that have changed and saves them to the database

Parameters

bool $onlyMandatory

true if only required fields should be saved

Return Value

BaseObject

Exceptions

RowInsertFailedException

if the insert fails (duplicate?)

in BaseObject at line 814
bool isDeleted()

whether or not this object has been, or should be considered, deleted

This function can be overriden with a custom validity-check, and is used as a filter when loading objects

Return Value

bool

in BaseObject at line 820
void NotifyDBDeleted()

Deletes this object without sending to the DB

Return Value

void

at line 112
void Delete()

Deletes the external authentication source and all accounts created by it

Return Value

void

in BaseObject at line 849
protected void DeleteLater()

Schedules the object to be deleted when Save() is called

Return Value

void

in BaseObject at line 855
bool isCreated()

True if this object has been created and not yet saved to DB (should not be overriden)

Return Value

bool

in BaseObject at line 861
static protected BaseObject BaseCreate(ObjectDatabase $database)

Creates a new object of this type in the database and returns it

Parameters

ObjectDatabase $database

Return Value

BaseObject

at line 39
static private array getAuthClasses()

Returns a map of all external Auth classes as $name=>$class

Return Value

array

at line 50
static string GetPropUsage()

Returns basic command usage for Create() and Edit()

Return Value

string

at line 55
static array GetPropUsages()

Gets command usage specific to external authentication backends

Return Value

array

at line 64
static Manager Create(ObjectDatabase $database, Input $input)

Creates and tests a new external authentication backend, creating a manager and optionally, a default group for it

Parameters

ObjectDatabase $database
Input $input

Return Value

Manager

at line 94
Manager Edit(Input $input)

Edits properties of an existing external auth backend

Parameters

Input $input

Return Value

Manager

at line 124
Group|null GetDefaultGroup()

Returns the group that all accounts from this auth source are implicitly part of

Return Value

Group|null

at line 127
string|null GetDefaultGroupID()

Returns the ID of the default group for this auth source

Return Value

string|null

at line 130
private Manager CreateDefaultGroup()

Creates a new default group whose implicit members are all accounts of this auth source

Return Value

Manager

at line 140
External GetAuthSource()

Returns the actual auth source interface for this manager

Return Value

External

at line 143
string GetAuthSourceType()

Returns the type of auth source for this manager, without actually loading it

Return Value

string

at line 146
private string GetShortSourceType()

Returns the class-only (no namespace) of the auth source

Return Value

string

at line 154
int GetEnabled()

Returns the enum of how/if this is enabled

Return Value

int

at line 157
string GetDescription()

Returns the description set for this auth source, or the class name if none is set

Return Value

string

at line 170
array GetClientObject(bool $admin)

Returns a printable client object for this manager and auth source

See the GetClientObject() for each specific auth source type.

Parameters

bool $admin

if true, show admin-level details

Return Value

array

{id:id, description:string} \ if $admin, add {enabled:enum, type:enum, authsource:(Authsource), default_group:?id}