Arikaim CMS

Validator extends Collection
in package

Data validation

Table of Contents

Properties

$data  : array<string|int, mixed>
Collection items data
$errors  : array<string|int, mixed>
Validation errors
$filters  : array<string|int, mixed>
Filters
$getErrorCallback  : Closure|null
Get error callback
$getValidCallback  : Closure|null
Get valida callback
$onErrorCallback  : Closure|null
On error callback
$onValidCallback  : Closure|null
On valid callback
$rules  : array<string|int, mixed>
validation rules

Methods

__construct()  : mixed
Constructor
__get()  : mixed
Get value
__set()  : mixed
Set value
add()  : void
Add item to collection
addError()  : void
Set validation error
addField()  : bool
Add value
addFilter()  : Validator
Add filter
addRule()  : Validator
Add validation rule
clear()  : void
Clear collection data
copy()  : self
Clone object
count()  : int
Return collection items count.
create()  : Collection
Create colleciton
createFromFile()  : Collection
Create colection form json file
doFilter()  : Validator
Sanitize form fields values
filter()  : FilterBuilder
Return filter builder
filterAndValidate()  : bool
Sanitize and validate form
get()  : mixed
Get value from collection
getArray()  : array<string|int, mixed>
Return array values
getBool()  : bool
Get boolean value
getByPath()  : mixed
Get value by path
getCollection()  : Collection
Get collection item
getErrors()  : array<string|int, mixed>
Return validation errors
getErrorsCount()  : int
Return number of errors
getFilters()  : array<string|int, mixed>
Return form filters
getFloat()  : float|null
Get float value
getInt()  : int|null
Get int value
getItems()  : array<string|int, mixed>
Get collection items
getIterator()  : ArrayIterator
Return iterator
getRules()  : array<string|int, mixed>
Return validation rules
getString()  : string
Get text value
getTimestamp()  : int|null
Get field converted to timestamp
has()  : bool
Return true if key exists in collection
isEmpty()  : bool
Return true if key exists and value not empty in collection
isValid()  : bool
Return true if form is valid
merge()  : void
Merge collection items
mergeItems()  : void
Merge all collection items
offsetExists()  : bool
Return true if key exists in collection
offsetGet()  : mixed
Get item
offsetSet()  : void
Set item
offsetUnset()  : void
Remove item
onError()  : void
Set callback for error valdation
onValid()  : void
Set callback for validation done
prepend()  : bool
Add value to begining of collection array
push()  : bool
Push value to collection
remove()  : Collection
Remove item
removeEmptyItems()  : void
Remove empy items
replace()  : Collection
Replace array
sanitizeVariable()  : mixed
Sanitize form value
set()  : Collection
Set item value in collection
setArrayValue()  : array<string|int, mixed>
Set array value
setBooleanValue()  : void
Set bool value
setValue()  : void
Set item value by path
slice()  : array<string|int, mixed>
Slice collecion by keys
toArray()  : array<string|int, mixed>
Return collection array
toTimeStamp()  : self
Convert filed to timestamp
union()  : Collection
Union arrays
validate()  : bool
Validate
validateRule()  : bool
Validate rule
validateRules()  : bool
Validate rules
withData()  : Collection
Set collection data
initCallback()  : void
Init callback

Properties

$data

Collection items data

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

$errors

Validation errors

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

$filters

Filters

private array<string|int, mixed> $filters = []

$getErrorCallback

Get error callback

private Closure|null $getErrorCallback = null

$getValidCallback

Get valida callback

private Closure|null $getValidCallback = null

$onErrorCallback

On error callback

private Closure|null $onErrorCallback = null

$onValidCallback

On valid callback

private Closure|null $onValidCallback = null

$rules

validation rules

private array<string|int, mixed> $rules = []

Methods

__construct()

Constructor

public __construct([array<string|int, mixed> $data = [] ][, Closure|null $getValidCallback = null ][, Closure|null $getErrorCallback = null ]) : mixed
Parameters
$data : array<string|int, mixed> = []
$getValidCallback : Closure|null = null
$getErrorCallback : Closure|null = null

