1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* \Wicked\Timely\DotEnvConfiguration |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
8
|
|
|
* that is available through the world-wide-web at this URL: |
9
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
10
|
|
|
* |
11
|
|
|
* PHP version 5 |
12
|
|
|
* |
13
|
|
|
* @author wick-ed |
14
|
|
|
* @copyright 2020 Bernhard Wick |
15
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
16
|
|
|
* @link https://github.com/wick-ed/timely |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Wicked\Timely; |
20
|
|
|
|
21
|
|
|
use JiraRestApi\Configuration\DotEnvConfiguration as JiraDotEnvConfiguration; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* DotEnvConfiguration class file |
25
|
|
|
* |
26
|
|
|
* @author wick-ed |
27
|
|
|
* @copyright 2020 Bernhard Wick |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link https://github.com/wick-ed/timely |
30
|
|
|
*/ |
31
|
|
|
class DotEnvConfiguration extends JiraDotEnvConfiguration |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
protected $pushService; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* DotEnvConfiguration constructor. |
38
|
|
|
* |
39
|
|
|
* @param string $path Path to the configuration file |
40
|
|
|
* |
41
|
|
|
* @throws \JiraRestApi\JiraException |
42
|
|
|
*/ |
43
|
|
|
public function __construct($path = '.') |
44
|
|
|
{ |
45
|
|
|
parent::__construct(realpath(__DIR__ . '/../')); |
46
|
|
|
$this->pushService = $this->env('PUSH_SERVICE'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Gets the value of an environment variable. Supports boolean, empty and null. |
51
|
|
|
* |
52
|
|
|
* @param string $key |
53
|
|
|
* @param mixed $default |
54
|
|
|
* |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
|
|
protected function env($key, $default = null) |
58
|
|
|
{ |
59
|
|
|
$value = getenv($key); |
60
|
|
|
|
61
|
|
|
if ($value === false) { |
62
|
|
|
return $default; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
switch (strtolower($value)) { |
66
|
|
|
case 'true': |
67
|
|
|
case '(true)': |
68
|
|
|
return true; |
69
|
|
|
|
70
|
|
|
case 'false': |
71
|
|
|
case '(false)': |
72
|
|
|
return false; |
73
|
|
|
|
74
|
|
|
case 'empty': |
75
|
|
|
case '(empty)': |
76
|
|
|
return ''; |
77
|
|
|
|
78
|
|
|
case 'null': |
79
|
|
|
case '(null)': |
80
|
|
|
return; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if ($this->startsWith($value, '"') && $this->endsWith($value, '"')) { |
84
|
|
|
return substr($value, 1, -1); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $value; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return mixed |
92
|
|
|
*/ |
93
|
|
|
public function getPushService() |
94
|
|
|
{ |
95
|
|
|
return $this->pushService; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Setter for the jira password configuration |
100
|
|
|
* |
101
|
|
|
* @param string $value Password value to set |
102
|
|
|
* |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
public function setJiraPassword($value) |
106
|
|
|
{ |
107
|
|
|
$this->jiraPassword = $value; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|