Skip to content

Commit c5f19cd

Browse files
authored
Merge pull request #262 from Art4/add-nativecurlclient
Add new NativeCurlClient
2 parents 8574a92 + 2d40ecb commit c5f19cd

20 files changed

+1709
-155
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- New native cURL client `Redmine\Client\NativeCurlClient` as a replacement for `Redmine\Client`
1213
- This `CHANGELOG.md` file
1314

1415
### Changed

README.md

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,59 @@ Uses [Redmine API](http://www.redmine.org/projects/redmine/wiki/Rest_api/).
77
## Features
88

99
* Follows PSR-4 conventions and coding standard: autoload friendly
10-
* API entry points implementation state :
11-
* OK Attachments
12-
* OK Groups
13-
* OK Custom Fields
14-
* OK Issues
15-
* OK Issue Categories
16-
* OK Issue Priorities
17-
* *NOK Issue Relations - only partially implemented*
18-
* OK Issue Statuses
19-
* OK News
20-
* OK Projects
21-
* OK Project Memberships
22-
* OK Queries
23-
* OK Roles
24-
* OK Time Entries
25-
* OK Time Entry Activities
26-
* OK Trackers
27-
* OK Users
28-
* OK Versions
29-
* OK Wiki
10+
* Choose between using native `cURL` function or any
11+
[PSR-18](https://www.php-fig.org/psr/psr-18/) http client like
12+
[Guzzle](https://github.com/guzzle/guzzle) for handling http connections
13+
* API entry points implementation state:
14+
* OK Attachments
15+
* OK Groups
16+
* OK Custom Fields
17+
* OK Issues
18+
* OK Issue Categories
19+
* OK Issue Priorities
20+
* *NOK Issue Relations - only partially implemented*
21+
* OK Issue Statuses
22+
* OK News
23+
* OK Projects
24+
* OK Project Memberships
25+
* OK Queries
26+
* OK Roles
27+
* OK Time Entries
28+
* OK Time Entry Activities
29+
* OK Trackers
30+
* OK Users
31+
* OK Versions
32+
* OK Wiki
3033

3134
## Todo
3235

3336
* Check header's response code (especially for POST/PUT/DELETE requests)
3437
* See http://stackoverflow.com/questions/9183178/php-curl-retrieving-response-headers-and-body-in-a-single-request/9183272#9183272
35-
* Maybe Guzzle for handling http connections
36-
* https://github.com/guzzle/guzzle
3738

38-
## Limitations
39+
## Limitations / Missing Redmine-API
3940

40-
Redmine is missing some APIs for a full remote management of the data :
41-
* List of activities & roles : http://www.redmine.org/issues/11464
42-
* ...
41+
Redmine is missing some APIs for a full remote management of the data:
42+
* List of activities & roles: http://www.redmine.org/issues/11464
43+
* Closing a project: https://www.redmine.org/issues/13725
4344

44-
A possible solution to this would be to create an extra APIs implementing the missing entry points. See existing effort in doing so : https://github.com/rschobbert/redmine-miss-api
45+
A possible solution to this would be to create an extra APIs implementing the
46+
missing entry points. See existing effort in doing so:
47+
https://github.com/rschobbert/redmine-miss-api
4548

4649
## Requirements
4750

4851
* PHP ^7.4 || ^8.0
49-
* The PHP [cURL](http://php.net/manual/en/book.curl.php) extension
5052
* The PHP [SimpleXML](http://php.net/manual/en/book.simplexml.php) extension
5153
* The PHP [JSON](http://php.net/manual/en/book.json.php) extension
52-
* [PHPUnit](https://phpunit.de/) >= 9.0 (optional) to run the test suite
5354
* "Enable REST web service" for your Redmine project (/settings/edit?tab=authentication)
5455
* then obtain your *API access key* in your profile page : /my/account
5556
* or use your *username & password* (not recommended)
5657

58+
### Optional
59+
60+
* The PHP [cURL](http://php.net/manual/en/book.curl.php) extension if you want to use the native `cURL` functions.
61+
* [PHPUnit](https://phpunit.de/) >= 9.0 (optional) to run the test suite
62+
5763
## Install
5864

5965
### Composer
@@ -75,7 +81,7 @@ For example,
7581
// This file is generated by Composer
7682
require_once 'vendor/autoload.php';
7783

78-
$client = new Redmine\Client('http://redmine.example.com', 'username', 'password');
84+
$client = new \Redmine\Client\NativeCurlClient('http://redmine.example.com', 'username', 'password');
7985
```
8086

8187
### Manual
@@ -100,7 +106,7 @@ example,
100106
// This file ships with php-redmine-api
101107
require 'vendor/php-redmine-api-1.6.0/vendor/autoload.php';
102108

103-
$client = new Redmine\Client('http://redmine.example.com', 'username', 'password');
109+
$client = new \Redmine\Client\NativeCurlClient('http://redmine.example.com', 'username', 'password');
104110
```
105111

106112
### Running the test suite
@@ -141,21 +147,26 @@ Create your project e.g. in the `index.php` by require the `vendor/autoload.php`
141147

142148
### Instantiate a Redmine Client
143149

144-
You can choose between the navite curl client or the PSR-18 compatible client.
150+
You can choose between:
151+
152+
1. a native curl client or
153+
2. the PSR-18 compatible client.
145154

146-
> :bulb: Since `php-redmine-api` v1.7.0 there is a new PSR-18 based client `Redmine\Client\Psr18Client`. [See this guide if you want to switch to this client.](docs/migrate-to-psr18client.md).
155+
#### 1. Native curl Client `Redmine\Client\NativeCurlClient`
147156

148-
#### Native curl Client `Redmine\Client`
157+
> :bulb: This client was introduced in `php-redmine-api` v1.8.0. If you are
158+
> using the old `Redmine\Client` please [see this migration guide for help to
159+
> upgrade your code](docs/migrate-to-nativecurlclient.md).
149160
150-
Every Client requires a URL to your Redmine instance and either a valid Apikey...
161+
You will need a URL to your Redmine instance and either a valid Apikey...
151162

152163
```diff
153164
<?php
154165

155166
require_once 'vendor/autoload.php';
156167
+
157168
+// Instantiate with ApiKey
158-
+$client = new Redmine\Client('http://localhost', '1234567890abcdfgh');
169+
+$client = new \Redmine\Client\NativeCurlClient('http://localhost', '1234567890abcdfgh');
159170
```
160171

161172
... or valid username/password.
@@ -167,7 +178,7 @@ require_once 'vendor/autoload.php';
167178
require_once 'vendor/autoload.php';
168179
+
169180
+// Instantiate with Username/Password (not recommended)
170-
+$client = new Redmine\Client('http://redmine.example.com', 'username', 'password');
181+
+$client = new \Redmine\Client\NativeCurlClient('http://redmine.example.com', 'username', 'password');
171182
```
172183

173184
> :bulb: For security reason it is recommended that you use an ApiKey rather than your username/password.
@@ -192,7 +203,9 @@ $client = new Redmine\Client('https://redmine.example.com', '1234567890abcdfgh')
192203
+$client->setCustomHost('https://localhost:8080');
193204

194205
```
195-
#### Psr-18 compatible Client `Redmine\Client\Psr18Client`
206+
#### 2. Psr-18 compatible Client `Redmine\Client\Psr18Client`
207+
208+
> :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](docs/migrate-to-psr18client.md).
196209
197210
The `Psr18Client` requires
198211

@@ -214,9 +227,9 @@ require_once 'vendor/autoload.php';
214227
+$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
215228
+
216229
+// Instantiate with ApiKey
217-
+$client = new Redmine\Client\Prs18Client($guzzle, $psr17Factory, $psr17Factory, 'https://redmine.example.com', '1234567890abcdfgh');
230+
+$client = new \Redmine\Client\Prs18Client($guzzle, $psr17Factory, $psr17Factory, 'https://redmine.example.com', '1234567890abcdfgh');
218231
+// ...or Instantiate with Username/Password (not recommended)
219-
+$client = new Redmine\Client\Prs18Client($guzzle, $psr17Factory, $psr17Factory, 'https://redmine.example.com', 'username', 'password');
232+
+$client = new \Redmine\Client\Prs18Client($guzzle, $psr17Factory, $psr17Factory, 'https://redmine.example.com', 'username', 'password');
220233
```
221234

222235
##### Guzzle configuration
@@ -267,8 +280,8 @@ $psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
267280
+};
268281
+
269282
// Instantiate with ApiKey
270-
-$client = new Redmine\Client\Prs18Client($guzzle, $psr17Factory, $psr17Factory, 'https://redmine.example.com', '1234567890abcdfgh');
271-
+$client = new Redmine\Client\Prs18Client($guzzleWrapper, $psr17Factory, $psr17Factory, 'https://redmine.example.com', '1234567890abcdfgh');
283+
-$client = new \Redmine\Client\Prs18Client($guzzle, $psr17Factory, $psr17Factory, 'https://redmine.example.com', '1234567890abcdfgh');
284+
+$client = new \Redmine\Client\Prs18Client($guzzleWrapper, $psr17Factory, $psr17Factory, 'https://redmine.example.com', '1234567890abcdfgh');
272285

273286
```
274287

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"require-dev": {
2727
"friendsofphp/php-cs-fixer": "^2.0",
2828
"phpunit/phpunit": "^9.5",
29-
"guzzlehttp/psr7": "^1.7"
29+
"guzzlehttp/psr7": "^1.7",
30+
"php-mock/php-mock-phpunit": "^2.6"
3031
},
3132
"autoload": {
3233
"psr-4": {

0 commit comments

Comments
 (0)