1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Server\Traits\ServerVarsObjectTrait |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Johann Zelger <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/server |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Server\Traits; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Trait ServerVarsObjectTrait |
25
|
|
|
* |
26
|
|
|
* @author Johann Zelger <[email protected]> |
27
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link https://github.com/appserver-io/server |
30
|
|
|
* @link http://www.appserver.io |
31
|
|
|
*/ |
32
|
|
View Code Duplication |
trait ServerVarsObjectTrait |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Sets a value to specific server var |
36
|
|
|
* |
37
|
|
|
* @param string $serverVar The server var to set |
38
|
|
|
* @param string $value The value to server var |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
public function setServerVar($serverVar, $value) |
43
|
|
|
{ |
44
|
|
|
$this->serverVars->add($serverVar, $value); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Unsets a specific server var |
49
|
|
|
* |
50
|
|
|
* @param string $serverVar The server var to unset |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function unsetServerVar($serverVar) |
55
|
|
|
{ |
56
|
|
|
$this->serverVars->remove($serverVar); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns a value for specific server var |
61
|
|
|
* |
62
|
|
|
* @param string $serverVar The server var to get value for |
63
|
|
|
* |
64
|
|
|
* @throws \AppserverIo\Server\Exceptions\ServerException |
65
|
|
|
* |
66
|
|
|
* @return string The value to given server var |
67
|
|
|
*/ |
68
|
|
|
public function getServerVar($serverVar) |
69
|
|
|
{ |
70
|
|
|
// get from hash map |
71
|
|
|
return $this->serverVars->get($serverVar); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Returns all the server vars as array key value pair format |
76
|
|
|
* |
77
|
|
|
* @return array The server vars as array |
78
|
|
|
*/ |
79
|
|
|
public function getServerVars() |
80
|
|
|
{ |
81
|
|
|
return $this->serverVars->toIndexedArray(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Checks if value exists for given server var |
86
|
|
|
* |
87
|
|
|
* @param string $serverVar The server var to check |
88
|
|
|
* |
89
|
|
|
* @return bool Weather it has serverVar (true) or not (false) |
90
|
|
|
*/ |
91
|
|
|
public function hasServerVar($serverVar) |
92
|
|
|
{ |
93
|
|
|
// check if server var is set |
94
|
|
|
return $this->serverVars->exists($serverVar); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Clears the server vars storage |
99
|
|
|
* |
100
|
|
|
* @return void |
101
|
|
|
*/ |
102
|
|
|
public function clearServerVars() |
103
|
|
|
{ |
104
|
|
|
$this->serverVars->clear(); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.