1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Server\Traits\ModuleVarsObjectTrait |
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 ModuleVarsObjectTrait |
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 ModuleVarsObjectTrait |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Sets a value to specific module var |
37
|
|
|
* |
38
|
|
|
* @param string $moduleVar The module var to set |
39
|
|
|
* @param string $value The value to module var |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function setModuleVar($moduleVar, $value) |
44
|
|
|
{ |
45
|
|
|
$this->moduleVars->add($moduleVar, $value); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Unsets a specific module var |
50
|
|
|
* |
51
|
|
|
* @param string $moduleVar The module var to unset |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
public function unsetModuleVar($moduleVar) |
56
|
|
|
{ |
57
|
|
|
$this->moduleVars->remove($moduleVar); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns a value for specific module var |
62
|
|
|
* |
63
|
|
|
* @param string $moduleVar The module var to get value for |
64
|
|
|
* |
65
|
|
|
* @throws \AppserverIo\Server\Exceptions\ServerException |
66
|
|
|
* |
67
|
|
|
* @return mixed The value to given module var |
68
|
|
|
*/ |
69
|
|
|
public function getModuleVar($moduleVar) |
70
|
|
|
{ |
71
|
|
|
// get from hash map |
72
|
|
|
return $this->moduleVars->get($moduleVar); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns all the module vars as array key value pair format |
78
|
|
|
* |
79
|
|
|
* @return array The module vars as array |
80
|
|
|
*/ |
81
|
|
|
public function getModuleVars() |
82
|
|
|
{ |
83
|
|
|
return $this->moduleVars->toIndexedArray(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Checks if value exists for given module var |
88
|
|
|
* |
89
|
|
|
* @param string $moduleVar The module var to check |
90
|
|
|
* |
91
|
|
|
* @return boolean Weather it has moduleVar (true) or not (false) |
92
|
|
|
*/ |
93
|
|
|
public function hasModuleVar($moduleVar) |
94
|
|
|
{ |
95
|
|
|
// check if var is set |
96
|
|
|
return $this->moduleVars->exists($moduleVar); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Clears the module vars storage |
101
|
|
|
* |
102
|
|
|
* @return void |
103
|
|
|
*/ |
104
|
|
|
public function clearModuleVars() |
105
|
|
|
{ |
106
|
|
|
$this->moduleVars->clear(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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.