bit-part/mt-data-api-php-client

Thin, safe Movable Type Data API v7 client for PHP.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/bit-part/mt-data-api-php-client

v1.0.0 2025-12-05 04:20 UTC

This package is auto-updated.

Last update: 2025-12-05 06:18:43 UTC


README

PHPStan License: MIT

Movable Type Data API v7のための、薄く、安全で、PSR準拠のPHPクライアントライブラリです。

特徴

  • PSR準拠: PSR-7 (HTTP Message)、PSR-17 (HTTP Factories)、PSR-18 (HTTP Client)、PSR-3 (Logger)を実装
  • 型安全: PHP 8.2+の厳格な型付けとPHPStan level max準拠
  • 柔軟性: 任意のPSR-18互換HTTPクライアント使用可能(Guzzleがデフォルト)
  • 開発者フレンドリー: 流暢なクエリビルダー、自動ページネーション、包括的なエラーハンドリング
  • 完全テスト: Pestフレームワークによる完全なテストカバレッジ
  • 自動生成: OpenAPI仕様からResourceクラスを自動生成

要件

  • PHP 8.2 以上
  • Composer

インストール

composer require bit-part/mt-data-api-php-client

環境設定(推奨)

認証情報を安全に管理するため、.env ファイルの使用を推奨します。

# .env サポートパッケージをインストール
composer require vlucas/phpdotenv

# .env.example をコピー
cp vendor/bit-part/mt-data-api-php-client/.env.example .env

# .env を編集して実際の値を設定

詳細は USAGE.md - 環境設定 を参照してください。

クイックスタート

<?php

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

// Initialize the client
$httpClient = new GuzzleClient();
$factory = new Psr17Factory();

$client = new Client(
    baseUrl: 'https://example.com/mt-data-api.cgi/v7',
    httpClient: $httpClient,
    requestFactory: $factory,
    streamFactory: $factory
);

// Authenticate (clientId is strongly recommended)
$authenticator = $client->getAuthenticator();
$authResult = $authenticator->login(
    username: 'username',
    password: 'password',
    remember: true,
    clientId: 'my-application'
);
$client = $authResult->client;

// Make API calls
$sites = $client->raw('GET', 'sites');

Resource Helpers

use Bitpart\MtDataApi\Query\Query;

// Entries scoped to site 1
$entries = $client->entries(1);

// List entries (returns the `items` array)
$items = $entries->list(Query::make()->limit(20));

// Create a new entry
$created = $entries->create([
    'title' => 'Hello World',
    'status' => 'Publish',
]);

// Upload an asset
$asset = $client->assets(1)->upload('/path/to/image.jpg', ['label' => 'Cover']);

// Publish a template
$client->publish(1)->template(123);

// Preview a page
$preview = $client->preview(1)->page([
    'page' => ['title' => 'Draft title'],
]);

Authentication Workflow

use Bitpart\MtDataApi\Auth\Authenticator;

$authenticator = new Authenticator($client);

// Login with username/password
// Note: clientId is strongly recommended for MT Data API v7
$login = $authenticator->login(
    username: 'username',
    password: 'password',
    clientId: 'my-application'  // Identifies your application
);
$client = $login->client; // holds access token & session id

// Refresh token later using stored session id
$refreshed = (new Authenticator($client))->refresh();
$client = $refreshed->client;

// Logout to invalidate session & token
$client = (new Authenticator($client))->logout();

Development

The quick summary is below; see docs/TESTING.md for expanded guidance.

Setup

composer install

Code Quality

# Run static analysis
composer lint

# Format code
composer format

# Run tests
composer test

# Run all CI checks
composer test:ci

Project Structure

src/
  Client.php              # Main client class
  Auth/                   # Authentication
  Exceptions/             # Custom exceptions
  Http/                   # PSR-18 adapters
  Query/                  # Query builder
  Pagination/             # Pagination helpers
  Resources/              # API resource endpoints

ドキュメント

📚 利用者向け

🔧 開発者向け

License

MIT License - see LICENSE file for details.

Contributing

This project follows PSR-12 coding standards and requires PHPStan level max compliance.

Support