优先级 / edm-sdk
一个用于与教育管理器(EDM)的RESTful API交互的PHP库。
1.0.0
2024-04-10 21:04 UTC
Requires
- php: ^7.4.1 || ^8.0
- guzzlehttp/guzzle: ^6.5.8 || ^7.0.0
- league/oauth2-client: ^2.4
Requires (Dev)
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2024-09-10 22:07:30 UTC
README
一个用于与教育管理器(EDM)的RESTful API交互的PHP库。
使用Composer安装
docker compose run --rm composer install
用法
初始化客户端
use Priorist\EDM\Client\Client; $client = new Client('https://edm.example.com', 'CLIENT_ID', 'CLIENT_SECRET'); // $client now works with global permission, e.g. to read events. $events = $client->event->findUpcoming(); // To switch to permissions of a given user, e.g. to read participant data, call logIn // with the user’s login name and password: $accessToken = $client->logIn('USER_NAME', 'PASSWORD'); $client->event->findParticipating(); // You may store $accessToken in your session to re-use it later: $client->setAccessToken($accessToken);
事件
给定ID的单个事件
$event = $client->event->findById(4711); if ($event !== null) echo $event['event_base_name'] . "\n"; }
即将发生的事件列表
$upcomingEvents = $client->event->findUpcoming(); foreach ($upcomingEvents as $event) { echo $event['event_base_name'] . "\n"; }
分类
给定ID的单个分类
$location = $client->category->findById(4711); if ($category !== null) echo $category['name'] . "\n"; }
所有分类列表
$categories = $client->category->findAll(); foreach ($categories as $category) { echo $category['name'] . "\n"; }
事件地点
给定ID的单个地点
$location = $client->eventLocation->findById(4711); if ($location !== null) echo $location['name'] . "\n"; }
所有地点列表
$locations = $client->eventLocation->findAll(); foreach ($locations as $location) { echo $location['name'] . "\n"; }
讲师
给定ID的单个讲师
$lecturer = $client->lecturer->findById(4711); if ($lecturer !== null) echo $lecturer['name'] . "\n"; }
所有讲师列表
$lecturers = $client->lecturer->findAll(); foreach ($lecturers as $lecturer) { echo $lecturer['name'] . "\n"; }
标签
给定ID的单个标签
$lecturer = $client->tag->findById(4711); if ($tag !== null) echo $tag['name'] . "\n"; }
所有标签列表
$tags = $client->tag->findAll(); foreach ($tags as $tag) { echo $tag['name'] . "\n"; }
报名
为给定事件报名
use Priorist\EDM\Client\Rest\ClientException; $enrollment = [ 'first_name' => 'John', 'last_name' => 'Doe', 'event' => 4711, 'price' => 4712, ]; try { $enrollment = $client->enrollment->create($enrollment); } catch (ClientException $e) { $errors = $e->getDetails(); // Contains errors for missing/invalid fields/values } echo $enrollment['id']; // Holds the resulting ID on success.
通用请求
如果您在某个存储库中找不到合适的方法,您可以使用更通用的方法fetchCollection($params = [])
和fetchSingle(int $id, array $params = [])
。
例如,$client->event->findUpcoming()
等于
$client->event->fetchCollection([ 'ordering' => 'first_day', 'first_day__gte' => date('Y-m-d'), ]);
您甚至可以调用任何您喜欢的端点,即使是没有实际存储库的端点
$client->getRestClient()->fetchCollection('events', [ 'ordering' => 'first_day', 'first_day__gte' => date('Y-m-d'), ]);
类文档
当前的PHPDocs可以在以下位置查看:https://priorist.github.io/edm-sdk-php/
运行测试
启用compose.override.yml
并运行
docker compose run --rm test
Docker for Mac包括XDebug支持。
要创建和查看详细的、可浏览的测试覆盖率报告,请运行
docker compose run --rm test tests --coverage-html test_results/coverage && open test_results/coverage/index.html
生成文档
docker compose run --rm docs && open docs/index.html
构建*.phar存档
要使用SDK在旧版应用程序中,您可以在应用程序中构建并包含*.phar包。
首先下载phar-composer
curl --location --output phar-composer.phar https://clue.engineering/phar-composer-latest.phar
构建存档
docker compose run --rm phar
要使用客户端,包括存档的自动加载
include 'edm-sdk.phar/vendor/autoload.php';