php-redmine-api

kbsaliMIT活跃维护

面向 Redmine 的 PHP 客户端库,采用面向对象封装 API 调用,省去手写 HTTP 请求和解析响应,方便在 PHP 项目中集成 Redmine 的工单与项目管理功能。

A simple PHP Redmine API client, Object Oriented

v2.10.0发布于 2026-10-26 15:23 UTC423star178fork同步于 2026-11-10 06:03 UTC

怎么上手

README 里没有找到可直接复制的安装命令

README 里没有找到可直接复制的安装命令,请到 README 或官方文档查看安装方式。

硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本v2.10.0
  1. v2.10.0最新正式版2026-10-26 · 2026-10-26 15:23 UTC

    What's Changed

    Full Changelog: https://github.com/kbsali/php-redmine-api/compare/v2.9.1...v2.10.0

  2. v2.9.12026-04-03 · 2026-04-03 07:37 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/kbsali/php-redmine-api/compare/v2.9.0...v2.9.1

  3. v2.9.02026-03-08 · 2026-03-08 05:58 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/kbsali/php-redmine-api/compare/v2.8.0...v2.9.0

  4. v2.8.02025-06-02 · 2025-06-02 19:09 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/kbsali/php-redmine-api/compare/v2.7.0...v2.8.0

  5. v2.7.02024-07-10 · 2024-07-10 11:58 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/kbsali/php-redmine-api/compare/v2.6.0...v2.7.0

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    PHP Redmine API

    Latest Version Software License Build Status Codecov Total Downloads

    A simple PHP Object Oriented wrapper for Redmine API.

    Uses Redmine API.

    Features

    • Follows PSR-4 conventions and coding standard: autoload friendly
    • Choose between using native cURL function or any PSR-18 HTTP client implementation like Guzzle for handling http connections
    • mid-level API e.g.
      $client->getApi('issue')->create(['project_id' => 1, 'subject' => 'issue title']);
      
      $response = $client->getApi('issue')->getLastResponse();
      
    • low-level API e.g.
      $response = $client->request(
          HttpFactory::makeJsonRequest(
              'POST',
              '/issues.json',
              '{"issue":{"project_id":1,"subject":"issue title"}}',
          ),
      );
      

    Supported Redmine versions

    We support (and run tests against) the latest supported Redmine versions that receive security updates.

    php-redmine-api7.06.16.05.15.04.2
    v2.10✅✅✅✅❌❌
    v2.9❌✅✅✅❌❌
    v2.8❌❌✅✅✅❌
    v2.7❌❌❌✅✅✅

    Nevertheless, you can also use this library for all older Redmine versions. In this case, however, be aware that some features might not be supported by your Redmine server.

    If a new Redmine version enables new features that are not yet supported with this library, you are welcome to create an issue.

    Requirements

    • PHP ^8.2
    • The PHP SimpleXML extension
    • The PHP JSON extension
    • Enabled REST web service on your Redmine server
      • Go to Administration -> Settings -> Api (/settings/edit?tab=api) and check the "Enable REST web service" box
      • Obtain your API access key in your profile page: /my/account
      • (or use your username & password; not recommended)

    Optional

    • The PHP cURL extension if you want to use the native cURL functions.
    • PHPUnit >= 11.5 (optional) to run the test suite

    Todo

    • Tracking of Redmine API feature support in #305

    Limitations / Missing Redmine-API

    Redmine is missing some APIs for a full remote management of the data:

    Install

    By using Composer you can simply run:

    $ php composer.phar require kbsali/redmine-api
    

    at the root of your projects. To utilize the library, include Composer's vendor/autoload.php in the scripts that will use the Redmine classes.

    For example,

    <?php
    // This file is generated by Composer
    require_once 'vendor/autoload.php';
    
    $client = new \Redmine\Client\NativeCurlClient('https://redmine.example.com', '0ef19567656532f8dd43a4dbfeda787f01f3e659');
    

    For a manual installation please follow this instruction.

    Running the test suite

    You can run test suite to make sure the library will work properly on your system. Simply run vendor/bin/phpunit in the project's directory :

    $ vendor/bin/phpunit
    PHPUnit 11.5.57 by Sebastian Bergmann and contributors.
    
    Runtime:       PHP 8.2.35
    Configuration: /path/to/php-redmine-api/phpunit.dist.xml
    
    .............................................................   61 / 1390 (  4%)
    .............................................................  122 / 1390 (  8%)
    .............................................................  183 / 1390 ( 13%)
    .............................................................  244 / 1390 ( 17%)
    .............................................................  305 / 1390 ( 21%)
    .............................................................  366 / 1390 ( 26%)
    .............................................................  427 / 1390 ( 30%)
    .............................................................  488 / 1390 ( 35%)
    .............................................................  549 / 1390 ( 39%)
    .............................................................  610 / 1390 ( 43%)
    .............................................................  671 / 1390 ( 48%)
    .............................................................  732 / 1390 ( 52%)
    .............................................................  793 / 1390 ( 57%)
    .............................................................  854 / 1390 ( 61%)
    .............................................................  915 / 1390 ( 65%)
    .............................................................  976 / 1390 ( 70%)
    ............................................................. 1037 / 1390 ( 74%)
    ............................................................. 1098 / 1390 ( 78%)
    ............................................................. 1159 / 1390 ( 83%)
    ............................................................. 1220 / 1390 ( 87%)
    ............................................................. 1281 / 1390 ( 92%)
    ............................................................. 1342 / 1390 ( 96%)
    ................................................              1390 / 1390 (100%)
    
    Time: 00:01.134, Memory: 26.00 MB
    
    OK (1390 tests, 6610 assertions)
    

    Basic usage of php-redmine-api client

    Start your project

    Create your project e.g. in the index.php by require the vendor/autoload.php file.

    +<?php
    +
    +require_once 'vendor/autoload.php';
    

    Instantiate a Redmine Client

    You can choose between:

    1. a native curl client or
    2. the PSR-18 compatible client.
    1. Native curl Client Redmine\Client\NativeCurlClient

    :bulb: This client was introduced in php-redmine-api v1.8.0. If you are using the old Redmine\Client please see this migration guide for help to upgrade your code.

    You will need a URL to your Redmine instance and either a valid Apikey...

    <?php
    
    require_once 'vendor/autoload.php';
    +
    +// Instantiate with ApiKey
    +$client = new \Redmine\Client\NativeCurlClient('https://redmine.example.com', '1234567890abcdfgh');
    

    ... or valid username/password.

    <?php
    
    require_once 'vendor/autoload.php';
    +
    +// Instantiate with Username/Password (not recommended)
    +$client = new \Redmine\Client\NativeCurlClient('https://redmine.example.com', 'username', 'password');
    

    :bulb: For security reason it is recommended that you use an ApiKey rather than your username/password.

    cURL configuration

    After you instantiate a client you can set some optional cURL settings.

    <?php
    
    require_once 'vendor/autoload.php';
    
    // Instantiate with ApiKey
    $client = new Redmine\Client\NativeCurlClient('https://redmine.example.com', '1234567890abcdfgh');
    +
    +// [OPTIONAL] if you want to check the servers' SSL certificate on Curl call
    +$client->setCurlOption(CURLOPT_SSL_VERIFYPEER, true);
    +
    +// [OPTIONAL] set the port (it will try to guess it from the url)
    +$client->setCurlOption(CURLOPT_PORT, 8080);
    +
    +// [OPTIONAL] set a custom host
    +$client->setCurlOption(CURLOPT_HTTPHEADER, ['Host: https://custom.example.com']);
    
    
    2. Psr-18 compatible Client Redmine\Client\Psr18Client

    :bulb: This client was introduced in v1.7.0 of this library. If you are using the old Redmine\Client please follow this migration guide.

    The Psr18Client requires

    • a Psr\Http\Client\ClientInterface implementation (like guzzlehttp/guzzle), see
    • a Psr\Http\Message\RequestFactoryInterface implementation (like guzzlehttp/psr7), see
    • a Psr\Http\Message\StreamFactoryInterface implementation (like guzzlehttp/psr7), see
    • a URL to your Redmine instance
    • an Apikey or username
    • and optional a password if you want tu use username/password.

    :bulb: For security reason it is recommended that you use an ApiKey rather than your username/password.

    <?php
    
    require_once 'vendor/autoload.php';
    +
    +$guzzle = new \GuzzleHttp\Client();
    +$psr17Factory = new \GuzzleHttp\Psr7\HttpFactory();
    +
    +// Instantiate with ApiKey
    +$client = new \Redmine\Client\Psr18Client(
    +    $guzzle,
    +    $psr17Factory,
    +    $psr17Factory,
    +    'https://redmine.example.com',
    +    '1234567890abcdfgh'
    +);
    +// ...or Instantiate with Username/Password (not recommended)
    +$client = new \Redmine\Client\Psr18Client(
    +    $guzzle,
    +    $psr17Factory,
    +    $psr17Factory,
    +    'https://redmine.example.com',
    +    'username',
    +    'password'
    +);
    
    Guzzle configuration

    Because the Psr18Client is agnostic about the HTTP client implementation every configuration specific to the transport has to be set to the Psr\Http\Client\ClientInterface implementation.

    This means that if you want to set any cURL settings to Guzzle you have multiple ways to set them:

    1. Using Guzzle environment variables
    2. Using request options inside a Psr\Http\Client\ClientInterface wrapper:
    <?php
    
    require_once 'vendor/autoload.php';
    
    +use Psr\Http\Client\ClientInterface;
    +use Psr\Http\Message\RequestInterface;
    +use Psr\Http\Message\ResponseInterface;
    +
    $guzzle = \GuzzleHttp\Client();
    $psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
    
    +$guzzleWrapper = new class(\GuzzleHttp\Client $guzzle) implements ClientInterface
    +{
    +    private $guzzle;
    +
    +    public function __construct(\GuzzleHttp\Client $guzzle)
    +    {
    +        $this->guzzle = $guzzle;
    +    }
    +
    +    public function sendRequest(RequestInterface $request): ResponseInterface
    +    {
    +        return $this->guzzle->send($request, [
    +            // Set the options for every request here
    +            'auth' => ['username', 'password', 'digest'],
    +            'cert' => ['/path/server.pem', 'password'],
    +            'connect_timeout' => 3.14,
    +            // Set specific CURL options, see https://docs.guzzlephp.org/en/stable/faq.html#how-can-i-add-custom-curl-options
    +            'curl' => [
    +                CURLOPT_SSL_VERIFYPEER => 1,
    +                CURLOPT_SSL_VERIFYHOST => 2,
    +                CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2,
    +            ],
    +        ]);
    +    }
    +};
    +
    // Instantiate with ApiKey
    $client = new \Redmine\Client\Psr18Client(
    -    $guzzle,
    +    $guzzleWrapper,
        $psr17Factory,
        $psr17Factory,
        'https://redmine.example.com',
        '1234567890abcdfgh'
    );
    

    Built-in Redmine features

    Impersonate User

    Redmine allows you to impersonate another user. This can be done using the methods startImpersonateUser() and stopImpersonateUser().

    $client->startImpersonateUser('kim');
    // all requests will now impersonate the user `kim`
    
    // To stop impersonation
    $client->stopImpersonateUser();
    

    API usage

    You can now use the getApi() method to create and get a specific Redmine API.

    <?php
    
    $client->getApi('user')->list();
    $client->getApi('user')->listLogins();
    
    $client->getApi('issue')->create([
        'project_id'  => 'test',
        'subject'     => 'some subject',
        'description' => 'a long description blablabla',
        'assigned_to_id' => 123, // or 'assigned_to' => 'user1' OR 'groupXX'
    ]);
    $client->getApi('issue')->list([
        'limit' => 1000
    ]);
    

    See further examples and read more about usage in the docs.

    Thanks!