【发布时间】:2019-05-28 21:08:01
【问题描述】:
我目前正在开发一个社交应用程序。
我想在我的 PHP 后端有一个版本控制系统,但我不知道从哪里开始:我在网上查了一堆文章,但我真的不明白我发现了什么。
假设我的应用程序是 v1.0。然后我创建了一个新版本 v2.0,当然我也更新了 PHP 文件。在此之后,如果有人没有从 v1.0 更新他们的应用程序,我希望他们联系myapp.com/v1.0/,这样应用程序就不会崩溃。
你会推荐什么?
我的一个典型的PHP文件是这样的,例如:
<?php
// Include files
include_once ('../../config.php');
include_once (ROOT_DIR . '/config/includes.php');
$_USERDATA = Validator::validateUser($_POST["userId"], $_POST["session"]);
// Valid session
$qry = $db->prepare('SELECT n.id, n.type, n.time, n.isRead, n.postId, n.commentId, n.text, n.inReplyToCommentId, u.id as byUserId,
( SELECT COUNT(nu.id)
FROM notificationUsers AS nu
WHERE nu.notificationId = n.id ) as detail1,
( SELECT nu2.userId
FROM notificationUsers AS nu2
WHERE nu2.notificationId = n.id ORDER BY nu2.id DESC LIMIT 1 ) as latestUserId FROM notifications AS n LEFT JOIN userData AS u ON n.byUserId = u.id
WHERE n.userId = :userId ORDER BY n.time DESC');
$qry->bindParam(':userId', $_USERDATA["userId"], PDO::PARAM_INT);
$qry->execute();
$notificationsArray = $qry->fetchAll(PDO::FETCH_ASSOC);
$returnValue = array();
$returnValue["status"] = "1";
$returnValue["title"] = "Success";
$returnValue["message"] = "Downloaded notifications";
$returnValue["data_notifications"] = $notificationsArray;
exit(json_encode($returnValue));
?>
...
更新 1
所以我决定做以下事情:
将每个未共享的文件放在一个文件夹中,如下所示:
/api/v1.0/file.php
但是每个资源(例如图像)都在 API 之外
/resources/images/profilepictures/image.jpg
如果我做一个小改动,我只会更新api/v1.0/ 文件夹中的文件。
然后,所有使用 Application v1.1 的用户都在请求 myapp.com/api/v1.1/,但我将他们重定向到 api/v1.0/ 在那里我可以向用户提供正确的数据(取决于请求是否从 v1.0 或 v1.1)
如果版本加起来并且我发布了更大的更新,我将创建一个名为 v2.0 的新文件夹,这样就可以了...
或者你怎么看?我该怎么做?
【问题讨论】:
标签: php api versioning