@@ -54,13 +54,6 @@ class JiraClient
54
54
*/
55
55
protected $ configuration ;
56
56
57
- /**
58
- * cookie file name.
59
- *
60
- * @var string
61
- */
62
- protected $ cookie = 'jira-cookies.txt ' ;
63
-
64
57
/**
65
58
* Constructor.
66
59
*
@@ -164,12 +157,13 @@ protected function filterNullVariable($haystack)
164
157
* @param string $context Rest API context (ex.:issue, search, etc..)
165
158
* @param string $post_data
166
159
* @param string $custom_request [PUT|DELETE]
160
+ * @param string $cookieFile cookie file
167
161
*
168
162
* @throws JiraException
169
163
*
170
164
* @return string
171
165
*/
172
- public function exec ($ context , $ post_data = null , $ custom_request = null )
166
+ public function exec ($ context , $ post_data = null , $ custom_request = null , $ cookieFile = null )
173
167
{
174
168
$ url = $ this ->createUrlByContext ($ context );
175
169
@@ -198,7 +192,7 @@ public function exec($context, $post_data = null, $custom_request = null)
198
192
}
199
193
}
200
194
201
- $ this ->authorization ($ ch );
195
+ $ this ->authorization ($ ch, $ cookieFile );
202
196
203
197
curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , $ this ->getConfiguration ()->isCurlOptSslVerifyHost ());
204
198
curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , $ this ->getConfiguration ()->isCurlOptSslVerifyPeer ());
@@ -434,18 +428,22 @@ protected function createUrlByContext($context)
434
428
*
435
429
* @param resource $ch
436
430
*/
437
- protected function authorization ($ ch )
431
+ protected function authorization ($ ch, $ cookieFile = null )
438
432
{
439
433
// use cookie
440
434
if ($ this ->getConfiguration ()->isCookieAuthorizationEnabled ()) {
441
- curl_setopt ($ ch , CURLOPT_COOKIEJAR , $ this ->cookie );
442
- curl_setopt ($ ch , CURLOPT_COOKIEFILE , $ this ->cookie );
435
+ if ($ cookieFile === null ){
436
+ $ cookieFile = $ this ->getConfiguration ()->getCookieFile ();
437
+ }
438
+
439
+ curl_setopt ($ ch , CURLOPT_COOKIEJAR , $ cookieFile );
440
+ curl_setopt ($ ch , CURLOPT_COOKIEFILE , $ cookieFile );
443
441
444
442
$ this ->log ->addDebug ('Using cookie.. ' );
445
443
}
446
444
447
445
// if cookie file not exist, using id/pwd login
448
- if (!file_exists ($ this -> cookie )) {
446
+ if (!file_exists ($ cookieFile )) {
449
447
$ username = $ this ->getConfiguration ()->getJiraUser ();
450
448
$ password = $ this ->getConfiguration ()->getJiraPassword ();
451
449
curl_setopt ($ ch , CURLOPT_USERPWD , "$ username: $ password " );
@@ -505,12 +503,13 @@ public function toHttpQueryParameter($paramArray)
505
503
* @param $url full url
506
504
* @param $outDir save dir
507
505
* @param $file save filename
506
+ * @param $cookieFile cookie filename
508
507
*
509
508
* @throws JiraException
510
509
*
511
510
* @return bool|mixed
512
511
*/
513
- public function download ($ url , $ outDir , $ file )
512
+ public function download ($ url , $ outDir , $ file, $ cookieFile = null )
514
513
{
515
514
$ file = fopen ($ outDir .DIRECTORY_SEPARATOR .$ file , 'w ' );
516
515
@@ -521,7 +520,7 @@ public function download($url, $outDir, $file)
521
520
// output to file handle
522
521
curl_setopt ($ ch , CURLOPT_FILE , $ file );
523
522
524
- $ this ->authorization ($ ch );
523
+ $ this ->authorization ($ ch, $ cookieFile );
525
524
526
525
curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , $ this ->getConfiguration ()->isCurlOptSslVerifyHost ());
527
526
curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , $ this ->getConfiguration ()->isCurlOptSslVerifyPeer ());
@@ -577,4 +576,17 @@ public function download($url, $outDir, $file)
577
576
578
577
return $ response ;
579
578
}
579
+
580
+ /**
581
+ * setting cookie file path.
582
+ *
583
+ * @param $cookieFile
584
+ * @return $this
585
+ */
586
+ public function setCookieFile ($ cookieFile )
587
+ {
588
+ $ this ->cookieFile = $ cookieFile ;
589
+
590
+ return $ this ;
591
+ }
580
592
}
0 commit comments