\Piko\ModelTrait

Base model trait.

Properties summary

Name Description
protected $errors Errors hash container

Methods summary

Name Description
public bind Bind the data to the model attributes.
public getErrors Return the errors hash container
public isValid Check if the model is valid
public toArray Get the model data as an associative array.
protected getAttributes Get the public properties reprenting the data mode…
protected setError Set an error that will be appended to the errors c…
protected validate Validate this model (Should be extended). Inherite…
private castBooleanValue Cast a value to a boolean using common form repres…
private castValueForProperty Cast a bound value according to the declared prope…

Properties

protected $errors : string[]

Errors hash container


Methods

public bind(): void

public  bind(array  $data): void

Bind the data to the model attributes.

Parameters

$data : An array of data (name-value pairs).


public getErrors(): string[]

public  getErrors(): string[]

Return the errors hash container

Return:

string[]


public isValid(): bool

public  isValid(): bool

Check if the model is valid

Return:

bool


public toArray(): array

public  toArray(): array

Get the model data as an associative array.

Return:

array


protected getAttributes(): array

protected  getAttributes(): array

Get the public properties reprenting the data model

Return:

array


protected setError(): void

protected  setError(string  $errorName, string  $errorMsg): void

Set an error that will be appended to the errors container

Parameters

$errorName :

$errorMsg :

see \Piko\ModelTrait::$errors


protected validate(): void

protected  validate(): void

Validate this model (Should be extended). Inherited method should fill the errors array using the setError method if the model is not valid.

see \Piko\ModelTrait::setError()

see \Piko\ModelTrait::isValid()

codeCoverageIgnore


private castBooleanValue(): bool

private  castBooleanValue(mixed  $value): bool

Cast a value to a boolean using common form representations.

Parameters

$value :

Return:

bool


private castValueForProperty(): mixed

private  castValueForProperty(\ReflectionProperty  $property, mixed  $value): mixed

Cast a bound value according to the declared property type.

Parameters

$property :

$value :

Return:

mixed