public static function toLegacy($value)
    {
        switch (true) {
            case $value instanceof BSON\Type:
                return self::convertBSONObjectToLegacy($value);
            case is_array($value):
            case is_object($value):
                $result = [];

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

                return $result;
            default:
                return $value;
        }
    }
public static function toLegacy($value)
    {
        switch (true) {
            case $value instanceof BSON\Type:
                return self::convertBSONObjectToLegacy($value);
            case is_array($value):
            case is_object($value):
                $result = [];

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

                return $result;
            default:
                return $value;
        }
    }
public static function toLegacy ( $ value ) { switch ( true ) { case $ value instanceof BSON \ Type : return self :: convertBSONObjectToLegacy ( $ value ) ; case is_array ( $ value ) : case is_object ( $ value ) : $ result = [ ] ; foreach ( $ value as $ key => $ item ) { $ result [ $ key ] = self :: toLegacy ( $ item ) ; } return $ result ; default : return $ value ; } }
Converts a BSON type to the legacy types

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

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