定制 markupai/php-sdk 二次开发

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

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

markupai/php-sdk

Composer 安装命令:

composer require markupai/php-sdk

包简介

PHP SDK for Markup.ai content governance platform

README 文档

README

Latest Version

A PHP SDK for integrating with the Markup.ai content governance platform. This library provides a clean, PSR-compliant interface for accessing Markup.ai's style checking, content validation, and automated rewriting capabilities.

Installation

Install the package via Composer:

composer require markupai/php-sdk

Laravel Integration

When used inside a Laravel 9+ application the package is auto-discovered. Configure your API token by setting MARKUPAI_API_TOKEN in the environment (or editing config/markupai.php after publishing).

php artisan vendor:publish --tag=markupai-config

Access the client through dependency injection or the optional facade:

use MarkupAI\MarkupAiClient;
use MarkupAI\Laravel\Facades\MarkupAi;

// Constructor injection
public function __construct(MarkupAiClient $client)
{
    $this->client = $client;
}

// Facade usage
$styleGuides = MarkupAi::styleGuides()->list();

Requirements

  • PHP 8.1 or higher
  • PSR-18 HTTP client implementation (e.g., Guzzle)
  • PSR-7 HTTP message implementation

Quick Start

<?php

require_once 'vendor/autoload.php';

use MarkupAI\MarkupAiClient;

// Initialize the client
$client = new MarkupAiClient('your-api-token');

// List all style guides
$styleGuides = $client->styleGuides()->list();

// Create a style check with file upload
$styleCheck = $client->styleChecks()->createWithFile([
    'dialect' => 'american_english',
    'style_guide' => 'your-style-guide-id'
], '/path/to/your/document.txt');

// Get style suggestions with file upload
$suggestions = $client->styleSuggestions()->createWithFile([
    'dialect' => 'american_english',
    'style_guide' => 'your-style-guide-id',
    'tone' => 'professional'
], '/path/to/your/document.txt');

// Generate a style rewrite with file upload
$rewrite = $client->styleRewrites()->createWithFile([
    'dialect' => 'american_english',
    'style_guide' => 'your-style-guide-id',
    'tone' => 'professional'
], '/path/to/your/document.txt');

API Reference

Style Guides

// List all style guides
$styleGuides = $client->styleGuides()->list();

// Create a new style guide
$styleGuide = $client->styleGuides()->create([
    'name' => 'My Style Guide',
    'description' => 'A custom style guide'
]);

// Get a specific style guide
$styleGuide = $client->styleGuides()->get('style-guide-id');

// Update a style guide
$styleGuide = $client->styleGuides()->update('style-guide-id', [
    'name' => 'Updated Style Guide'
]);

// Delete a style guide
$client->styleGuides()->delete('style-guide-id');

Style Checks

// Create a style check with file upload (required)
$styleCheck = $client->styleChecks()->createWithFile([
    'dialect' => 'american_english',
    'style_guide' => 'your-style-guide-id'
], '/path/to/document.txt');

// Get style check results
$styleCheck = $client->styleChecks()->get('style-check-id');

// Check if completed
if ($styleCheck->isCompleted()) {
    $results = $styleCheck->getResults();
    // Access issues and scores
    $issues = $results['original']['issues'] ?? [];
    $qualityScore = $results['original']['scores']['quality']['score'] ?? null;
}

Style Suggestions

// Create style suggestions with file upload
$suggestions = $client->styleSuggestions()->createWithFile([
    'dialect' => 'american_english',
    'style_guide' => 'your-style-guide-id',
    'tone' => 'professional'
], '/path/to/document.txt');

// Get suggestions
$suggestions = $client->styleSuggestions()->get('suggestion-id');

if ($suggestions->isCompleted()) {
    $suggestionData = $suggestions->getSuggestions();
}

Style Rewrites

// Create a style rewrite with file upload
$rewrite = $client->styleRewrites()->createWithFile([
    'dialect' => 'american_english',
    'style_guide' => 'your-style-guide-id',
    'tone' => 'professional'
], '/path/to/document.txt');

// Get rewritten content
$rewrite = $client->styleRewrites()->get('rewrite-id');

if ($rewrite->isCompleted()) {
    $rewrittenContent = $rewrite->getRewrittenContent();
}

Configuration

Custom HTTP Client

You can provide your own PSR-18 HTTP client:

use GuzzleHttp\Client as GuzzleClient;
use Nyholm\Psr7\Factory\Psr17Factory;

$httpClient = new GuzzleClient();
$factory = new Psr17Factory();

$client = new MarkupAiClient(
    token: 'your-api-token',
    httpClient: $httpClient,
    requestFactory: $factory,
    streamFactory: $factory
);

Custom Base URL

$client = new MarkupAiClient(
    token: 'your-api-token',
    baseUrl: 'https://custom-api.markup.ai/v1'
);

Error Handling

The SDK provides specific exception types for different error conditions:

use MarkupAI\Exceptions\AuthenticationException;
use MarkupAI\Exceptions\ValidationException;
use MarkupAI\Exceptions\RateLimitException;
use MarkupAI\Exceptions\ServerException;

try {
    $styleGuides = $client->styleGuides()->list();
} catch (AuthenticationException $e) {
    // Handle authentication errors (401)
    echo 'Invalid API token: ' . $e->getMessage();
} catch (ValidationException $e) {
    // Handle validation errors (422)
    echo 'Validation error: ' . $e->getMessage();
} catch (RateLimitException $e) {
    // Handle rate limiting (429)
    echo 'Rate limit exceeded: ' . $e->getMessage();
} catch (ServerException $e) {
    // Handle server errors (500+)
    echo 'Server error: ' . $e->getMessage();
}

Development

Running Tests

# Run all tests
composer test

# Run tests with coverage
composer test-coverage

# Run static analysis
composer phpstan

# Fix code style
composer cs-fix

# Check code style
composer cs-check

Requirements for Development

# Install development dependencies
composer install

# Install suggested packages for HTTP client
composer require guzzlehttp/guzzle nyholm/psr7

Running Integration Tests

Integration tests require a valid Markup.ai API token:

# Copy the example environment file
cp .env.testing.example .env.testing

# Edit .env.testing and add your API token
# MARKUPAI_API_TOKEN=your_actual_token_here

# Run all tests (integration tests will be skipped if no token is provided)
composer test

# Run only unit tests (no API token required)
vendor/bin/phpunit tests/Unit/

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

markupai/php-sdk 适用场景与选型建议

markupai/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 7, 最近一次更新时间为 2025 年 09 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 markupai/php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2025-09-17