public static function isInternalType($value)
    {
        if (!is_object($value)) {
            return false;
        }

        if (class_exists('\MongoDB\BSON\Type')) {
            // mongodb extension for PHP 7
            return $value instanceof \MongoDB\BSON\Type;
        } else {
            // legacy mongo extension for PHP 5
            $mongoTypes = array(
                'MongoId',
                'MongoCode',
                'MongoDate',
                'MongoRegex',
                'MongoBinData',
                'MongoInt32',
                'MongoInt64',
                'MongoDBRef',
                'MongoMinKey',
                'MongoMaxKey',
                'MongoTimestamp'
            );

            return in_array(
                get_class($value),
                $mongoTypes
            );
        }
    }