Skip to content

Commit afff2c8

Browse files
committed
Merge pull request #96 from orlitzky/master
Add autoloader to allow manual installation and update documentation
2 parents 159689e + 4f0a6bc commit afff2c8

File tree

4 files changed

+131
-47
lines changed

4 files changed

+131
-47
lines changed

README.markdown

+99-28
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@ Uses [Redmine API](http://www.redmine.org/projects/redmine/wiki/Rest_api/).
88

99
* Follows PSR-0 conventions and coding standard: autoload friendly
1010
* 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
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
3030

3131
## Todo
3232

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

3838
## Limitations
3939

@@ -45,27 +45,98 @@ A possible solution to this would be to create an extra APIs implementing the mi
4545

4646
## Requirements
4747

48-
* PHP >= 5.3.2 with [cURL](http://php.net/manual/en/book.curl.php) extension,
48+
* PHP >= 5.4
49+
* The PHP [cURL](http://php.net/manual/en/book.curl.php) extension
50+
* The PHP [SimpleXML](http://php.net/manual/en/book.simplexml.php) extension
51+
* The PHP [JSON](http://php.net/manual/en/book.json.php) extension
52+
* [PHPUnit](https://phpunit.de/) >= 4.0 (optional) to run the test suite
4953
* "Enable REST web service" for your Redmine project (/settings/edit?tab=authentication)
50-
* then obtain your *API access key* in your profile page : /my/account
51-
* or use your *username & password*
54+
* then obtain your *API access key* in your profile page : /my/account
55+
* or use your *username & password*
5256

5357
## Install
5458

55-
Through [composer](http://getcomposer.org/download/), simply run :
59+
### Composer
60+
61+
[Composer](http://getcomposer.org/download/) users can simply run:
5662

5763
```bash
5864
$ php composer.phar require kbsali/redmine-api:~1.0
5965
```
6066

67+
at the root of their projects. To utilize the library, include
68+
Composer's `vendor/autoload.php` in the scripts that will use the
69+
`Redmine` classes.
70+
71+
For example,
72+
73+
```php
74+
<?php
75+
// This file is generated by Composer
76+
require_once 'vendor/autoload.php';
77+
$client = new Redmine\Client('http://redmine.example.com', 'username', 'password');
78+
```
79+
80+
### Manual
81+
82+
It is also possible to install the library oneself, either locally to
83+
a project or globally; say, in `/usr/share/php`.
84+
85+
First, download and extract the library somewhere. For example, the
86+
following steps extract v1.5.1 of the library into the
87+
`vendor/php-redmine-api-1.5.1` directory:
88+
89+
```bash
90+
$ mkdir vendor
91+
$ wget -q https://github.com/kbsali/php-redmine-api/archive/v1.5.1.tar.gz
92+
$ tar -xf v1.5.1.tar.gz -C vendor/
93+
$ rm v1.5.1.tar.gz
94+
```
95+
96+
Now, in any scripts that will use the `Redmine` classes, include the
97+
`lib/autoload.php` file from the php-redmine-api directory. For
98+
example,
99+
100+
```php
101+
<?php
102+
// This file ships with php-redmine-api
103+
require 'vendor/php-redmine-api-1.5.1/lib/autoload.php';
104+
$client = new Redmine\Client('http://redmine.example.com', 'username', 'password');
105+
```
106+
107+
### Running the test suite
108+
109+
If you have [PHPUnit](https://phpunit.de/) >= 4.0 installed, you can
110+
run the test suite to make sure that the library will function
111+
properly on your system. Simply run `phpunit` in the php-redmine-api
112+
directory. For example,
113+
114+
```
115+
$ phpunit
116+
PHPUnit 4.3.1 by Sebastian Bergmann.
117+
118+
Configuration read from ./phpunit.xml.dist
119+
120+
............................................................... 63 / 276 ( 22%)
121+
............................................................... 126 / 276 ( 45%)
122+
............................................................... 189 / 276 ( 68%)
123+
............................................................... 252 / 276 ( 91%)
124+
........................
125+
126+
Time: 591 ms, Memory: 10.50Mb
127+
```
128+
61129
## Basic usage of `php-redmine-api` client
62130

63131
```php
64132
<?php
65133

66-
// This file is generated by Composer
134+
// For Composer users (this file is generated by Composer)
67135
require_once 'vendor/autoload.php';
68136

137+
// Or if you've installed the library manually, use this instead.
138+
// require 'vendor/php-redmine-api-x.y.z/lib/autoload.php';
139+
69140
$client = new Redmine\Client('http://redmine.example.com', 'API_ACCESS_KEY');
70141
//-- OR --
71142
$client = new Redmine\Client('http://redmine.example.com', 'username', 'password');
@@ -84,7 +155,7 @@ $client->api('issue')->all([
84155
]);
85156
```
86157

87-
see `example.php`
158+
See `example.php` for further examples.
88159

89160
## User Impersonation
90161

@@ -110,4 +181,4 @@ $client->setImpersonateUser(null);
110181
* Thanks to [Thomas Spycher](https://github.com/tspycher/) for the 1st version of the class.
111182
* Thanks to [Thibault Duplessis aka. ornicar](https://github.com/ornicar) for the php-github-api library, great source of inspiration!
112183
* And all the [contributors](https://github.com/kbsali/php-redmine-api/graphs/contributors)
113-
* specially [JanMalte](https://github.com/JanMalte) for his impressive contribution to the test coverage! :)
184+
* specially [JanMalte](https://github.com/JanMalte) for his impressive contribution to the test coverage! :)

lib/autoload.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/* An autoloader for Redmine\Foo classes. This should be require()d by
4+
* the user before attempting to instantiate any of the Redmine
5+
* classes.
6+
*/
7+
8+
spl_autoload_register(function ($class) {
9+
/* All of the classes have names like "Redmine\Foo", so we need to
10+
* replace the backslashes with frontslashes if we want the name
11+
* to map directly to a location in the filesystem.
12+
*/
13+
$class = str_replace('\\', '/', $class);
14+
15+
/* First, check under the current directory. It is important that
16+
* we look here first, so that we don't waste time searching for
17+
* test classes in the common case.
18+
*/
19+
$path = dirname(__FILE__).'/'.$class.'.php';
20+
if (file_exists($path)) {
21+
require_once($path);
22+
}
23+
24+
/* If we didn't find what we're looking for already, maybe it's
25+
* a test class?
26+
*/
27+
$path = dirname(__FILE__).'/../test/'.$class.'.php';
28+
if (file_exists($path)) {
29+
require_once($path);
30+
}
31+
});

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
processIsolation="false"
1010
stopOnFailure="false"
1111
syntaxCheck="false"
12-
bootstrap="test/bootstrap.php"
12+
bootstrap="lib/autoload.php"
1313
>
1414
<testsuites>
1515
<testsuite name="php-redmine-api Test Suite">

test/bootstrap.php

-18
This file was deleted.

0 commit comments

Comments
 (0)