定制 openeuropa/cdt-client 二次开发

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

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

openeuropa/cdt-client

最新稳定版本:1.0.0

Composer 安装命令:

composer require openeuropa/cdt-client

包简介

A PHP client library for communicating with the CDT service.

README 文档

README

Build Status Packagist

Description

CDT Client is a library offering a PHP API to consume Translation Centre For the Bodies of the EU services.

Install

Use Composer to install the package:

$ composer require openeuropa/cdt-client

Usage

All calls should be done by instantiating the client class:

require_once 'vendor/autoload.php';

$client = new \OpenEuropa\CdtClient\ApiClient(
    new \GuzzleHttp\Client(),
    new \GuzzleHttp\Psr7\HttpFactory(),
    new \GuzzleHttp\Psr7\HttpFactory(),
    [
        // For a full list of options see "Configuration".
        'apiBaseUrl' => 'https://example.com',
        'username' => 'your-user-name',
        'password' => 'your-password',
        'client' => 'client-name',
    ]
);

In the above example, we're passing the Guzzle HTTP client, request, stream and URI factories. But these can be replaced by any similar factories that are implementing the PSR interfaces. The last parameter is the configuration.

Configuration

Possible configurations:

  • username (string): Used for authentication.
  • password (string): Used for authentication.
  • client (string): Used for authentication.
  • apiBaseUrl (string, valid URI): The base API url.

Check connection

$response = $client->checkConnection();

Will return true or false depending on the availability of the CDT service.

Get reference data

$response = $client->getReferenceData();

Will return an array of business reference data, serialized into OpenEuropa\CdtClient\Model\Response\ReferenceData.

Translation requests

To validate and send a translation request, run the following code:

use OpenEuropa\CdtClient\Model\Request\Translation;
use OpenEuropa\CdtClient\Exception\ValidationErrorsException;

$translationRequest = new Translation()
try {
    if ($client->validateTranslationRequest($translationRequest)) {
        $correlationId = $client->sendTranslationRequest($translationRequest);
    }
} catch (ValidationErrorsException $e) {
    $errors = $e->getValidationErrors();
    // Handle the errors.
}

On success, the sendTranslationRequest() method will return the temporary Correlation ID.

Get permanent request identifier

$permanentId = $client->getPermanentIdentifier($correlationId);

Will return a permanent string identifier for the translation request, based on correlation ID. Throws the ValidationErrorsException if the correlation ID is not found.

Get the status of a translation request

$translationStatus = $client->getRequestStatus($permanentId);

Will return information on the status of translation request, based on permanent ID. The information includes the list of files to download. Throws the ValidationErrorsException if the permanent ID is invalid.

Download the file (source or translated)

$file = $client->downloadFile($fileUrl);

Downloads the specified file, if available, based on the filename listed in getRequestStatus(). Throws a ValidationErrorsException if the filename is invalid.

Contributing

Please read the full documentation for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: EUPL-1.2
  • 更新时间: 2026-04-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固