@@ -35,18 +35,17 @@ class JiraClient {
35
35
/** @var Monolog instance */
36
36
protected $ log ;
37
37
38
- private $ options = array (
39
- // disable SSL Certification validation
40
- CURLOPT_SSL_VERIFYHOST => 0 ,
41
- // FALSE to stop CURL from verifying the peer's certificate.
42
- CURLOPT_SSL_VERIFYPEER => 0 ,
38
+ // disable SSL Certification validation
39
+ protected $ CURLOPT_SSL_VERIFYHOST = false ;
40
+ // FALSE to stop CURL from verifying the peer's certificate.
41
+ protected $ CURLOPT_SSL_VERIFYPEER = false ;
43
42
44
- CURLOPT_VERBOSE => true ,
45
-
46
- 'LOG_FILE ' => 'jira-rest-client.log ' ,
47
- 'LOG_LEVEL ' => Logger::INFO ,
48
- );
43
+ // debug curl
44
+ protected $ CURLOPT_VERBOSE = false ;
49
45
46
+ protected $ LOG_FILE = 'jira-rest-client.log ' ;
47
+ protected $ LOG_LEVEL = Logger::INFO ;
48
+
50
49
private function convertLogLevel ($ log_level ) {
51
50
if ($ log_level == 'DEBUG ' )
52
51
return Logger::DEBUG ;
@@ -58,7 +57,7 @@ private function convertLogLevel($log_level) {
58
57
return Logger::INFO ;
59
58
}
60
59
61
- public function __construct ($ config, $ options = null )
60
+ public function __construct ($ config )
62
61
{
63
62
$ this ->json_mapper = new \JsonMapper ();
64
63
$ this ->json_mapper ->bExceptionOnUndefinedProperty = true ;
@@ -67,25 +66,25 @@ public function __construct($config, $options = null)
67
66
$ this ->username = $ config ['username ' ];
68
67
$ this ->password = $ config ['password ' ];
69
68
70
- if (!is_null ($ options )) {
71
- //http://stackoverflow.com/questions/5929642/php-array-merge-with-numerical-keys
72
- // array_merge with numeric key
73
- $ this ->options = $ this ->options + $ options ;
74
- //$this->options = array_merge($this->options, $options);
69
+ if (isset ($ config ['CURLOPT_SSL_VERIFYHOST ' ]))
70
+ $ this ->CURLOPT_SSL_VERIFYHOST = $ config ['CURLOPT_SSL_VERIFYHOST ' ] === 'true ' ? true : false ;
71
+
72
+ if (isset ($ config ['CURLOPT_SSL_VERIFYPEER ' ]))
73
+ $ this ->CURLOPT_SSL_VERIFYPEER = $ config ['CURLOPT_SSL_VERIFYPEER ' ] === 'true ' ? true : false ;
74
+
75
+ if (isset ($ config ['CURLOPT_VERBOSE ' ]))
76
+ $ this ->CURLOPT_VERBOSE = $ config ['CURLOPT_VERBOSE ' ] === 'true ' ? true : false ;
75
77
76
- if (isset ($ options ['LOG_FILE ' ]))
77
- $ this ->options ['LOG_FILE ' ] = $ options ['LOG_FILE ' ];
78
- if (isset ($ options ['LOG_LEVEL ' ]))
79
- $ this ->options ['LOG_LEVEL ' ] = $ this ->convertLogLevel ($ options ['LOG_LEVEL ' ]);
80
- }
78
+ if (isset ($ config ['LOG_FILE ' ]))
79
+ $ this ->LOG_FILE = $ config ['LOG_FILE ' ];
81
80
82
- // create logger
83
- $ log_file = $ options ['LOG_FILE ' ];
84
- $ log_level = $ this ->convertLogLevel ($ options ['LOG_LEVEL ' ]);
81
+ if (isset ($ config ['LOG_LEVEL ' ]))
82
+ $ this ->LOG_LEVEL = $ this ->convertLogLevel ($ config ['LOG_LEVEL ' ]);
85
83
84
+ // create logger
86
85
$ this ->log = new Logger ('JiraClient ' );
87
- $ this ->log ->pushHandler (new StreamHandler ($ this ->options [ ' LOG_FILE ' ] ,
88
- $ this ->options [ ' LOG_LEVEL ' ] ));
86
+ $ this ->log ->pushHandler (new StreamHandler ($ this ->LOG_FILE ,
87
+ $ this ->LOG_LEVEL ));
89
88
90
89
$ this ->http_response = 200 ;
91
90
}
@@ -117,14 +116,14 @@ public function exec($context, $post_data = null, $custom_request = null) {
117
116
118
117
curl_setopt ($ ch , CURLOPT_USERPWD , "$ this ->username : $ this ->password " );
119
118
120
- curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , $ this ->options [ CURLOPT_SSL_VERIFYHOST ] );
121
- curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , $ this ->options [ CURLOPT_SSL_VERIFYPEER ] );
119
+ curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , $ this ->CURLOPT_SSL_VERIFYHOST );
120
+ curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , $ this ->CURLOPT_SSL_VERIFYPEER );
122
121
123
122
curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , true );
124
123
curl_setopt ($ ch , CURLOPT_HTTPHEADER ,
125
124
array ('Accept: */* ' , 'Content-Type: application/json ' ));
126
125
127
- curl_setopt ($ ch , CURLOPT_VERBOSE , $ this ->options [ CURLOPT_VERBOSE ] );
126
+ curl_setopt ($ ch , CURLOPT_VERBOSE , $ this ->CURLOPT_VERBOSE );
128
127
129
128
$ this ->log ->addDebug ('Curl exec= ' . $ url );
130
129
$ response = curl_exec ($ ch );
0 commit comments