markupai/php-sdk
Composer 安装命令:
composer require markupai/php-sdk
包简介
PHP SDK for Markup.ai content governance platform
README 文档
README
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 markupai/php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
A Symfony bundle for using the CssToInlineStyles translator by tijsverkoyen
A block that displays featured content - large image, title, description and link.
Fixing php code style
The coding standard applying to all Youdot PHP projects, based on Doctrine set of PHPCS rules, with additional checks.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-09-17