lesstif / confluence-rest-api
PHP用户使用的Confluence REST API客户端。
0.3
2021-11-05 01:23 UTC
Requires
- php: ^7.3|^8.0
- ext-curl: *
- ext-iconv: *
- ext-json: *
- guzzlehttp/guzzle: ^7.0.1
- league/flysystem: ^1.1
- monolog/monolog: ~1.12|^2.0
- netresearch/jsonmapper: ^2.0|^3.0|^4.0
- vlucas/phpdotenv: ^4.0|^5.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpstan/phpstan: ^0.12.79
- phpunit/phpunit: ^8.0|^9.0
- symfony/var-dumper: ^4.0|^5.0
- vimeo/psalm: ^4.6
This package is auto-updated.
Last update: 2024-09-05 07:42:16 UTC
README
Atlassian的Confluence & Confluence Question REST API客户端,适用于PHP用户。
安装
-
手动安装PHP Composer或从Composer首页下载。
php -r "copy('https://getcomposer.org.cn/installer', 'composer-setup.php');" php composer-setup.php php -r "unlink('composer-setup.php');"
-
运行composer安装依赖项。
php composer.phar require 'lesstif/confluence-rest-api'
或更新您的composer.json文件。
"require": {
"lesstif/confluence-rest-api": "^0.1"
}
配置
您可以选择加载环境变量,可以是'dotenv'或'array'。
使用dotenv
将.env.example文件复制到项目根目录的.env中。
CONFLUENCE_HOST="https://your-confluence.host.com"
CONFLUENCE_USER="confluence-username"
CONFLUENCE_PASS="confluence-password"
使用array
使用ArrayConfiguration参数创建Service类。
use Lesstif\Confluence\Question\QuestionService; $qs = new QuestionService(new \Lesstif\Confluence\Configuration\ArrayConfiguration( [ 'host' => 'https://your-confluence.host.com', 'user' => 'confluence-username', 'password' => 'confluence-password', ] ));
用法
CQL
$cql = [ 'SPACE' => 'LAR', 'type' => 'page', ]; try { $s = new CQLService(); $ret = $s->search($cql); dump($ret); } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
问题
获取问题列表
$queryParam = [ // the number of questions needed (10 by default) 'limit' => 10, //the start index (0 by default) 'start' => 0, // The optional filter string which value is one of "unanswered", "popular", "my", "recent" // (default value 'recent') 'filter' => 'unanswered', ]; try { $qs = new QuestionService(); $questions = $qs->getQuestion($queryParam); foreach($questions as $q) { echo sprintf("<a href=\"%s\">%s</a><p/>\n", $q->url, $q->title); } } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
获取问题的详细信息。
try { $qs = new QuestionService(); $q = $qs->getQuestionDetail($questionId); foreach($q->answers as $a) { // print accepted answer if ($a->accepted === true) { dump($a); } } } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
获取已接受答案
try { $qs = new QuestionService(); $q = $qs->getAcceptedAnswer($questionId); dump($q); } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
答案
获取用户的答案列表
try { $username = 'lesstif'; $as = new AnswerService(); $ans = $as->getAnswers($username); foreach($ans as $a) { dump($a); } } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
获取相关问题。
try { $answerId = '123456'; $as = new AnswerService(); $q = $as->getQuestion($answerId); dump($q); } catch (\Lesstif\Confluence\ConfluenceException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); }
Confluence Rest API文档
- Confluence Server REST API - https://developer.atlassian.com/confdev/confluence-server-rest-api
- 最新服务器 - https://docs.atlassian.com/atlassian-confluence/REST/latest-server/
- Confluence Question REST API - https://docs.atlassian.com/confluence-questions/rest/index.html