public static function getDocumentIdFromLocation($location)
    {
        if (!is_string($location)) {
            // can't do anything about it if location is not even a string
            return null;
        }

        if (0 === strpos($location, '/_db/')) {
            // /_db/<dbname>/_api/document/<collection>/<key>
            @list(, , , , , $collectionName, $id) = explode('/', $location);
        } else {
            // /_api/document/<collection>/<key>
            @list(, , , $collectionName, $id) = explode('/', $location);
        }

        if (is_string($id)) {
            $id = urldecode($id);
        }

        return $collectionName . '/' . $id;
    }