Class DecimalType
Decimal type converter.
Use to convert decimal data between PHP and the database types.
Property Summary
- 
        $_name protectedstring|nullIdentifier name for this type 
- 
        $_useLocaleParser protectedboolWhether numbers should be parsed using a locale aware parser when marshalling string inputs. 
- 
        $numberClass public staticstringThe class to use for representing number objects 
Method Summary
- 
          __construct() publicConstructor 
- 
          _parseValue() protectedConverts localized string into a decimal string after parsing it using the locale aware parser. 
- 
          getBaseType() publicReturns the base type name that this class is inheriting. 
- 
          getName() publicReturns type identifier name for this object. 
- 
          manyToPHP() publicReturns an array of the values converted to the PHP representation of this type. 
- 
          marshal() publicMarshalls request data into decimal strings. 
- 
          newId() publicGenerate a new primary key value for a given type. 
- 
          toDatabase() publicConvert decimal strings into the database format. 
- 
          toPHP() publicCasts given value from a database type to a PHP equivalent. 
- 
          toStatement() publicGet the correct PDO binding type for decimal data. 
- 
          useLocaleParser() publicSets whether or not to parse numbers passed to the marshal() function by using a locale aware parser. 
Method Detail
__construct() ¶ public
__construct(string|null $name = null)Constructor
Parameters
- 
                string|null$name optional
- The name identifying this type 
_parseValue() ¶ protected
_parseValue(string $value): stringConverts localized string into a decimal string after parsing it using the locale aware parser.
Parameters
- 
                string$value
- The value to parse and convert to an float. 
Returns
stringgetBaseType() ¶ public
getBaseType(): string|nullReturns the base type name that this class is inheriting.
This is useful when extending base type for adding extra functionality, but still want the rest of the framework to use the same assumptions it would do about the base type it inherits from.
Returns
string|nullgetName() ¶ public
getName(): string|nullReturns type identifier name for this object.
Returns
string|nullmanyToPHP() ¶ public
manyToPHP(array $values, string[] $fields, Cake\Database\DriverInterface $driver): arrayReturns an array of the values converted to the PHP representation of this type.
Parameters
- 
                array$values
- 
                string[]$fields
- 
                Cake\Database\DriverInterface$driver
Returns
arraymarshal() ¶ public
marshal(mixed $value): string|nullMarshalls request data into decimal strings.
Most useful for converting request data into PHP objects, that make sense for the rest of the ORM/Database layers.
Parameters
- 
                mixed$value
- The value to convert. 
Returns
string|nullConverted value.
newId() ¶ public
newId(): mixedGenerate a new primary key value for a given type.
This method can be used by types to create new primary key values when entities are inserted.
Returns
mixedtoDatabase() ¶ public
toDatabase(mixed $value, Cake\Database\DriverInterface $driver): string|float|int|nullConvert decimal strings into the database format.
Parameters
- 
                mixed$value
- The value to convert. 
- 
                Cake\Database\DriverInterface$driver
- The driver instance to convert with. 
Returns
string|float|int|nullThrows
InvalidArgumentExceptiontoPHP() ¶ public
toPHP(mixed $value, Cake\Database\DriverInterface $driver): string|nullCasts given value from a database type to a PHP equivalent.
Parameters
- 
                mixed$value
- The value to convert. 
- 
                Cake\Database\DriverInterface$driver
- The driver instance to convert with. 
Returns
string|nulltoStatement() ¶ public
toStatement(mixed $value, Cake\Database\DriverInterface $driver): intGet the correct PDO binding type for decimal data.
Parameters
- 
                mixed$value
- The value being bound. 
- 
                Cake\Database\DriverInterface$driver
- The driver. 
Returns
intuseLocaleParser() ¶ public
useLocaleParser(bool $enable = true): $thisSets whether or not to parse numbers passed to the marshal() function by using a locale aware parser.
Parameters
- 
                bool$enable optional
- Whether or not to enable 
Returns
$thisThrows
RuntimeExceptionProperty Detail
$_useLocaleParser ¶ protected
Whether numbers should be parsed using a locale aware parser when marshalling string inputs.
Type
bool