定制 kylewlawrence/gridpane-api-client-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kylewlawrence/gridpane-api-client-php

Composer 安装命令:

composer require kylewlawrence/gridpane-api-client-php

包简介

GridPane API PHP SDK

README 文档

README

API Client Version

This is the first version of a community sponsored PHP SDK client for GridPane API.

API version support

This client only supports GridPane's API v1. Please see their API documentation for more information.

Requirements

  • PHP 8.1+

Installation

The GridPane API PHP SDK client can be installed using Composer.

Are you using this with Laravel? If so, use the Laravel wrapper.

Composer

To install run composer require kylewlawrence/gridpane-api-client-php

Configuration

Configuration is done through an instance of GridPane\Api\HttpClient. The block is mandatory and if not passed, an error will be thrown.

// load Composer
require 'vendor/autoload.php';

use KyleWLawrence\GridPane\Api\HttpClient as GridPaneAPI;

$bearer     = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; // replace this with your GridPane Personal Access/Bearer token

$client = new GridPaneAPI();
$client->setAuth('bearer', ['bearer' => $bearer]);

Usage

Basic Operations

// Get all servers
$servers = $client->servers()->getAll();
print_r($servers);

// Create a new server
$newServer = $client->servers()->create([
    'servername' => 'hal9000',                          
    'ip' => '199.199.199.199',                        
    'datacenter' => 'space-station-v',                     
    'webserver' => 'nginx',      
    'database' => 'percona'
]);
print_r($newServer);

// Update a server
$client->servers()->update(12345,[
    'security_updates_reboot_time' => '04:00'
]);

// Delete a server
$client->servers()->delete(12345);

// Get all sites
$sites = $client->sites()->getAll();
print_r($sites);

Discovering Methods & Classes

// Get the base methods/classes available
$client->getValidSubResrouces()

// The above example will output something like:
[
    "backups" => "GridPane\Api\Resources\Core\Backups",
    "bundle" => "GridPane\Api\Resources\Core\Bundle",
    "domain" => "GridPane\Api\Resources\Core\Domain",
    "server" => "GridPane\Api\Resources\Core\Server",
    "site" => "GridPane\Api\Resources\Core\Site",
    "systemUser" => "GridPane\Api\Resources\Core\SystemUser",
    "teams" => "GridPane\Api\Resources\Core\Teams",
    "user" => "GridPane\Api\Resources\Core\User",
]

// These are methods/classes that can be chained to the client. For instance:
// For instance, "backups" => "GridPane\Api\Resources\Core\Backups", can be used as $client->backups()

// To find the chained methods available to the class, now do:
$client->site()->getRoutes()

// The above example will output something like:
[
    "getAll" => "site",
    "get" => "site/{id}",
    "create" => "site",
    "update" => "site/{id}",
    "runCLICommand" => "site/run-wp-cli/{id}",
    "addWPUser" => "site/add-wp-user/{id}",
    "delete" => "site",
    "deleteByID" => "site/{id}",
]

// Those routes can be compared with the GridPane documentation routes and run as chained methods such as the below command to get all sites:
$client->site()->getAll()

Pagination

The GridPane API offers a way to get the next pages for the requests and is documented in the GridPane Developer Documentation.

The way to do this is to pass it as an option to your request.

$servers = $this->client->servers()->getAll(['per_page' => 100, 'page' => 2]);

The allowed options are

  • per_page
  • page

Retrying Requests

Add the RetryHandler middleware on the HandlerStack of your GuzzleHttp\Client instance. By default GridPane\Api\HttpClient retries:

  • timeout requests
  • those that throw Psr\Http\Message\RequestInterface\ConnectException:class
  • and those that throw Psr\Http\Message\RequestInterface\RequestException:class that are identified as ssl issue.

Available options

Options are passed on RetryHandler as an array of values.

  • max = 2 limit of retries
  • interval = 300 base delay between retries in milliseconds
  • max_interval = 20000 maximum delay value
  • backoff_factor = 1 backoff factor
  • exceptions = [ConnectException::class] Exceptions to retry without checking retry_if
  • retry_if = null callable function that can decide whether to retry the request or not

Contributing

Pull Requests are always welcome. I'll catch-up and develop the contribution guidelines soon. For the meantime, just open and issue or create a pull request.

Copyright and license

Copyright 2013-present GridPane

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

kylewlawrence/gridpane-api-client-php 适用场景与选型建议

kylewlawrence/gridpane-api-client-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 617 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php-sdk」 「gridpane」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kylewlawrence/gridpane-api-client-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kylewlawrence/gridpane-api-client-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 kylewlawrence/gridpane-api-client-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 617
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 13
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-08