|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the LGPL. For more information please see |
|
17
|
|
|
* <http://phing.info>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Representation of a single env value. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Siad Ardroumli <[email protected]> |
|
24
|
|
|
* @package phing.types.environment |
|
25
|
|
|
*/ |
|
26
|
|
|
class EnvVariable |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* env key and value pair; everything gets expanded to a string |
|
30
|
|
|
* during assignment |
|
31
|
|
|
*/ |
|
32
|
|
|
private $key; |
|
33
|
|
|
private $value; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* set the key |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $key string |
|
39
|
|
|
*/ |
|
40
|
2 |
|
public function setKey($key) |
|
41
|
|
|
{ |
|
42
|
2 |
|
$this->key = $key; |
|
43
|
2 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* set the value |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $value |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function setValue($value) |
|
51
|
|
|
{ |
|
52
|
1 |
|
$this->value = $value; |
|
53
|
1 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* key accessor |
|
57
|
|
|
* |
|
58
|
|
|
* @return string key |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getKey() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->key; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* value accessor |
|
67
|
|
|
* |
|
68
|
|
|
* @return string value |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getValue() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->value; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* stringify path and assign to the value. |
|
77
|
|
|
* The value will contain all path elements separated by the appropriate |
|
78
|
|
|
* separator |
|
79
|
|
|
* |
|
80
|
|
|
* @param Path $path |
|
81
|
|
|
*/ |
|
82
|
1 |
|
public function setPath(Path $path) |
|
83
|
|
|
{ |
|
84
|
1 |
|
$this->value = (string) $path; |
|
85
|
1 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* get the absolute path of a file and assign it to the value |
|
89
|
|
|
* |
|
90
|
|
|
* @param PhingFile $file file to use as the value |
|
91
|
|
|
*/ |
|
92
|
|
|
public function setFile(PhingFile $file) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->value = $file->getAbsolutePath(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* get the assignment string |
|
99
|
|
|
* This is not ready for insertion into a property file without following |
|
100
|
|
|
* the escaping rules of the properties class. |
|
101
|
|
|
* |
|
102
|
|
|
* @return string of the form key=value. |
|
103
|
|
|
* @throws BuildException if key or value are unassigned |
|
104
|
|
|
*/ |
|
105
|
2 |
|
public function getContent() |
|
106
|
|
|
{ |
|
107
|
2 |
|
$this->validate(); |
|
108
|
2 |
|
return trim($this->key) . '=' . trim($this->value); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* checks whether all required attributes have been specified. |
|
113
|
|
|
* |
|
114
|
|
|
* @throws BuildException if key or value are unassigned |
|
115
|
|
|
*/ |
|
116
|
3 |
|
public function validate() |
|
117
|
|
|
{ |
|
118
|
3 |
|
if ($this->key === null || $this->value === null) { |
|
119
|
1 |
|
throw new BuildException('key and value must be specified for environment variables.'); |
|
120
|
|
|
} |
|
121
|
2 |
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|