Phpdocumentor和Slim路由器文档

3

我使用phpdocumentor为我的项目生成文档。它可以为我的函数生成良好的文档,例如:

    /**
       * Hash generator
       *
       * Long description
       *
       * @param string $password Password
       * @return string
       */
    function generate_hash($password) {
        global $PASSWORD_SALT;
        return crypt($password, $PASSWORD_SALT);
    }

但是我还没有找到一种为slim (php框架)文档化映射的方法:

    /**
     * Delete news
     *
     * Delete news by id
     *
     * @link /news/delete/:id
     *
     */
    $app->get('/news/delete/:id', function ($id) use ($app) {
        $item = ORM::for_table('news')->find_one($id);
        if ($item)
            $item->delete();
        $app->redirect('/');
    })->conditions(array('id'=>'\d+'));

如何正确地记录类似这样的事情?


API使用不是API文档的一部分。您可以将代码包装在一个函数或方法中,并返回结果。 - Daniel
1个回答

0
为了将我的评论描述为答案,我会指向类似于以下内容的东西:
/**
 * Delete news
 *
 * Delete news by id
 *
 * @link /news/delete/:id
 *
 */
public function deleteNewsByID (&$app, $id)
{
     return $app->get('/news/delete/:id', function ($id) use ($app) {
         $item = ORM::for_table('news')->find_one($id);
         if ($item)
             $item->delete();
         $app->redirect('/');
     })->conditions(array('id'=>'\d+'));
}

但我不熟悉slim,所以我不能保证这会起作用。正如下面的评论所述,这也不被推荐或漂亮。


1
将代码更改以使“自动文档”起作用,听起来像是“本末倒置”。 - Saic Siquot
是的,但这是在 documentor 或 apigen 中记录此信息的唯一方法。我从未说过它很漂亮,也不明白为什么有人想要在源代码之外记录这个。 - Daniel
1
有几个原因。有时候你必须与第三方程序员合作,他们没有访问API源代码的权限,但仍然需要文档来编写他们的客户端。 - Andres SK
这是使用Slim框架构建REST API的非常常见的用例,而API的消费者需要一个API文档。非常简单明了。 - Kristian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接