1 | <?php |
||
35 | trait ServerVarsArrayTrait |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Maps configuration value types to string values. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $typeMappings = array( |
||
44 | ServerVars::SERVER_AUTO_INDEX => array( |
||
45 | true => ServerVars::VALUE_AUTO_INDEX_ON, |
||
46 | false => ServerVars::VALUE_AUTO_INDEX_OFF |
||
47 | ), |
||
48 | ServerVars::HTTPS => array( |
||
49 | 'ssl' => ServerVars::VALUE_HTTPS_ON, |
||
50 | 'tcp' => ServerVars::VALUE_HTTPS_OFF |
||
51 | ) |
||
52 | ); |
||
53 | |||
54 | /** |
||
55 | * Sets a value to specific server var |
||
56 | * |
||
57 | * @param string $serverVar The server var to set |
||
58 | * @param string $value The value to server var |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | 1 | public function setServerVar($serverVar, $value) |
|
63 | { |
||
64 | 1 | if (!is_null($value)) { |
|
65 | 1 | if (isset($this->typeMappings[$serverVar][$value])) { |
|
66 | $this->serverVars[$serverVar] = $this->typeMappings[$serverVar][$value]; |
||
|
|||
67 | } else { |
||
68 | 1 | $this->serverVars[$serverVar] = $value; |
|
69 | } |
||
70 | 1 | } |
|
71 | 1 | } |
|
72 | |||
73 | /** |
||
74 | * Unsets a specific server var |
||
75 | * |
||
76 | * @param string $serverVar The server var to unset |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | public function unsetServerVar($serverVar) |
||
81 | { |
||
82 | if (isset($this->serverVars[$serverVar])) { |
||
83 | unset($this->serverVars[$serverVar]); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Returns a value for specific server var |
||
89 | * |
||
90 | * @param string $serverVar The server var to get value for |
||
91 | * |
||
92 | * @throws \AppserverIo\Server\Exceptions\ServerException |
||
93 | * |
||
94 | * @return string The value to given server var |
||
95 | */ |
||
96 | 1 | public function getServerVar($serverVar) |
|
105 | |||
106 | /** |
||
107 | * Returns all the server vars as array key value pair format. |
||
108 | * |
||
109 | * @return array The server vars as array |
||
110 | */ |
||
111 | public function getServerVars() |
||
115 | |||
116 | /** |
||
117 | * Checks if value exists for given server var |
||
118 | * |
||
119 | * @param string $serverVar The server var to check |
||
120 | * |
||
121 | * @return bool Weather it has serverVar (true) or not (false) |
||
122 | */ |
||
123 | public function hasServerVar($serverVar) |
||
132 | |||
133 | /** |
||
134 | * Clears the server vars storage |
||
135 | * |
||
136 | * @return void |
||
137 | */ |
||
138 | public function clearServerVars() |
||
144 | } |
||
145 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: