gentics/mesh-php-client
Composer 安装命令:
composer require gentics/mesh-php-client
包简介
Gentics Mesh PHP Client Library
关键字:
README 文档
README
PHP Client implementation for Gentics Mesh REST API.
Installation
composer require gentics/mesh-php-client
Basic usage
use Gentics\Mesh\Client\MeshClient; require_once __DIR__ . '/vendor/autoload.php'; $client = new MeshClient("http://localhost:8080/api/v1"); // Load user info (sync) $request = $client->me(); $response = $request->send(); echo $response->getBody(); // Load user info (async) $promise = $request->sendAsync(); $promise->then(function ($response) { echo 'I completed! ' . $response->getBody(); }); $promise->wait(); // Load users and apply paging $request = $client->findUsers(["perPage" => 1]); $response = $request->send(); echo $response->getBody();
Authentication
$client = new MeshClient("http://localhost:8080/api/v1"); // You can either login and use the build-in cookie handling // Keep in mind that your cookie will not be automatically refreshed. // Any authenticated request will refresh the cookie and keep you authenticated. $client->login("admin", "admin")->wait(); // Or use a dedicated API key which will never expire // You can use the mesh-cli to generate a key // Setting the API key will invalidate any previously set login token information $client->setAPIKey("eyJ0eXAiOiJKV1QiLC … ZYYJbD8HllF6XZT0xRTxr3i4b9PY");
GraphQL Example
$client = new MeshClient("http://localhost:8080/api/v1"); $query = [ "query" => "{users{elements{uuid, username}}}" ]; $request = $client->graphQL("demo", $query); $response = $request->send(); $json = $response->toJson(); $this->assertEquals("anonymous", $json->data->users->elements[0]->username);
WebRoot Example
With webroot you can fetch any node which contains a segment field in the schema.
The webroot endpoint is also able to directly return binary data.
$client = new MeshClient("http://localhost:8888/api/v1"); $request = $client->webroot("demo", "/images/yacht-pelorus.jpg"); $response = $request->send(); // You can check whether the webroot response returns json or otherwise binary data (e.g. image data) $response->isJson();
CRUD Example
$client = new MeshClient("http://localhost:8080/api/v1"); $client->login("admin", "admin")->wait(); // 1. Create User $request = [ "username" => "guzzle", "password" => "geheim", ]; $uuid = "5725992507e748a1a5992507e7f8a115"; $userResp = $client->createUserWithUuid($uuid, $request)->send()->toJson(); // 2. Read user $user = $client->findUserByUuid($uuid)->send()->toJson(); // 3. Update user $user->username = "hugo"; $updated = $client->updateUser($uuid, $user)->send()->toJson(); // 4. Delete user $client->deleteUser($uuid)->send();
Error Handling
By default exceptions will be thrown if the request fails (e.g. 4xx, 5xx error code).
try { $uuid = "5725992507e748a1a5992507e7f8a115"; $client->deleteUser($uuid)->send(); } catch (ClientException $e) { // Error could indicate a 404 $response = $e->getResponse(); echo $response->getBody()->getContents(); }
Configuration
It is possible to configure the underlying Guzzle client:
// Change the default error behaviour to not throw error exceptions $config = ['http_errors' => false]; $client = new MeshClient("http://localhost:8080/api/v1", $config);
Compatibility
- Gentics Mesh 1.8.x
- PHP 8.1+
TODOs
- Implement full upload support
- Implement eventbus websocket support
Release
maintenance-0.10.x branch Versioning: 0.10.x - PHP 7.x, Guzzle 6
master branch Versioning: 0.20.x - PHP 8.1+, Guzzle 7
License
gentics/mesh-php-client 适用场景与选型建议
gentics/mesh-php-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.45k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 08 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sdk」 「mesh」 「rest-client」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gentics/mesh-php-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gentics/mesh-php-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gentics/mesh-php-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP library for extracting MeSH descriptors from XML.
Simple PHP Rest Client
package to programitcaily create content for WordPress
REST client for PHP 7.4+
A PHP library for accessing REST services
PHP client for Dinas Shipping API
统计信息
- 总下载量: 14.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2018-08-29