@@ -54,13 +54,6 @@ class JiraClient
5454 */
5555 protected $ configuration ;
5656
57- /**
58- * cookie file name.
59- *
60- * @var string
61- */
62- protected $ cookie = 'jira-cookies.txt ' ;
63-
6457 /**
6558 * Constructor.
6659 *
@@ -164,12 +157,13 @@ protected function filterNullVariable($haystack)
164157 * @param string $context Rest API context (ex.:issue, search, etc..)
165158 * @param string $post_data
166159 * @param string $custom_request [PUT|DELETE]
160+ * @param string $cookieFile cookie file
167161 *
168162 * @throws JiraException
169163 *
170164 * @return string
171165 */
172- public function exec ($ context , $ post_data = null , $ custom_request = null )
166+ public function exec ($ context , $ post_data = null , $ custom_request = null , $ cookieFile = null )
173167 {
174168 $ url = $ this ->createUrlByContext ($ context );
175169
@@ -198,7 +192,7 @@ public function exec($context, $post_data = null, $custom_request = null)
198192 }
199193 }
200194
201- $ this ->authorization ($ ch );
195+ $ this ->authorization ($ ch, $ cookieFile );
202196
203197 curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , $ this ->getConfiguration ()->isCurlOptSslVerifyHost ());
204198 curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , $ this ->getConfiguration ()->isCurlOptSslVerifyPeer ());
@@ -434,18 +428,22 @@ protected function createUrlByContext($context)
434428 *
435429 * @param resource $ch
436430 */
437- protected function authorization ($ ch )
431+ protected function authorization ($ ch, $ cookieFile = null )
438432 {
439433 // use cookie
440434 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 );
443441
444442 $ this ->log ->addDebug ('Using cookie.. ' );
445443 }
446444
447445 // if cookie file not exist, using id/pwd login
448- if (!file_exists ($ this -> cookie )) {
446+ if (!file_exists ($ cookieFile )) {
449447 $ username = $ this ->getConfiguration ()->getJiraUser ();
450448 $ password = $ this ->getConfiguration ()->getJiraPassword ();
451449 curl_setopt ($ ch , CURLOPT_USERPWD , "$ username: $ password " );
@@ -505,12 +503,13 @@ public function toHttpQueryParameter($paramArray)
505503 * @param $url full url
506504 * @param $outDir save dir
507505 * @param $file save filename
506+ * @param $cookieFile cookie filename
508507 *
509508 * @throws JiraException
510509 *
511510 * @return bool|mixed
512511 */
513- public function download ($ url , $ outDir , $ file )
512+ public function download ($ url , $ outDir , $ file, $ cookieFile = null )
514513 {
515514 $ file = fopen ($ outDir .DIRECTORY_SEPARATOR .$ file , 'w ' );
516515
@@ -521,7 +520,7 @@ public function download($url, $outDir, $file)
521520 // output to file handle
522521 curl_setopt ($ ch , CURLOPT_FILE , $ file );
523522
524- $ this ->authorization ($ ch );
523+ $ this ->authorization ($ ch, $ cookieFile );
525524
526525 curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , $ this ->getConfiguration ()->isCurlOptSslVerifyHost ());
527526 curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , $ this ->getConfiguration ()->isCurlOptSslVerifyPeer ());
@@ -577,4 +576,17 @@ public function download($url, $outDir, $file)
577576
578577 return $ response ;
579578 }
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+ }
580592}
0 commit comments