__get()

Get value

public __get(string $key) : mixed
Parameters
$key : string

__set()

Set value

public __set(string $key, mixed $value) : mixed
Parameters
$key : string
$value : mixed

add()

Add item to collection

public add(string $key, mixed $value) : void
Parameters
$key : string

key name

$value : mixed

addError()

Set validation error

public addError(string $fieldName, string|null $errorCode[, array<string|int, mixed> $params = [] ]) : void
Parameters
$fieldName : string
$errorCode : string|null
$params : array<string|int, mixed> = []

addField()

Add value

public addField(string $path, mixed $value) : bool
Parameters
$path : string
$value : mixed
Return values
bool

addFilter()

Add filter

public addFilter(string|null $fieldName, Filter|string $filter[, array<string|int, mixed> $args = [] ]) : Validator
Parameters
$fieldName : string|null
$filter : Filter|string
$args : array<string|int, mixed> = []
Return values
Validator

addRule()

Add validation rule

public addRule(RuleInterface|string $rule[, string|null $fieldName = null ][, string|null $errorCode = null ]) : Validator
Parameters
$rule : RuleInterface|string
$fieldName : string|null = null
$errorCode : string|null = null
Return values
Validator

clear()

Clear collection data

public clear() : void

copy()

Clone object

public copy() : self
Return values
self

count()

Return collection items count.

public count() : int
Return values
int

create()

Create colleciton

public static create(array<string|int, mixed> $data) : Collection
Parameters
$data : array<string|int, mixed>
Return values
Collection

createFromFile()

Create colection form json file

public static createFromFile(string $fileName[, string|null $root = null ][, array<string|int, mixed>|null $vars = null ]) : Collection
Parameters
$fileName : string
$root : string|null = null
$vars : array<string|int, mixed>|null = null
Return values
Collection

doFilter()

Sanitize form fields values

public doFilter([array<string|int, mixed>|null $data = null ]) : Validator
Parameters
$data : array<string|int, mixed>|null = null
Return values
Validator

filter()

Return filter builder

public filter() : FilterBuilder
Return values
FilterBuilder

filterAndValidate()

Sanitize and validate form

public filterAndValidate([bool $throwException = false ]) : bool
Parameters
$throwException : bool = false
Return values
bool

get()

Get value from collection

public get(string $key[, mixed $default = null ]) : mixed
Parameters
$key : string

Name

$default : mixed = null

If key not exists return default value

getArray()

Return array values

public getArray(string $key[, mixed $default = null ]) : array<string|int, mixed>
Parameters
$key : string
$default : mixed = null
Return values
array<string|int, mixed>

getBool()

Get boolean value

public getBool(string $key[, bool|null $default = null ]) : bool
Parameters
$key : string
$default : bool|null = null
Return values
bool

getByPath()

Get value by path

public getByPath(string $path[, mixed $default = null ]) : mixed
Parameters
$path : string
$default : mixed = null

getErrors()

Return validation errors

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

getErrorsCount()

Return number of errors

public getErrorsCount() : int
Return values
int

getFilters()

Return form filters

public getFilters(string $fieldName) : array<string|int, mixed>
Parameters
$fieldName : string
Return values
array<string|int, mixed>

getFloat()

Get float value

public getFloat(string $key[, float|null $default = null ]) : float|null
Parameters
$key : string
$default : float|null = null
Return values
float|null

getInt()

Get int value

public getInt(string $key[, int|null $default = null ]) : int|null
Parameters
$key : string
$default : int|null = null
Return values
int|null

getItems()

Get collection items

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

getIterator()

Return iterator

public getIterator() : ArrayIterator
Return values
ArrayIterator

getRules()

Return validation rules

public getRules(string $fieldName) : array<string|int, mixed>
Parameters
$fieldName : string
Return values
array<string|int, mixed>

getString()

Get text value

public getString(string $key[, string|null $default = null ]) : string
Parameters
$key : string
$default : string|null = null
Return values
string

getTimestamp()

Get field converted to timestamp

