Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400]

LICENSE This file is part of CFPropertyList.

Author: Rodney Rehm <rodney.rehm@medialize.de>
Author: Christian Kruse <cjk@wwwtech.de>
Copyright: Copyright © 2018 Teclib
License: MIT
File Size: 239 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

CFTypeDetector:: (4 methods):
  __construct()
  isAssociativeArray()
  defaultValue()
  toCFType()


Class: CFTypeDetector  - X-Ref

CFTypeDetector
Interface for converting native PHP data structures to CFPropertyList objects.

__construct(array $options = array()   X-Ref
Create new CFTypeDetector

param: array $options Configuration for casting values [autoDictionary, suppressExceptions, objectToArrayMethod, castNumericStrings]

isAssociativeArray($value)   X-Ref
Determine if an array is associative or numerical.
Numerical Arrays have incrementing index-numbers that don't contain gaps.

return: boolean true if array is associative, false if array has numeric indexes
param: array $value Array to check indexes of

defaultValue()   X-Ref
Get the default value

return: CFType the default value to return if no suitable type could be determined

toCFType($value)   X-Ref
Create CFType-structure by guessing the data-types.
CFArray, {@link CFDictionary}, {@link CFBoolean}, {@link CFNumber} and {@link CFString} can be created, {@link CFDate} and {@link CFData} cannot.
<br /><b>Note:</b>Distinguishing between {@link CFArray} and {@link CFDictionary} is done by examining the keys.
Keys must be strictly incrementing integers to evaluate to a {@link 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 {@link CFDictionary},
feel free to set the appropriate flag.
<br /><b>Note:</b> If $value is an instance of CFType it is simply returned.
<br /><b>Note:</b> If $value is neither a CFType, array, numeric, boolean nor string, it is omitted.

return: CFType CFType based on guessed type
param: mixed $value Value to convert to CFType