PHP Class Alcaeus\MongoDbAdapter\TypeConverter

Datei anzeigen Open project: alcaeus/mongo-php-adapter Class Usage Examples

Public Methods

Method Description
fromLegacy ( mixed $value ) : mixed Converts a legacy type to the new BSON type
isNumericArray ( array $array ) : boolean Helper method to find out if an array has numerical indexes
toLegacy ( mixed $value ) : mixed Converts a BSON type to the legacy types

Private Methods

Method Description
convertBSONObjectToLegacy ( MongoDB\BSON\Type $value ) : mixed Converter method to convert a BSON object to its legacy type
ensureCorrectType ( array $array, boolean $wasObject = false ) : array | MongoDB\Model\BSONArray | MongoDB\Model\BSONDocument Converts all arrays with non-numeric keys to stdClass

Method Details

fromLegacy() public static method

This method handles type conversion from ext-mongo to ext-mongodb: - For all types (MongoId, MongoDate, etc.) it returns the correct BSON object instance - For arrays and objects it iterates over properties and converts each item individually - For other types it returns the value unconverted
public static fromLegacy ( mixed $value ) : mixed
$value mixed
return mixed

isNumericArray() public static method

For performance reason, this method checks the first array index only. More thorough inspection of the array might be needed. Note: Returns true for empty arrays to preserve compatibility with empty lists.
public static isNumericArray ( array $array ) : boolean
$array array
return boolean

toLegacy() public static method

This method handles type conversion from ext-mongodb to ext-mongo: - For all instances of BSON\Type it returns an object of the corresponding legacy type (MongoId, MongoDate, etc.) - For arrays and objects it iterates over properties and converts each item individually - For other types it returns the value unconverted
public static toLegacy ( mixed $value ) : mixed
$value mixed
return mixed