public getTimestamp(string $key[, mixed $default = null ][, int|null $baseTimestamp = null ]) : int|null
Parameters
$key : string
$default : mixed = null
$baseTimestamp : int|null = null
Return values
int|null

has()

Return true if key exists in collection

public has(string $key) : bool
Parameters
$key : string
Return values
bool

isEmpty()

Return true if key exists and value not empty in collection

public isEmpty(string $key) : bool
Parameters
$key : string

Name

Return values
bool

isValid()

Return true if form is valid

public isValid() : bool
Return values
bool

merge()

Merge collection items

public merge(string $key, array<string|int, mixed> $data[, bool $recursive = false ]) : void
Parameters
$key : string
$data : array<string|int, mixed>
$recursive : bool = false

mergeItems()

Merge all collection items

public mergeItems(array<string|int, mixed> $data[, bool $recursive = false ]) : void
Parameters
$data : array<string|int, mixed>
$recursive : bool = false

offsetExists()

Return true if key exists in collection

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed
Return values
bool

offsetGet()

Get item

public offsetGet(mixed $key) : mixed
Parameters
$key : mixed

offsetSet()

Set item

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed
$value : mixed

offsetUnset()

Remove item

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed

onError()

Set callback for error valdation

public onError(Closure $callback) : void
Parameters
$callback : Closure

onValid()

Set callback for validation done

public onValid(Closure $callback) : void
Parameters
$callback : Closure

prepend()

Add value to begining of collection array

public prepend(string $key, mixed $value[, string|null $subKey = null ]) : bool
Parameters
$key : string
$value : mixed
$subKey : string|null = null
Return values
bool

push()

Push value to collection

public push(string $key, mixed $value[, string|null $subKey = null ]) : bool
Parameters
$key : string
$value : mixed
$subKey : string|null = null
Return values
bool

removeEmptyItems()

Remove empy items

public removeEmptyItems() : void

replace()

Replace array

public replace(array<string|int, mixed> $replacement) : Collection
Parameters
$replacement : array<string|int, mixed>
Return values
Collection

sanitizeVariable()

Sanitize form value

public static sanitizeVariable(mixed $value[, int $type = FILTER_SANITIZE_STRING ]) : mixed
Parameters
$value : mixed
$type : int = FILTER_SANITIZE_STRING

set()

Set item value in collection

public set(string $key, mixed $value) : Collection
Parameters
$key : string

Key Name

$value : mixed

Value

Return values
Collection

setArrayValue()

Set array value

public static setArrayValue(array<string|int, mixed> $array, string $path, mixed $value[, string $separator = '/' ]) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>
$path : string
$value : mixed
$separator : string = '/'
Return values
array<string|int, mixed>

setBooleanValue()

Set bool value

public setBooleanValue(string $path, int|string $value) : void
Parameters
$path : string
$value : int|string

setValue()

Set item value by path

public setValue(string $path, mixed $value) : void
Parameters
$path : string
$value : mixed

slice()

Slice collecion by keys

public slice(array<string|int, mixed>|string $keys) : array<string|int, mixed>
Parameters
$keys : array<string|int, mixed>|string
Return values
array<string|int, mixed>

toArray()

Return collection array

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

toTimeStamp()

Convert filed to timestamp

public toTimeStamp(string $key[, mixed $default = null ][, int|null $baseTimestamp = null ]) : self
Parameters
$key : string
$default : mixed = null
$baseTimestamp : int|null = null
Return values
self

union()

Union arrays

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

validate()

Validate

public validate([bool $throwException = false ]) : bool
Parameters
$throwException : bool = false
Tags
throws
DataValidatorException
Return values
bool

validateRule()

Validate rule

public validateRule(RuleInterface $rule, mixed $value) : bool
Parameters
$rule : RuleInterface
$value : mixed
Return values
bool

validateRules()

Validate rules

public validateRules(string $fieldName, array<string|int, mixed> $rules) : bool
Parameters
$fieldName : string
$rules : array<string|int, mixed>
Return values
bool

withData()

Set collection data

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

initCallback()

Init callback

protected initCallback() : void

        
On this page

Search results