Documentation

LDAPObject
in package

LDAP Object class

This class is the parent of the users and committees returned by the LDAP.

Tags
author

ITco itco@astatine.utwente.nl

author

Robert Roos robert.roos@astatine.utwente.nl

copyright

September 2017 - 2018, S.A. Astatine

license

PHP License 3.01

Table of Contents

BIND_KEY  = ''
Key to the type of bind address (actual bind address is read by LDAPI)
FIXED_FIELDS  = []
List of fields that cannot be patched directly (when altered directly changes are not saved!)
LDAP_KEYS  = []
Maps LDAP keys to properties ('ldap_key' => 'property')
SEARCH_PREFIX  = ''
Search addition needed for ldap_search (contains object type)
$id  : int|null
Primary id of this object
$dirty  : array<string|int, mixed>
Altered fields, queue to be saved, 'field' => 'new_value'
$DISPLAY_KEYS  : array<string|int, mixed>
Maps properties to LDAP keys, reverse of LDAP_KEYS: 'property' => 'ldap_keys'
$errors  : array<string|int, mixed>
Validation errors, ordered by field as key
$ldapi_link  : LDAPI
Link to LDAPI instance
$validators  : array<string|int, mixed>
Validators to apply: 'field' => [list of rules]
__construct()  : void
Initialize object from LDAP result
__debugInfo()  : array<string|int, mixed>
Override default debug to make result more clear
_clearDirty()  : void
Clear all dirty fields
_dirty()  : array<string|int, mixed>
Return dirty fields with their new values
_dirtyToLDAPArray()  : array<string|int, mixed>
Collect all dirty fields and return an array compatible with ldap_save
_getDisplayKey()  : string|false|array<string|int, mixed>
Find a display key (property) based on ldap_key
_getDNPrefix()  : string
Return prefix needed for LDAP binds
_getLdapKey()  : string|false|array<string|int, mixed>
Find an ldap key based on a display key (property)
_setErrors()  : void
Add validation errors
_validate()  : bool
Verify the content, errors are saved in $this->errors
getErrors()  : array<string|int, mixed>|false
Return validation errors
patchEntity()  : bool
Alter or insert data, validate it and mark it to be saved
_buildObjectFromLdapData()  : void
Fill instance according to LDAP data

Constants

BIND_KEY

Key to the type of bind address (actual bind address is read by LDAPI)

public string BIND_KEY = ''

FIXED_FIELDS

List of fields that cannot be patched directly (when altered directly changes are not saved!)

public array<string|int, string> FIXED_FIELDS = []

LDAP_KEYS

Maps LDAP keys to properties ('ldap_key' => 'property')

public array<string|int, mixed> LDAP_KEYS = []

SEARCH_PREFIX

Search addition needed for ldap_search (contains object type)

public string SEARCH_PREFIX = ''

Properties

$id

Primary id of this object

public int|null $id = null

$dirty

Altered fields, queue to be saved, 'field' => 'new_value'

protected array<string|int, mixed> $dirty = []

$DISPLAY_KEYS

Maps properties to LDAP keys, reverse of LDAP_KEYS: 'property' => 'ldap_keys'

protected static array<string|int, mixed> $DISPLAY_KEYS = []

This property is static instead of const, because we want to automatically set it based on LDAP_KEYS.

$errors

Validation errors, ordered by field as key

protected array<string|int, mixed> $errors = []

$validators

Validators to apply: 'field' => [list of rules]

protected static array<string|int, mixed> $validators = []

Methods

__construct()

Initialize object from LDAP result

public __construct([array<string|int, mixed>|null $ldap_entry = null ][, LDAPI|null &$ldapi_link = null ]) : void
Parameters
$ldap_entry : array<string|int, mixed>|null = null

LDAP array

$ldapi_link : LDAPI|null = null

Link to LDAPI instance

Return values
void

__debugInfo()

Override default debug to make result more clear

public __debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

_clearDirty()

Clear all dirty fields

public _clearDirty() : void
Return values
void

_dirty()

Return dirty fields with their new values

public _dirty() : array<string|int, mixed>
Return values
array<string|int, mixed>

_dirtyToLDAPArray()

Collect all dirty fields and return an array compatible with ldap_save

public _dirtyToLDAPArray() : array<string|int, mixed>

The keys of the array will be ldap keys.

Return values
array<string|int, mixed>

_getDisplayKey()

Find a display key (property) based on ldap_key

public static _getDisplayKey([ $ldap_key = null ]) : string|false|array<string|int, mixed>

If a key could not be found, false is returned and a warning is triggered.

The LDAP_KEYS array contains display keys as values, hence it's used here.

Parameters
$ldap_key : = null

string|null Leave empty to return all

Return values
string|false|array<string|int, mixed>

_getDNPrefix()

Return prefix needed for LDAP binds

public _getDNPrefix() : string
Return values
string

_getLdapKey()

Find an ldap key based on a display key (property)

public static _getLdapKey([ $display_key = null ]) : string|false|array<string|int, mixed>

If a key could not be found, false is returned and a warning is triggered.

The DISPLAY_KEYS array contains ldap keys as values, hence it's used here.

Parameters
$display_key : = null

string|null Leave empty to return all

Return values
string|false|array<string|int, mixed>

_setErrors()

Add validation errors

public _setErrors(string $field, array<string|int, mixed>|string $errors) : void
Parameters
$field : string

For property or field

$errors : array<string|int, mixed>|string

Error message(s)

Return values
void

_validate()

Verify the content, errors are saved in $this->errors

public _validate([array<string|int, mixed>|null $fields = null ]) : bool
Parameters
$fields : array<string|int, mixed>|null = null

Verify these fields only, if null all dirty fields are processed

Return values
bool

False on errors

getErrors()

Return validation errors

public getErrors([string|null $val = null ]) : array<string|int, mixed>|false
Parameters
$val : string|null = null

Return errors for this field or return all errors

Return values
array<string|int, mixed>|false

Array of errors or false if none exist

patchEntity()

Alter or insert data, validate it and mark it to be saved

public patchEntity(array<string|int, mixed> $data) : bool
Parameters
$data : array<string|int, mixed>
Return values
bool

False on validation errors

_buildObjectFromLdapData()

Fill instance according to LDAP data

protected _buildObjectFromLdapData(array<string|int, mixed> $entry) : void
Parameters
$entry : array<string|int, mixed>

LDAP entry array (single entry!)

Return values
void

Search results