Skip to content

Commit b34cac2

Browse files
committed
Merge pull request #11 from Keanor/master
external configuration, framework compability
2 parents d097af7 + aa3e343 commit b34cac2

File tree

8 files changed

+400
-156
lines changed

8 files changed

+400
-156
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: keanor
5+
* Date: 17.08.15
6+
* Time: 22:23
7+
*/
8+
9+
namespace JiraRestApi\Configuration;
10+
11+
/**
12+
* Class AbstractConfiguration
13+
*
14+
* @package JiraRestApi\Configuration
15+
*/
16+
abstract class AbstractConfiguration implements ConfigurationInterface
17+
{
18+
/**
19+
* Jira host
20+
*
21+
* @var string
22+
*/
23+
protected $jiraHost;
24+
25+
/**
26+
* Jira login
27+
*
28+
* @var string
29+
*/
30+
protected $jiraUser;
31+
32+
/**
33+
* Jira password
34+
*
35+
* @var string
36+
*/
37+
protected $jiraPassword;
38+
39+
/**
40+
* Path to log file
41+
*
42+
* @var string
43+
*/
44+
protected $jiraLogFile;
45+
46+
/**
47+
* Log level (DEBUG, INFO, ERROR, WARNING)
48+
*
49+
* @var string
50+
*/
51+
protected $jiraLogLevel;
52+
53+
/**
54+
* Curl options CURLOPT_SSL_VERIFYHOST
55+
*
56+
* @var boolean
57+
*/
58+
protected $curlOptSslVerifyHost;
59+
60+
/**
61+
* Curl options CURLOPT_SSL_VERIFYPEER
62+
*
63+
* @var boolean
64+
*/
65+
protected $curlOptSslVerifyPeer;
66+
67+
/**
68+
* Curl options CURLOPT_VERBOSE
69+
*
70+
* @var boolean
71+
*/
72+
protected $curlOptVerbose;
73+
74+
/**
75+
* @return string
76+
*/
77+
public function getJiraHost()
78+
{
79+
return $this->jiraHost;
80+
}
81+
82+
/**
83+
* @return string
84+
*/
85+
public function getJiraUser()
86+
{
87+
return $this->jiraUser;
88+
}
89+
90+
/**
91+
* @return string
92+
*/
93+
public function getJiraPassword()
94+
{
95+
return $this->jiraPassword;
96+
}
97+
98+
/**
99+
* @return string
100+
*/
101+
public function getJiraLogFile()
102+
{
103+
return $this->jiraLogFile;
104+
}
105+
106+
/**
107+
* @return string
108+
*/
109+
public function getJiraLogLevel()
110+
{
111+
return $this->jiraLogLevel;
112+
}
113+
114+
/**
115+
* @return boolean
116+
*/
117+
public function isCurlOptSslVerifyHost()
118+
{
119+
return $this->curlOptSslVerifyHost;
120+
}
121+
122+
/**
123+
* @return boolean
124+
*/
125+
public function isCurlOptSslVerifyPeer()
126+
{
127+
return $this->curlOptSslVerifyPeer;
128+
}
129+
130+
/**
131+
* @return boolean
132+
*/
133+
public function isCurlOptVerbose()
134+
{
135+
return $this->curlOptVerbose;
136+
}
137+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: keanor
5+
* Date: 17.08.15
6+
* Time: 22:40
7+
*/
8+
9+
namespace JiraRestApi\Configuration;
10+
11+
/**
12+
* Class ArrayConfiguration
13+
*
14+
* @package JiraRestApi\Configuration
15+
*/
16+
class ArrayConfiguration extends AbstractConfiguration
17+
{
18+
/**
19+
* @param array $configuration
20+
*/
21+
public function __construct(array $configuration)
22+
{
23+
foreach ($configuration as $key => $value) {
24+
if (property_exists($this, $key)) {
25+
$this->$key = $value;
26+
}
27+
}
28+
}
29+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: keanor
5+
* Date: 17.08.15
6+
* Time: 21:58
7+
*/
8+
namespace JiraRestApi\Configuration;
9+
10+
/**
11+
* Interface ConfigurationInterface
12+
*
13+
* @package JiraRestApi\Configuration
14+
*/
15+
interface ConfigurationInterface
16+
{
17+
/**
18+
* Jira host
19+
*
20+
* @return string
21+
*/
22+
public function getJiraHost();
23+
24+
/**
25+
* Jira login
26+
*
27+
* @return string
28+
*/
29+
public function getJiraUser();
30+
31+
/**
32+
* Jira password
33+
*
34+
* @return string
35+
*/
36+
public function getJiraPassword();
37+
38+
/**
39+
* Path to log file
40+
*
41+
* @return string
42+
*/
43+
public function getJiraLogFile();
44+
45+
/**
46+
* Log level (DEBUG, INFO, ERROR, WARNING)
47+
*
48+
* @return string
49+
*/
50+
public function getJiraLogLevel();
51+
52+
/**
53+
* Curl options CURLOPT_SSL_VERIFYHOST
54+
*
55+
* @return boolean
56+
*/
57+
public function isCurlOptSslVerifyHost();
58+
59+
/**
60+
* Curl options CURLOPT_SSL_VERIFYPEER
61+
*
62+
* @return boolean
63+
*/
64+
public function isCurlOptSslVerifyPeer();
65+
66+
/**
67+
* Curl options CURLOPT_VERBOSE
68+
*
69+
* @return boolean
70+
*/
71+
public function isCurlOptVerbose();
72+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: keanor
5+
* Date: 17.08.15
6+
* Time: 22:01
7+
*/
8+
namespace JiraRestApi\Configuration;
9+
10+
use Dotenv;
11+
12+
/**
13+
* Class DotEnvConfiguration
14+
*
15+
* @package JiraRestApi\Configuration
16+
*/
17+
class DotEnvConfiguration extends AbstractConfiguration
18+
{
19+
/**
20+
* @param string $path
21+
*/
22+
public function __construct($path = '.')
23+
{
24+
Dotenv::load($path);
25+
26+
// not available in dotenv 1.1
27+
// $dotenv->required(['JIRA_HOST', 'JIRA_USER', 'JIRA_PASS']);
28+
29+
$this->jiraHost = $this->env('JIRA_HOST');
30+
$this->jiraUser = $this->env('JIRA_USER');
31+
$this->jiraPassword = $this->env('JIRA_PASS');
32+
$this->jiraLogFile = $this->env('JIRA_LOG_FILE', 'jira-rest-client.log');
33+
$this->jiraLogLevel = $this->env('JIRA_LOG_LEVEL', 'WARNING');
34+
$this->curlOptSslVerifyHost = $this->env('CURLOPT_SSL_VERIFYHOST', false);
35+
$this->curlOptSslVerifyPeer = $this->env('CURLOPT_SSL_VERIFYPEER', false);
36+
$this->curlOptVerbose = $this->env('CURLOPT_VERBOSE', false);
37+
}
38+
39+
/**
40+
* Gets the value of an environment variable. Supports boolean, empty and null.
41+
*
42+
* @param string $key
43+
* @param mixed $default
44+
*
45+
* @return mixed
46+
*/
47+
private function env($key, $default = null)
48+
{
49+
$value = getenv($key);
50+
51+
if ($value === false) {
52+
return $default;
53+
}
54+
55+
switch (strtolower($value)) {
56+
case 'true':
57+
case '(true)':
58+
return true;
59+
60+
case 'false':
61+
case '(false)':
62+
return false;
63+
64+
case 'empty':
65+
case '(empty)':
66+
return '';
67+
68+
case 'null':
69+
case '(null)':
70+
return null;
71+
}
72+
73+
if ($this->startsWith($value, '"') && endsWith($value, '"')) {
74+
return substr($value, 1, -1);
75+
}
76+
77+
return $value;
78+
}
79+
80+
/**
81+
* Determine if a given string starts with a given substring.
82+
*
83+
* @param string $haystack
84+
* @param string|array $needles
85+
*
86+
* @return bool
87+
*/
88+
public function startsWith($haystack, $needles)
89+
{
90+
foreach ((array) $needles as $needle) {
91+
if ($needle != '' && strpos($haystack, $needle) === 0) {
92+
return true;
93+
}
94+
}
95+
96+
return false;
97+
}
98+
99+
/**
100+
* Determine if a given string ends with a given substring.
101+
*
102+
* @param string $haystack
103+
* @param string|array $needles
104+
*
105+
* @return bool
106+
*/
107+
public function endsWith($haystack, $needles)
108+
{
109+
foreach ((array) $needles as $needle) {
110+
if ((string) $needle === substr($haystack, -strlen($needle))) {
111+
return true;
112+
}
113+
}
114+
115+
return false;
116+
}
117+
}

src/Issue/IssueField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function getIssueType()
149149
/** @var array */
150150
public $progress;
151151

152-
/** @var Timetracking */
152+
/** @var TimeTracking */
153153
public $timetracking;
154154

155155
/** @var IssueType */

src/Issue/IssueService.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ class IssueService extends \JiraRestApi\JiraClient
66
{
77
private $uri = '/issue';
88

9-
public function __construct($path = '.')
10-
{
11-
parent::__construct($path);
12-
}
13-
149
/**
1510
* get all project list.
1611
*

0 commit comments

Comments
 (0)