Skip to content

Commit dcd280f

Browse files
committed
change configuration to json file.
1 parent a8b6a6d commit dcd280f

11 files changed

+46
-82
lines changed

README.md

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,18 @@
55
composer require lesstif/php-jira-rest-client dev-master
66
```
77

8-
create config.jira.php file on your project root.
9-
````php
10-
<?php
11-
12-
function getConfig() {
13-
return array(
14-
// JIRA Host config
15-
'host' => 'https://jira.example.com',
16-
'username' => 'username',
17-
'password' => 'password',
18-
19-
// Options
20-
'CURLOPT_SSL_VERIFYHOST' => false,
21-
'CURLOPT_SSL_VERIFYPEER' => false,
22-
'CURLOPT_VERBOSE' => true,
23-
'LOG_FILE' => 'jira-rest-client.log',
24-
'LOG_LEVEL' => 'DEBUG'
25-
);
8+
create config.jira.json file on your project root.
9+
````json
10+
{
11+
"host": "https://jira.example.com",
12+
"username": "username",
13+
"password": "password",
14+
"CURLOPT_SSL_VERIFYHOST": false,
15+
"CURLOPT_SSL_VERIFYPEER": false,
16+
"CURLOPT_VERBOSE": false,
17+
"LOG_FILE": "jira-rest-client.log",
18+
"LOG_LEVEL": "DEBUG"
2619
}
27-
2820
?>
2921
````
3022

@@ -35,7 +27,6 @@ function getConfig() {
3527
````php
3628
<?php
3729
require 'vendor/autoload.php';
38-
require_once 'config.jira.php';
3930

4031
use JiraRestApi\Project\ProjectService;
4132

@@ -55,7 +46,6 @@ try {
5546
````php
5647
<?php
5748
require 'vendor/autoload.php';
58-
require_once 'config.jira.php';
5949

6050
use JiraRestApi\Project\ProjectService;
6151

@@ -81,7 +71,6 @@ try {
8171
````php
8272
<?php
8373
require 'vendor/autoload.php';
84-
require_once 'config.jira.php';
8574

8675
use JiraRestApi\Issue\IssueService;
8776
try {
@@ -102,7 +91,6 @@ try {
10291
````php
10392
<?php
10493
require 'vendor/autoload.php';
105-
require_once 'config.jira.php';
10694

10795
use JiraRestApi\Issue\IssueService;
10896
use JiraRestApi\Issue\IssueField;
@@ -135,7 +123,6 @@ try {
135123
````php
136124
<?php
137125
require 'vendor/autoload.php';
138-
require_once 'config.jira.php';
139126

140127
use JiraRestApi\Issue\IssueService;
141128
use JiraRestApi\Issue\IssueField;
@@ -157,7 +144,6 @@ try {
157144
````php
158145
<?php
159146
require 'vendor/autoload.php';
160-
require_once 'config.jira.php';
161147

162148
use JiraRestApi\Issue\IssueService;
163149
use JiraRestApi\Issue\IssueField;

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"require": {
77
"php": ">=5.4.0",
88
"netresearch/jsonmapper": "0.4.*",
9-
"monolog/monolog": "~1.12"
9+
"monolog/monolog": "~1.12",
10+
"noodlehaus/config": "0.7.*"
1011
},
1112
"require-dev": {
1213
"phpunit/phpunit": "~4.4"

phpunit.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
<phpunit bootstrap="tests/bootstrap.php" colors="true">
44
<testsuites>
55
<testsuite name="Jira Rest API Test Suite">
6-
<!--
76
<directory>tests/</directory>
8-
-->
9-
<file>tests/ProjectTest.php</file>
10-
<file>tests/IssueTest.php</file>
117
</testsuite>
128
</testsuites>
139

src/JiraClient.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class JIRAException extends \Exception { }
99
use \Monolog\Logger as Logger;
1010
use \Monolog\Handler\StreamHandler;
1111

12+
use \Noodlehaus\Config as Config;
13+
1214
/**
1315
* interact jira server with REST API
1416
*/
@@ -43,8 +45,8 @@ class JiraClient {
4345
// debug curl
4446
protected $CURLOPT_VERBOSE = false;
4547

46-
protected $LOG_FILE = 'jira-rest-client.log';
47-
protected $LOG_LEVEL = Logger::INFO;
48+
protected $LOG_FILE;
49+
protected $LOG_LEVEL;
4850

4951
private function convertLogLevel($log_level) {
5052
if ($log_level == 'DEBUG')
@@ -75,29 +77,24 @@ protected function filterNullVariable($haystack)
7577
return $haystack;
7678
}
7779

78-
public function __construct($config)
79-
{
80+
public function __construct()
81+
{
82+
$config = Config::load('config.jira.json');
83+
8084
$this->json_mapper = new \JsonMapper();
8185
$this->json_mapper->bExceptionOnUndefinedProperty = true;
8286

8387
$this->host = $config['host'];
8488
$this->username = $config['username'];
8589
$this->password = $config['password'];
8690

87-
if (isset($config['CURLOPT_SSL_VERIFYHOST']))
88-
$this->CURLOPT_SSL_VERIFYHOST = $config['CURLOPT_SSL_VERIFYHOST'] === true ? true: false;
89-
90-
if (isset($config['CURLOPT_SSL_VERIFYPEER']))
91-
$this->CURLOPT_SSL_VERIFYPEER = $config['CURLOPT_SSL_VERIFYPEER'] === true ? true: false;
91+
$this->CURLOPT_SSL_VERIFYHOST = $config->get('CURLOPT_SSL_VERIFYHOST', false);
9292

93-
if (isset($config['CURLOPT_VERBOSE']))
94-
$this->CURLOPT_VERBOSE = $config['CURLOPT_VERBOSE'] === true ? true: false;
93+
$this->CURLOPT_SSL_VERIFYPEER = $config->get('CURLOPT_SSL_VERIFYPEER', false);
94+
$this->CURLOPT_VERBOSE = $config->get('CURLOPT_VERBOSE', false);
9595

96-
if (isset($config['LOG_FILE']))
97-
$this->LOG_FILE = $config['LOG_FILE'];
98-
99-
if (isset($config['LOG_LEVEL']))
100-
$this->LOG_LEVEL = $this->convertLogLevel($config['LOG_LEVEL']);
96+
$this->LOG_FILE = $config->get('LOG_FILE', 'jira-rest-client.log');
97+
$this->LOG_LEVEL = $this->convertLogLevel($config->get('LOG_LEVEL', Logger::INFO));
10198

10299
// create logger
103100
$this->log = new Logger('JiraClient');
@@ -193,11 +190,11 @@ public function upload($context, $upload_file) {
193190
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
194191
curl_setopt($ch, CURLOPT_URL, $url);
195192

196-
/*
197-
$attachments = array(
198-
'file' => '@' . realpath($upload_file)
199-
);
193+
/* CURLFile support PHP 5.5
194+
$cf = new \CURLFile(realpath($upload_file), 'image/png', $upload_file);
195+
$this->log->addDebug('CURLFile=' . var_export($cf, true));
200196
*/
197+
201198
$attachments = realpath($upload_file);
202199
$filename = basename($upload_file);
203200

src/config.jira.example.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"host": "https://jira.example.com",
3+
"username": "username",
4+
"password": "password",
5+
"CURLOPT_SSL_VERIFYHOST": false,
6+
"CURLOPT_SSL_VERIFYPEER": false,
7+
"CURLOPT_VERBOSE": false,
8+
"LOG_FILE": "jira-rest-client.log",
9+
"LOG_LEVEL": "DEBUG"
10+
}

src/config.jira.example.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/issue/IssueService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class IssueService extends \JiraRestApi\JiraClient {
66
private $uri = "/issue";
77

88
public function __construct() {
9-
parent::__construct(getConfig());
9+
parent::__construct();
1010
}
1111

1212
/**

src/project/ProjectService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ProjectService extends \JiraRestApi\JiraClient {
66
private $uri = "/project";
77

88
public function __construct() {
9-
parent::__construct(getConfig());
9+
parent::__construct();
1010
}
1111

1212
/**

tests/IssueTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public function testIssue()
2828

2929
public function testCreateIssue()
3030
{
31-
$this->markTestIncomplete();
3231
try {
3332
$issueField = new IssueField();
3433

@@ -62,8 +61,7 @@ public function testCreateIssue()
6261
*
6362
*/
6463
public function testAddAttachment($issueKey)
65-
{
66-
$this->markTestIncomplete();
64+
{
6765
try {
6866

6967
$issueService = new IssueService();
@@ -79,13 +77,11 @@ public function testAddAttachment($issueKey)
7977
}
8078

8179
/**
82-
* depends testAddAttachment
80+
* @depends testAddAttachment
8381
*
8482
*/
85-
public function testUpdateIssue()
83+
public function testUpdateIssue($issueKey)
8684
{
87-
$issueKey = "TEST-920";
88-
8985
//$this->markTestIncomplete();
9086
try {
9187
$issueField = new IssueField(true);

tests/ProjectTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function testGetProjectLists()
2929

3030
$prjs = $proj->getAllProjects();
3131

32-
$i = 0;
3332
foreach ($prjs as $p) {
3433
echo sprintf("Project Key:%s, Id:%s, Name:%s, projectCategory: %s\n",
3534
$p->key, $p->id, $p->name, $p->projectCategory['name']

0 commit comments

Comments
 (0)