Functional
in package
Functional algorithms
Table of Contents
- SORT_DIRECTION_ASC = 0
- Sorting directions
- SORT_DIRECTION_DESC = 1
- expandRecordsWith() : void
- Method unites corresponding records
- expandRecordWith() : void
- Method expands record $dest with frields of the $src
- fieldExists() : bool
- Method returns field of the object/array
- fieldExistsPlain() : bool
- Method returns field of the object/array without recursive inspection
- filter() : array<string|int, mixed>
- Method filters objects in array
- getField() : mixed
- Method returns field of the object/array
- getFields() : mixed
- Method fetches all fields from objects/arrays of an array
- replaceField() : void
- Method replaces one field to another in array of records
- replaceFieldInEntity() : void
- Method replaces one field to another in record
- replaceFields() : void
- Method replaces one field toanother in array of records
- replaceFieldsInEntity() : void
- Method replaces one field to another in record
- setChild() : void
- Method adds nested record to the original record of objects
- setChildren() : void
- Method adds nested records to the original record of objects
- setField() : void
- Method sets field of the object/array
- setFieldsInObjects() : void
- Method sets fields $fieldName in array of objects $objects with $values
- sortRecords() : void
- Method sorts records by the specified field
- sumFields() : float|int
- Method sums fields in an array of objects
- transform() : void
- Method transforms objects in array
- setExistingField() : void
- Method sets existing field of the object/array
Constants
SORT_DIRECTION_ASC
Sorting directions
public
mixed
SORT_DIRECTION_ASC
= ""
SORT_DIRECTION_DESC
public
mixed
SORT_DIRECTION_DESC
= 1
Methods
expandRecordsWith()
Method unites corresponding records
public
static expandRecordsWith(array<string|int, mixed> &$dest, string $destField, array<string|int, mixed> $src, string $srcField) : void
Parameters
- $dest : array<string|int, mixed>
-
Destination array of records
- $destField : string
-
Field name
- $src : array<string|int, mixed>
-
Source array of records
- $srcField : string
-
Field name
Return values
void —expandRecordWith()
Method expands record $dest with frields of the $src
public
static expandRecordWith(array<string|int, mixed>|object &$dest, array<string|int, mixed>|object $src) : void
Parameters
- $dest : array<string|int, mixed>|object
-
record to be expanded
- $src : array<string|int, mixed>|object
-
record to be the expander
Return values
void —fieldExists()
Method returns field of the object/array
public
static fieldExists(mixed &$record, string $field[, bool $recursive = true ]) : bool
Parameters
- $record : mixed
-
Record to be analyzed
- $field : string
-
Field name
- $recursive : bool = true
-
Do we need recursive descending
Tags
Return values
bool —Does the field $field exists or not
fieldExistsPlain()
Method returns field of the object/array without recursive inspection
public
static fieldExistsPlain(mixed &$record, string $field) : bool
Parameters
- $record : mixed
-
Record to be analyzed
- $field : string
-
Field name
Tags
Return values
bool —Does the field $field exists or not
filter()
Method filters objects in array
public
static filter(array<string|int, mixed> &$objects, string $field[, string $operation = '==' ][, mixed $value = false ]) : array<string|int, mixed>
Parameters
- $objects : array<string|int, mixed>
-
List of records to be filtered
- $field : string
-
Filter field
- $operation : string = '=='
-
Filtration operation
- $value : mixed = false
-
Filtration value
Tags
Return values
array<string|int, mixed> —List of filtered records
getField()
Method returns field of the object/array
public
static getField(mixed $record, string $field[, bool $recursive = true ]) : mixed
Parameters
- $record : mixed
-
Processing record
- $field : string
-
Field name
- $recursive : bool = true
-
Shold we search the field $field along the whole object
Tags
Return values
mixed —Field value
getFields()
Method fetches all fields from objects/arrays of an array
public
static getFields(mixed $data, string $field[, bool $recursive = true ]) : mixed
Parameters
- $data : mixed
-
processing record
- $field : string
-
field name
- $recursive : bool = true
-
chold we search the field $field along the whole object
Tags
Return values
mixed —value of the field
replaceField()
Method replaces one field to another in array of records
public
static replaceField(array<string|int, mixed> &$objects, string $fieldFrom, string $fieldTo) : void
Parameters
- $objects : array<string|int, mixed>
-
Objects to be processed
- $fieldFrom : string
-
Field name to be replaced
- $fieldTo : string
-
Field name to be added
Tags
Return values
void —replaceFieldInEntity()
Method replaces one field to another in record
public
static replaceFieldInEntity(array<string|int, mixed>|object|mixed &$object, string $fieldFrom, string $fieldTo) : void
Parameters
- $object : array<string|int, mixed>|object|mixed
-
Object to be processed
- $fieldFrom : string
-
Field name to be replaced
- $fieldTo : string
-
Field name to be added
Tags
Return values
void —replaceFields()
Method replaces one field toanother in array of records
public
static replaceFields(array<string|int, mixed> &$objects, array<string|int, string> $fieldsFrom, array<string|int, string> $fieldsTo) : void
Parameters
- $objects : array<string|int, mixed>
-
Objects to be processed
- $fieldsFrom : array<string|int, string>
-
Field names to be replaced
- $fieldsTo : array<string|int, string>
-
Field names to be added
Return values
void —replaceFieldsInEntity()
Method replaces one field to another in record
public
static replaceFieldsInEntity(array<string|int, mixed>|object &$object, array<string|int, string> $fieldsFrom, array<string|int, string> $fieldsTo) : void
Parameters
- $object : array<string|int, mixed>|object
-
Object to be processed
- $fieldsFrom : array<string|int, string>
-
Field names to be replaced
- $fieldsTo : array<string|int, string>
-
Field names to be added
Return values
void —setChild()
Method adds nested record to the original record of objects
public
static setChild(string $field, array<string|int, mixed> &$objects, string $objectField, array<string|int, mixed> $records, string $recordField) : void
Parameters
- $field : string
-
Field name
- $objects : array<string|int, mixed>
-
The original record of objects
- $objectField : string
-
Filtering field
- $records : array<string|int, mixed>
-
List of nested records
- $recordField : string
-
Filtering field
Return values
void —setChildren()
Method adds nested records to the original record of objects
public
static setChildren(string $field, array<string|int, mixed> &$objects, string $objectField, array<string|int, mixed> $records, string $recordField) : void
Parameters
- $field : string
-
Field name
- $objects : array<string|int, mixed>
-
The original array of objects
- $objectField : string
-
Filtering field
- $records : array<string|int, mixed>
-
List of nested records
- $recordField : string
-
Filtering field
Tags
Return values
void —setField()
Method sets field of the object/array
public
static setField(mixed &$record, string $field, mixed $value) : void
Parameters
- $record : mixed
-
processing record
- $field : string
-
field name
- $value : mixed
-
value to be set
Tags
Return values
void —setFieldsInObjects()
Method sets fields $fieldName in array of objects $objects with $values
public
static setFieldsInObjects(array<string|int, mixed> &$objects, string $fieldName, array<string|int, mixed> $values) : void
Parameters
- $objects : array<string|int, mixed>
-
Array of objects to be processed
- $fieldName : string
-
Field name
- $values : array<string|int, mixed>
-
Values to be set
Return values
void —sortRecords()
Method sorts records by the specified field
public
static sortRecords(array<string|int, mixed> &$objects, string $field[, int $direction = Functional::SORT_DIRECTION_ASC ]) : void
Parameters
- $objects : array<string|int, mixed>
-
records to be sorted
- $field : string
-
field name
- $direction : int = Functional::SORT_DIRECTION_ASC
-
direction of sorting
Return values
void —sumFields()
Method sums fields in an array of objects
public
static sumFields(array<string|int, mixed> &$objects, string $fieldName) : float|int
Parameters
- $objects : array<string|int, mixed>
-
array of objects to be processed
- $fieldName : string
-
field name
Tags
Return values
float|int —sum of fields
transform()
Method transforms objects in array
public
static transform(array<string|int, mixed> &$objects, callable $transformer) : void
Parameters
- $objects : array<string|int, mixed>
-
array of objects to be processed
- $transformer : callable
Tags
Return values
void —setExistingField()
Method sets existing field of the object/array
protected
static setExistingField(mixed &$record, string $field, mixed $value) : void
Parameters
- $record : mixed
-
processing record
- $field : string
-
field name
- $value : mixed
-
value to be set