arbor-education/arbor-sdk-php
Composer 安装命令:
composer require arbor-education/arbor-sdk-php
包简介
Arbor Education PHP SDK
README 文档
README
Arbor Education SDK library.
Introduction
PHP SDK is a library which simplifies the process of integrating the Arbor REST API with your own software.
Rather than handling XML and making HTTP requests in your code, you can simply include the SDK and use getters and setters on models in order to access data from Arbor. PHP SDK includes hundreds of models as well as a gateway pattern for querying the API via a query model.
SDK supports and requires any PSR 18 based HTTP client. Make sure to install one prior to using the SDK.
Requirements
- PHP 8.1 or higher
- Composer
Installation
Simply download the project and run composer install from the root of the project to use as standalone for testing purposes.
Find the latest version on Packagist Arbor Education - PHP SDK and install it with composer directly in your project composer require arbor-education/arbor-sdk-php
Once setup use the examples/config-dist.php to create your own config. For this you will need your apps credentials added on Arbor Education - Developers Portal in order to be able to make requests to a sandbox environment.
Usage
The PsrRestGateway class is a gateway implementation for interacting with REST APIs using PSR-compliant HTTP clients. It provides methods for CRUD operations, bulk creation, querying, and handling API responses.
In the examples/example-bootstrap you will find the configuration needed to make requests, either using it directly from examples/config.php or using your own configuration. The entire examples directory is focused on helping you develop your app faster. Scripts written represent some of the most frequently used queries.
Example
When initializing the PsrRestGateway you will need to pass the Arbor\Api\Gateway\HttpClient\HttpClientInterface.
$httpClient = new \Arbor\Api\Gateway\HttpClient\HttpClient( new \Arbor\Api\Gateway\HttpClient\TypedRequestFactory(), null, null, $config['api']['baseUrl'], $config['api']['auth']['user'], $config['api']['auth']['password'] ); $api = new \Arbor\Api\Gateway\PsrRestGateway( $httpClient, new \Arbor\Model\Hydrator(), new \Arbor\Filter\CamelCaseToDash(), new \Arbor\Filter\PluralizeFilter(), );
This will create a new instance of the PsrRestGateway which you can use to interact with the Arbor API. It will try to find any existing installed PSR-18 HTTP client, or you can pass your own implementation of Psr\Http\Client\ClientInterface to the HttpClient class.
This will set the default gateway for all models, allowing you to use the SDK without needing to pass the gateway instance every time you want to retrieve or manipulate a model.
\Arbor\Model\ModelBase::setDefaultGateway($api);
Use Arbor\Api\Gateway\PsrRestGateway to make GET, POST, PUT and DELETE requests and use Arbor\Query\Query to add filters to your requests.
Multipart upload request
Use the upload() method to submit files as multipart/form-data.
use Arbor\Api\Gateway\UploadFile; $fileContent = file_get_contents('/path/to/document.pdf'); $response = $api->upload( '/rest-v2/documents/upload', new UploadFile(name: 'file', contents: $fileContent, filename: 'document.pdf') );
For large files, pass a PSR-7 stream to avoid loading the entire file into memory:
// $streamFactory can be any PSR-17 StreamFactoryInterface implementation $stream = $streamFactory->createStreamFromFile('/path/to/large-video.mp4'); $response = $api->upload( '/rest-v2/documents/upload', new UploadFile(name: 'file', contents: $stream, filename: 'large-video.mp4') );
GET request:
$student = \Arbor\Model\Student::retrieve(16);
or use examples/student-retrieve.php to see how to retrieve a record.
POST request:
use examples/staff-create.php to see how to create a new record.
PUT request:
use examples/staff-create.php to see how to update an existing record.
DELETE request:
$api->delete($staff->getPerson()); // assuming that you are deleting your newly created staff record
Query filters:
List of filters can be found in Arbor\Query\Query
$query = new \Arbor\Query\Query(Arbor\Resource\ResourceType::ARBOR_MODEL); $query->addPropertyFilter(ArborModel::PROPERTY_NAME, OPERATOR, $value); $query->addPropertyFilter(ArborModel::PROPERTY_NAME, SECOND_OPERATOR, $value); ... $records = \Arbor\Model\ArborModel::query($query); // will return an array of records foreach ($records as $record) { // e.g. $record->getDisplayName(); }
Check examples directory to see usages of filters.
arbor-education/arbor-sdk-php 适用场景与选型建议
arbor-education/arbor-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.23k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2018 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「library」 「sdk」 「REST API」 「mis」 「arbor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arbor-education/arbor-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arbor-education/arbor-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arbor-education/arbor-sdk-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Inbox pattern process implementation for your Laravel Applications
Core library that defines common interfaces used by the rest of the intahwebz..
Amqp classes
Provides command to manage a web library directory
统计信息
- 总下载量: 7.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2018-02-07