@@ -9,6 +9,8 @@ class JIRAException extends \Exception { }
9
9
use \Monolog \Logger as Logger ;
10
10
use \Monolog \Handler \StreamHandler ;
11
11
12
+ use \Noodlehaus \Config as Config ;
13
+
12
14
/**
13
15
* interact jira server with REST API
14
16
*/
@@ -43,8 +45,8 @@ class JiraClient {
43
45
// debug curl
44
46
protected $ CURLOPT_VERBOSE = false ;
45
47
46
- protected $ LOG_FILE = ' jira-rest-client.log ' ;
47
- protected $ LOG_LEVEL = Logger:: INFO ;
48
+ protected $ LOG_FILE ;
49
+ protected $ LOG_LEVEL ;
48
50
49
51
private function convertLogLevel ($ log_level ) {
50
52
if ($ log_level == 'DEBUG ' )
@@ -75,29 +77,24 @@ protected function filterNullVariable($haystack)
75
77
return $ haystack ;
76
78
}
77
79
78
- public function __construct ($ config )
79
- {
80
+ public function __construct ()
81
+ {
82
+ $ config = Config::load ('config.jira.json ' );
83
+
80
84
$ this ->json_mapper = new \JsonMapper ();
81
85
$ this ->json_mapper ->bExceptionOnUndefinedProperty = true ;
82
86
83
87
$ this ->host = $ config ['host ' ];
84
88
$ this ->username = $ config ['username ' ];
85
89
$ this ->password = $ config ['password ' ];
86
90
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 );
92
92
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 ) ;
95
95
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 ));
101
98
102
99
// create logger
103
100
$ this ->log = new Logger ('JiraClient ' );
@@ -193,11 +190,11 @@ public function upload($context, $upload_file) {
193
190
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
194
191
curl_setopt ($ ch , CURLOPT_URL , $ url );
195
192
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));
200
196
*/
197
+
201
198
$ attachments = realpath ($ upload_file );
202
199
$ filename = basename ($ upload_file );
203
200
0 commit comments