@@ -9,6 +9,8 @@ class JIRAException extends \Exception { }
99use \Monolog \Logger as Logger ;
1010use \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
0 commit comments