CRUDKit api-doc [Developer]

DataProcessor
in package

Entity for formatting and processing data coming eiter from, or going into the Database.

Mostly needed by CRUDKit internally.

Table of Contents

__construct()  : mixed
An instance is needed when dealing with data (pre/postprocessing).
postProcess()  : array<string|int, mixed>
Formats the data in record(s) so that they can be displayed to the user or consumed by views.
preProcess()  : array<string|int, mixed>
Processing data from request before INSERT, UPDATE it to the database.
formatBytes()  : mixed
formatDateAndTime()  : mixed
getUploadFileData()  : mixed
Gets the binary data from an uploaded file.
matrix()  : void
Ah yes, the "Matrix". The core logic of preprocessing data, based on the paramters.
processBinaryData()  : mixed
setData()  : mixed
setEmpty()  : mixed
Setting the empty or the DB specific value empty for some datatypes
setNull()  : mixed

Methods

__construct()

An instance is needed when dealing with data (pre/postprocessing).

public __construct(TableDescriptor $table) : mixed
Parameters
$table : TableDescriptor

Table for later pre/postprocessing

Tags
internal
Return values
mixed

postProcess()

Formats the data in record(s) so that they can be displayed to the user or consumed by views.

public postProcess(mixed $records[, bool $singleRecord = false ][, bool $formaDateAndTime = true ][, bool $formatBool = true ][, bool $formatDec = true ][, bool $formatBinary = true ]) : array<string|int, mixed>
Parameters
$records : mixed

Raw data from the DB. Obtained by readRecordsRaw() or readRecordRaw()

$singleRecord : bool = false

TRUE if the records is a single record, FALSE if its an array of multiple records.

$formaDateAndTime : bool = true
$formatBool : bool = true
$formatDec : bool = true
$formatBinary : bool = true
Return values
array<string|int, mixed>

$records

preProcess()

Processing data from request before INSERT, UPDATE it to the database.

public preProcess(array<string|int, mixed> $requestData, string $isInsert) : array<string|int, mixed>

Considering the 5 important things:

  • Request data for the field exists
  • Request data for the field has value or is NULL
  • Field has a DEFAULT value in the DB
  • Field is set to NOT NULL in the DB
  • Field is set to AUTOINCREMENT in the DB
Parameters
$requestData : array<string|int, mixed>
$isInsert : string

TRUE for insert, FALSE for update

Tags
internal
Return values
array<string|int, mixed>

$recordData

formatBytes()

private formatBytes(mixed $bytes[, int $precision = 2 ]) : mixed
Parameters
$bytes : mixed
$precision : int = 2
Tags
internal
Return values
mixed

formatDateAndTime()

private formatDateAndTime(mixed &$columnValue, string $datatype) : mixed
Parameters
$columnValue : mixed
$datatype : string
Tags
internal
Return values
mixed

getUploadFileData()

Gets the binary data from an uploaded file.

private getUploadFileData(UploadedFile $uploadedFile) : mixed
Parameters
$uploadedFile : UploadedFile
Tags
internal
Return values
mixed

matrix()

Ah yes, the "Matrix". The core logic of preprocessing data, based on the paramters.

private matrix(mixed &$data, string $datatype, bool $d, bool $n, bool $nn, bool $df, bool $ai, bool &$i, bool &$u) : void

It decides if a field has its data, is null, empty of if its even included in the final SQL statement.

The syntax of this code may not be the most efficent but its easier to oversee all possibilities.

Parameters
$data : mixed

The field data

$datatype : string

The datatype of the field based on crudkit, or doctrine/dbal (there might be fields which are not defined in crudkit, but are still in the DB)

$d : bool

Per definition: data exist, if the field is present in request, even if NULL

$n : bool

Per definition: data === null. This doesnt indicate if its NULL in the request or set to NULL here, because is doesnt exist in the request.

$nn : bool

Field is defined as NOT NULL in the database

$df : bool

Field has a DEFAULT value in database

$ai : bool

Field is defined as AUTOINCREMTN in the database

$i : bool

Specifies if we ulitmately want to include this field in the SQL INSERT statement.

$u : bool

Specifies if we ulitmately want to include this field in the SQL UPDATE statement.

Tags
internal
Return values
void

processBinaryData()

private processBinaryData(mixed &$columnValue, mixed $singleRecord, string $datatype) : mixed
Parameters
$columnValue : mixed
$singleRecord : mixed
$datatype : string
Tags
internal
Return values
mixed

setData()

private setData(mixed &$data, string $datatype) : mixed
Parameters
$data : mixed
$datatype : string
Tags
internal
Return values
mixed

setEmpty()

Setting the empty or the DB specific value empty for some datatypes

private setEmpty(mixed &$data, string $datatype) : mixed
Parameters
$data : mixed
$datatype : string
Tags
internal
Return values
mixed

setNull()

private setNull(mixed &$data) : mixed
Parameters
$data : mixed
Tags
internal
Return values
mixed

Search results