DecimalType
extends BaseType
in package
implements
BatchCastingInterface
Decimal type converter.
Use to convert decimal data between PHP and the database types.
Table of Contents
Interfaces
- BatchCastingInterface
- Denotes type objects capable of converting many values from their original database representation to php values.
Properties
- $numberClass : string
- The class to use for representing number objects
- $_name : string|null
- Identifier name for this type
- $_useLocaleParser : bool
- Whether numbers should be parsed using a locale aware parser when marshalling string inputs.
Methods
- __construct() : mixed
- Constructor
- getBaseType() : string|null
- Returns the base type name that this class is inheriting.
- getName() : string|null
- Returns type identifier name for this object.
- manyToPHP() : array<string, mixed>
- Returns an array of the values converted to the PHP representation of this type.
- marshal() : string|null
- Marshalls request data into decimal strings.
- newId() : mixed
- Generate a new primary key value for a given type.
- toDatabase() : string|float|int|null
- Convert decimal strings into the database format.
- toPHP() : string|null
- Casts given value from a database type to a PHP equivalent.
- toStatement() : int
- Get the correct PDO binding type for decimal data.
- useLocaleParser() : $this
- Sets whether to parse numbers passed to the marshal() function by using a locale aware parser.
- _parseValue() : string
- Converts localized string into a decimal string after parsing it using the locale aware parser.
Properties
$numberClass
The class to use for representing number objects
public
static string
$numberClass
= \Cake\I18n\Number::class
$_name
Identifier name for this type
protected
string|null
$_name
$_useLocaleParser
Whether numbers should be parsed using a locale aware parser when marshalling string inputs.
protected
bool
$_useLocaleParser
= false
Methods
__construct()
Constructor
public
__construct([string|null $name = null ]) : mixed
Parameters
- $name : string|null = null
-
The name identifying this type
getBaseType()
Returns the base type name that this class is inheriting.
public
getBaseType() : string|null
Tags
Return values
string|null —The base type name that this class is inheriting.
getName()
Returns type identifier name for this object.
public
getName() : string|null
Tags
Return values
string|null —The type identifier name for this object.
manyToPHP()
Returns an array of the values converted to the PHP representation of this type.
public
manyToPHP(array<string|int, mixed> $values, array<string|int, mixed> $fields, DriverInterface $driver) : array<string, mixed>
Parameters
- $values : array<string|int, mixed>
-
The original array of values containing the fields to be casted
- $fields : array<string|int, mixed>
-
The field keys to cast
- $driver : DriverInterface
-
Object from which database preferences and configuration will be extracted.
Tags
Return values
array<string, mixed>marshal()
Marshalls request data into decimal strings.
public
marshal(mixed $value) : string|null
Parameters
- $value : mixed
-
The value to convert.
Return values
string|null —Converted value.
newId()
Generate a new primary key value for a given type.
public
newId() : mixed
Tags
Return values
mixed —A new primary key value.
toDatabase()
Convert decimal strings into the database format.
public
toDatabase(mixed $value, DriverInterface $driver) : string|float|int|null
Parameters
- $value : mixed
-
The value to convert.
- $driver : DriverInterface
-
The driver instance to convert with.
Tags
Return values
string|float|int|nulltoPHP()
Casts given value from a database type to a PHP equivalent.
public
toPHP(mixed $value, DriverInterface $driver) : string|null
Parameters
- $value : mixed
-
The value to convert.
- $driver : DriverInterface
-
The driver instance to convert with.
Return values
string|nulltoStatement()
Get the correct PDO binding type for decimal data.
public
toStatement(mixed $value, DriverInterface $driver) : int
Parameters
- $value : mixed
-
The value being bound.
- $driver : DriverInterface
-
The driver.
Return values
intuseLocaleParser()
Sets whether to parse numbers passed to the marshal() function by using a locale aware parser.
public
useLocaleParser([bool $enable = true ]) : $this
Parameters
- $enable : bool = true
-
Whether to enable
Tags
Return values
$this_parseValue()
Converts localized string into a decimal string after parsing it using the locale aware parser.
protected
_parseValue(string $value) : string
Parameters
- $value : string
-
The value to parse and convert to an float.