Convert DAO value for HTML display

Do NOT use if PHP is multi threaded

package salt\converter
inherited_from \salt\AbstractConverter

 Methods

Retrieve converted value

__get(string $field) : mixed
Inherited

Parameters

$field

string

Field name

Returns

mixedconverter value

Set a field with converted value

__set(string $field, mixed $value) 
Inherited

Parameters

$field

string

Field name

$value

mixed

Value

Convert field to column name

column(\salt\Base $object, \salt\Field $field, mixed $value, string $format, array<mixed,mixed> $params) : string

Parameters

$object

\salt\Base

The singleton object

$field

\salt\Field

the field to display

$value

mixed

the default value

$format

string

format to use for change the output

$params

array<mixed,mixed>

others parameters passed to convert function

Returns

stringHTML escaped text for describe $field in $format

Convert a value

convert(mixed $value) : mixed
see
inherited_from \salt\AbstractConverter::convert()

Parameters

$value

mixed

The value to convert

Returns

mixedthe converted value

Convert a value

convert(mixed $value) : mixed
Inherited
see
inherited_from \salt\Converter::convert()

Parameters

$value

mixed

The value to convert

Returns

mixedthe converted value

Convert a value using another object converter

convertAs(\salt\Base $otherObject, mixed $value, string $method = NULL) : mixed

Parameters

$otherObject

\salt\Base

An instance of the other object (retrieve it with ::singleton())

$value

mixed

The value to convert

$method

string

Optional, override the method to use for convert, one of DAOConverter::METHOD_*

Returns

mixedthe converted value

Convert a value

convertForSetter(mixed $value) : mixed
see
inherited_from \salt\AbstractConverter::convertForSetter()

Parameters

$value

mixed

The value to convert for set in object

Returns

mixedthe converted value

Convert a value

convertForSetter(mixed $value) : mixed
Inherited
see
inherited_from \salt\Converter::convertForSetter()

Parameters

$value

mixed

The value to convert for set in object

Returns

mixedthe converted value

Convert a field to an HTML input control

edit(\salt\Base $object, \salt\Field $field, mixed $value, string $format, array<mixed,mixed> $params) : string

Parameters

$object

\salt\Base

object that contains the value

$field

\salt\Field

the field

$value

mixed

the value to edit

$format

string

format to use

$params

array<mixed,mixed>

others parameters passed to convert function

Returns

stringa full HTML form tag (input, select, etc...) for editing the value

Retrieve context for accessor

getContext() : mixed
Inherited

Returns

mixed$context The context

Retrieve field name

getField() : string
Inherited

Returns

stringthe field name

Retrieve a Converter instance

getInstance(object|string $object = NULL, mixed $context = NULL, string $fieldName = NULL) : static
InheritedStatic

Parameters

$object

objectstring

Object or class name for static call

$context

mixed

context to pass at convert method

$fieldName

string

set field name : use it when delegate calls between DAOConverters only.

Returns

staticthe converter instance

Retrieve object for accessor

getObject() : object | string
Inherited

Returns

objectstring$object Instance of class name of the object

Retrieve value of a field on the current object

getValue(string $field) : mixed | NULL
see
inherited_from \salt\AbstractConverter::getValue()

Parameters

$field

string

field name

Returns

mixedNULLthe field value on current object or NULL if there is no current object or if method is COLUMN

Retrieve value of a field on the current object

getValue(string $field) : mixed | NULL
Inherited

Parameters

$field

string

field name

Returns

mixedNULLthe field value on current object or NULL if there is no current object

Convert a value before setting in object : Base->field = value;

setter(\salt\Field $field, mixed $value) : mixed

Parameters

$field

\salt\Field

field

$value

mixed

the value to convert

Returns

mixedthe converted value

Convert a DB value before setting in object, called at object load

setterDB(\salt\Field $field, mixed $value, string $format) : mixed

Parameters

$field

\salt\Field

field

$value

mixed

the value to convert

$format

string

the format to use

Returns

mixedthe converted value

Convert an Input value before setting in object : Base->FORM->field = value;

setterInput(\salt\Base $object, \salt\Field $field, mixed $value, string $format, array<mixed,mixed> $params) : mixed

Parameters

$object

\salt\Base

object that contains the value

$field

\salt\Field

field

$value

mixed

the value to convert

$format

string

the format of the value

$params

array<mixed,mixed>

others parameters passed to convert function

Returns

mixedthe converted value

Convert value for HTML display

show(\salt\Base $object, \salt\Field $field, mixed $value, string $format, array<mixed,mixed> $params) : string

Parameters

$object

\salt\Base

object that contains the value

$field

\salt\Field

the field

$value

mixed

the value to display

$format

string

format to use

$params

array<mixed,mixed>

others parameters passed to convert function

Returns

stringan HTML escaped value

Convert a value for using it in SQL query.

sql(\salt\Base $object, \salt\Field $field, mixed $value, string $format, array<mixed,mixed> $params) : mixed

This method DO NOT make any SQL escape. With PDO or similar, we don't need escape

Parameters

$object

\salt\Base

object that contains the value

$field

\salt\Field

field

$value

mixed

the value to convert

$format

string

the format of the value

$params

array<mixed,mixed>

others parameters passed to convert function

Returns

mixedthe value for using in SQL query

Convert field value to text

text(\salt\Base $object, \salt\Field $field, mixed $value, string $format, array<mixed,mixed> $params) : string

Parameters

$object

\salt\Base

object that contains the value

$field

\salt\Field

the field

$value

mixed

the value to display

$format

string

format to use

$params

array<mixed,mixed>

others parameters passed to convert function

Returns

stringa non-HTML escaped value

Initialize a converter accessor call

_init(array<mixed,mixed> $context = NULL, object $object = NULL, string $field = NULL
Inherited

Parameters

$context

array<mixed,mixed>

an array with format entry

$object

object

the object

$field

string

the field name

Convert a value from external source (input form or database) for storage in object.

convertFromExternal(string $field, mixed $value, string $format) : mixed

A value for a boolean field is converted to boolean. A value for a date field is converted to timestamp.

Parameters

$field

string

Field name

$value

mixed

value to convert

$format

string

date format

Returns

mixedthe converted value

Handle NULL values, that does not exists in HTML.

convertNullValues(\salt\Field $field, mixed $value, string $format) : NULL | string

Any nullable field with an empty string value will be NULL. If we want a real empty string, we have to use Field::EMPTY_STRING instead

Parameters

$field

\salt\Field

the field

$value

mixed

the value

$format

string

the format from convert function

Returns

NULLstringthe converted value

Make a new Converter

__construct() 
Inherited

Call the appropriate function for convert the value

delegateTo(mixed $value, array<mixed,string> $validMethods) : mixed

Parameters

$value

mixed

value to convert

$validMethods

array<mixed,string>

valid methods

Returns

mixedthe converted value

 Properties

 

context for accessor call. Generaly an array with format entry

$_salt_context : array<mixed,mixed>

Default

NULL
 

field name

$_salt_field : string

Default

NULL
 

Converters instances, indexed by class name

$_salt_instances : array<mixed,\salt\Converter>

Default

array()
Static
 

object for accessor call.

$_salt_object : object

Default

NULL

 Constants

 

METHOD_COLUMN

METHOD_COLUMN = 'column' 
 

METHOD_EDIT

METHOD_EDIT = 'edit' 
 

METHOD_SET

METHOD_SET = 'setterInput' 
 

METHOD_SHOW

METHOD_SHOW = 'show' 
 

METHOD_SQL

METHOD_SQL = 'sql' 
 

METHOD_TEXT

METHOD_TEXT = 'text'