public static function fromLegacy($value)
    {
        switch (true) {
            case $value instanceof TypeInterface:
                return $value->toBSONType();
            case $value instanceof BSON\Type:
                return $value;
            case is_array($value):
            case is_object($value):
                $result = [];

                foreach ($value as $key => $item) {
                    $result[$key] = self::fromLegacy($item);
                }

                return self::ensureCorrectType($result, is_object($value));
            default:
                return $value;
        }
    }
public static function fromLegacy($value)
    {
        switch (true) {
            case $value instanceof TypeInterface:
                return $value->toBSONType();
            case $value instanceof BSON\Type:
                return $value;
            case is_array($value):
            case is_object($value):
                $result = [];

                foreach ($value as $key => $item) {
                    $result[$key] = self::fromLegacy($item);
                }

                return self::ensureCorrectType($result, is_object($value));
            default:
                return $value;
        }
    }
public static function fromLegacy ( $ value ) { switch ( true ) { case $ value instanceof TypeInterface : return $ value -> toBSONType ( ) ; case $ value instanceof BSON \ Type : return $ value ; case is_array ( $ value ) : case is_object ( $ value ) : $ result = [ ] ; foreach ( $ value as $ key => $ item ) { $ result [ $ key ] = self :: fromLegacy ( $ item ) ; } return self :: ensureCorrectType ( $ result , is_object ( $ value ) ) ; default : return $ value ; } }
Converts a legacy type to the new BSON type

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

@param mixed $value
@return mixed
Converts a legacy type to the new BSON type