定制 contentzen/sdk-php 二次开发

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

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

contentzen/sdk-php

最新稳定版本:v1.0.0

Composer 安装命令:

composer require contentzen/sdk-php

包简介

Official PHP SDK for ContentZen CMS

README 文档

README

Official PHP SDK for ContentZen CMS. Easily fetch and render content in Laravel and other PHP-based frameworks.

Installation

Install via Composer:

composer require contentzen/sdk-php

Usage

Initialize the Client

use ContentZen\Client;

// For public endpoints (no authentication required)
$client = new Client();

// For private endpoints (API token required)
$client = new Client('your_api_token_here');

Fetch Public Documents

$documents = $client->documents()->getPublicDocuments('collection-uuid', [
    'limit' => 10,
    'offset' => 0,
    'state' => 'published',
]);

Fetch a Public Document

$document = $client->documents()->getPublicDocument('collection-uuid', 'document-uuid');

Fetch Private Documents (API Token Required)

$documents = $client->documents()->getDocuments('collection-uuid', [
    'limit' => 10,
    'offset' => 0,
]);

Fetch a Private Document (API Token Required)

$document = $client->documents()->getDocument('collection-uuid', 'document-uuid');

Error Handling

All SDK methods throw ContentZen\Exception on error. Example:

use ContentZen\Exception;

try {
    $documents = $client->documents()->getDocuments('collection-uuid');
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Collections

// List collections
$collections = $client->collections()->getCollections();

// Get a collection
$collection = $client->collections()->getCollection('collection-uuid');

// Create a collection
$new = $client->collections()->createCollection([
    'name' => 'products',
    'display_name' => 'Products',
    'description' => 'Product catalog',
    'is_public' => false,
    'fields' => [
        ['name' => 'title', 'type' => 'string', 'display_name' => 'Product Title', 'required' => true],
        ['name' => 'price', 'type' => 'number', 'display_name' => 'Price', 'required' => true],
    ]
]);

// Update a collection
$updated = $client->collections()->updateCollection('collection-uuid', [
    'display_name' => 'Updated Products',
    'description' => 'Updated product catalog',
    'is_public' => true,
]);

// Delete a collection
$client->collections()->deleteCollection('collection-uuid');

// Get collection schema
$schema = $client->collections()->getCollectionSchema('collection-uuid');

// Get collection fields
$fields = $client->collections()->getCollectionFields('collection-uuid');

// Get field types
$fieldTypes = $client->collections()->getFieldTypes();

Media

// List media
$media = $client->media()->listMedia();

// Upload media
$uploaded = $client->media()->uploadMedia('/path/to/file.jpg');

// Get media file
$file = $client->media()->getMedia('media-uuid');

// Delete media file
$client->media()->deleteMedia('media-uuid');

Webhooks

// List webhooks
$webhooks = $client->webhooks()->listWebhooks();

// Create webhook
$newWebhook = $client->webhooks()->createWebhook([
    'url' => 'https://example.com/webhook',
    'event' => 'document.published',
]);

// Update webhook
$updatedWebhook = $client->webhooks()->updateWebhook('webhook-uuid', [
    'url' => 'https://example.com/new-webhook',
]);

// Delete webhook
$client->webhooks()->deleteWebhook('webhook-uuid');

Resources

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-31