garchicms/garchi-sdk-php
最新稳定版本:v1.0.1
Composer 安装命令:
composer require garchicms/garchi-sdk-php
包简介
A PHP SDK wrapper for the Garchi CMS API
README 文档
README
The GarchiCMS PHP SDK is a PHP package for interacting with the Garchi CMS API. It provides a simple, modular, and intuitive interface for managing categories, data items, reviews, reactions, spaces, and headless CMS features.
📖 API Documentation: Garchi CMS API Docs
📖 Table of Contents
- GarchiCMS PHP SDK
Features
- ✅ Manage Data Items: Create, update, delete, and fetch data items.
- ✅ Handle Categories: Create, update, delete, and list categories.
- ✅ Manage Spaces: Create, update, and fetch spaces.
- ✅ Handle Reviews: Create, update, delete, and fetch reviews.
- ✅ Manage Reactions: Add or remove reactions for items or reviews.
- ✅ Perform Compound Queries: Execute complex queries across items, categories, and reviews.
- ✅ Work with Headless CMS: Manage assets, pages, and section templates.
Installation
Using Composer
composer require garchicms/garchi-php-sdk
Usage
This SDK is a wrapper around the Garchi CMS API, providing easy-to-use modular functions that map directly to API endpoints.
Initializing the SDK
Once installed, you can use the SDK without manually requiring files, thanks to Composer's autoloading.
use GarchiCMS\GarchiCMS; $garchi = new GarchiCMS("YOUR_API_KEY");
Module Mapping
Each module corresponds to a specific API group:
-
$garchi->dataItem→ Data Item API$garchi->dataItem->create()corresponds to Create data item API$garchi->dataItem->update()corresponds to Update data item API$garchi->dataItem->delete()corresponds to Delete data item API$garchi->dataItem->createMetaInfo()corresponds to Create meta info for item API$garchi->dataItem->deleteMetaInfo()corresponds to Delete meta info for item API$garchi->dataItem->updateMetaInfo()corresponds to Update meta info for item API$garchi->dataItem->getBySpace()corresponds to Get items by space API$garchi->dataItem->semanticSearch()corresponds to Semantic item search API$garchi->dataItem->featured()corresponds to Get featured items API$garchi->dataItem->get()corresponds to Get data item API$garchi->dataItem->getAll()corresponds to Get all data items API$garchi->dataItem->filter()corresponds to Filter data items API$garchi->dataItem->filterByMeta()corresponds to Filter data items by meta information API$garchi->dataItem->getByIds()corresponds to Get data items by IDs API
-
$garchi->category→ Category API$garchi->category->create()corresponds to Create category API$garchi->category->update()corresponds to Update category API$garchi->category->delete()corresponds to Delete category API$garchi->category->getAll()corresponds to Get all categories API
-
$garchi->space→ Space API$garchi->space->create()corresponds to Create a space API$garchi->space->update()corresponds to Update a space API$garchi->space->delete()corresponds to Delete a space API$garchi->space->getAll()corresponds to Get all spaces API$garchi->space->get()corresponds to Get space details API$garchi->space->categories()corresponds to Get categories for space API
-
$garchi->review→ Review API$garchi->review->create()corresponds to Create a review API$garchi->review->update()corresponds to Update review API$garchi->review->delete()corresponds to Delete review API$garchi->review->getByItem()corresponds to Get reviews for an item API
-
$garchi->headless→ Headless API$garchi->headless->getAsset()corresponds to Get asset file for space API$garchi->headless->getPage()corresponds to Get page content API$garchi->headless->createOrUpdateSectionTemplates()corresponds to Create or update section templates API
-
$garchi->reaction→ Reaction API$garchi->reaction->manage()corresponds to Reaction API
-
$garchi->compoundQuery→ Compound Query API$garchi->compoundQuery->query()corresponds to Compound query API
Each module’s return values correspond to the return value of the respective API endpoint. The only difference is that for non-paginated API endpoints, each module’s return value can be accessed without the .data attribute.
Example Usages
Here are some example usages
Data Item API
Create a Data Item
$newItem = $garchi->dataItem->create([ 'space_uid' => 'your_space_uid', 'name' => 'New Item', 'categories' => [1, 2, 3], ]);
Get All Items
$items = $garchi->dataItem->getAll(['size' => 10]);
Category API
Create a Category
$newCategory = $garchi->category->create([ 'category' => 'New Category', 'space_uid' => 'your_space_uid' ]);
Get All Categories
$categories = $garchi->category->getAll();
Review API
Create a Review
$review = $garchi->review->create([ 'item_id' => 1, 'rating' => 5, 'review_body' => 'Excellent product!', 'user_email' => 'user@example.com', 'user_name' => 'John Doe' ]);
Reaction API
Add or Update Reaction
$reaction = $garchi->reaction->manage([ 'reaction' => 'like', 'user_identifier' => 'user@example.com', 'review_id' => 1, 'item_id' => 1, 'reaction_for' => 'review' ]);
Space API
Create a Space
$newSpace = $garchi->space->create([ 'name' => 'New Space', 'logo' => $yourLogoFile ]);
Compound Query API
Perform a Compound Query
$queryResult = $garchi->compoundQuery->query([ 'dataset' => 'items', 'fields' => ['name', 'price'], 'conditions' => ['like', 'gte'], 'values' => ['%item%', '10'], 'logic' => ['and'] ], ['order_key' => 'name', 'order_by' => 'asc']);
Headless CMS API
Get a Page
$page = $garchi->headless->getPage([ 'space_uid' => 'your_space_uid', 'slug' => '/', 'lang' => 'en-US', 'mode' => 'live' ]);
Error Handling
All API calls throw exceptions if the API call fails.
try { $item = $garchi->dataItem->get(['item' => 1]); print_r($item); } catch (\Exception $error) { echo 'Error: ' . $error->getMessage(); }
Types and Interfaces
The SDK provides structured PHP classes for better type hinting and autocompletion.
use GarchiCMS\Contracts\GarchiItem; use GarchiCMS\Contracts\GarchiCategory; use GarchiCMS\Contracts\GarchiReview;
Contributing
Feel free to submit issues and pull requests to improve the SDK.
License
This project is licensed under the MIT License.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-12