定制 remluben/cockpit-client 二次开发

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

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

remluben/cockpit-client

最新稳定版本:v1.1.0

Composer 安装命令:

composer require remluben/cockpit-client

包简介

A simple readonly api client for the cockpit headless cms

README 文档

README

NOTE:

This library can be used with the new Cockpit - Content Platform, a brand-new version of the Cockpit headless api-first CMS.

As for this basic version the API client is readonly. This is likely going to change in future versions.

A PHP API client for a very simple straightforward readonly access to the cockpit headless CMS data.

Installation

You can install the package via composer:

composer require remluben/cockpit-client

That's it. No more steps required in first place.

Usage

This section provides usage information. We refer to an instance of the \Remluben\CockpitClient\Client class as client.

Basics

At first ensure to setup your client with sensible Guzzle settings to avoid timeouts and bad performance. Next you can call any method the client provides you with to fetch data from your Cockpit installation.

// Set up your basic HTTP client, which makes the HTTP requests to Cockpit under
// the hood.
$http = new GuzzleHttp\Client([
    GuzzleHttp\RequestOptions::TIMEOUT => 2.0, // set an appropriate timeout that suits your application and server needs
    GuzzleHttp\RequestOptions::DEBUG => false, // optionally enable in development mode
]);

// Create an instance of the Cockpit client by passing all required data
$client = new Remluben\CockpitClient\Client(
    $http,                                          // The HTTP client
    'https://url-to-cockpit.tld/api/',              // The URL to the API of your Cockpit instance, i.e. https://url-to-cockpit.tld/api/
    'API-1a45a0876a88fb3f042cc6524059a4a11bf3f163', // a static token / api-key for server-side usage, should not expire
);

$results = [];
// Fetch your first content items, i.e. for content model *faqs*
try {
  $results = $client->contentItems('faqs');
}
catch (\Remluben\CockpitClient\Exceptions\ClientException $e) {
  // A client exception happens whenever 
  // - the HTTP client itself rises an exception
  // - the Cockpit API returns non 2xx status codes or runs into issues
}
catch (\Remluben\CockpitClient\Exceptions\InvalidArgumentException $e) {
  // For unintended method calls, invalid parameters or similar problems the
  // client usually throws this exception 
}

// process your results, if any...
foreach ($results as $item) {
  // do something here...
}

Error handling

Handling errors should be quite strait forward. Whenever something unexpected happens, a bad HTTP status code or an error is returned via API response the client reacts by throwing an Exception.

In other words, this means: only for HTTP status code 200 with a valid JSON response the request is considered as successful.

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

This software is released under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固