Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
CFTypeDetector Class Reference

Public Member Functions

 __construct (array $options=array())
 Create new CFTypeDetector.
 
 toCFType ($value)
 Create CFType-structure by guessing the data-types.
 

Protected Member Functions

 defaultValue ()
 Get the default value.
 
 isAssociativeArray ($value)
 Determine if an array is associative or numerical.
 

Protected Attributes

boolean $autoDictionary = false
 flag stating if all arrays should automatically be converted to CFDictionary
 
boolean $castNumericStrings = true
 flag stating if "123.23" should be converted to float (true) or preserved as string (false)
 
callable $objectToArrayMethod = null
 name of a method that will be used for array to object conversations
 
boolean $suppressExceptions = false
 flag stating if exceptions should be suppressed or thrown
 

Constructor & Destructor Documentation

◆ __construct()

CFTypeDetector::__construct ( array $options = array())

Create new CFTypeDetector.

Parameters
array$optionsConfiguration for casting values [autoDictionary, suppressExceptions, objectToArrayMethod, castNumericStrings]

Member Function Documentation

◆ defaultValue()

CFTypeDetector::defaultValue ( )
protected

Get the default value.

Return values
CFTypethe default value to return if no suitable type could be determined

◆ isAssociativeArray()

CFTypeDetector::isAssociativeArray ( $value)
protected

Determine if an array is associative or numerical.

Numerical Arrays have incrementing index-numbers that don't contain gaps.

Parameters
array$valueArray to check indexes of
Return values
booleantrue if array is associative, false if array has numeric indexes

◆ toCFType()

CFTypeDetector::toCFType ( $value)

Create CFType-structure by guessing the data-types.

CFArray, CFDictionary, CFBoolean, CFNumber and CFString can be created, CFDate and CFData cannot.
Note:Distinguishing between CFArray and CFDictionary is done by examining the keys. Keys must be strictly incrementing integers to evaluate to a CFArray. Since PHP does not offer a function to test for associative arrays, this test causes the input array to be walked twice and thus work rather slow on large collections. If you work with large arrays and can live with all arrays evaluating to CFDictionary, feel free to set the appropriate flag.
Note: If $value is an instance of CFType it is simply returned.
Note: If $value is neither a CFType, array, numeric, boolean nor string, it is omitted.

Parameters
mixed$valueValue to convert to CFType
Return values
CFTypeCFType based on guessed type @uses isAssociativeArray() to check if an array only has numeric indexes

The documentation for this class was generated from the following file: