Code Duplication    Length = 90-92 lines in 2 locations

src/AppserverIo/Server/Traits/EnvVarsArrayTrait.php 1 location

@@ 34-123 (lines=90) @@
31
 * @link      https://github.com/appserver-io/server
32
 * @link      http://www.appserver.io
33
 */
34
trait EnvVarsArrayTrait
35
{
36
    /**
37
     * Sets a value to specific env var
38
     *
39
     * @param string $envVar The env var to set
40
     * @param string $value  The value to env var
41
     *
42
     * @return void
43
     */
44
    public function setEnvVar($envVar, $value)
45
    {
46
        if (!is_null($value)) {
47
            $this->envVars[$envVar] = $value;
48
        }
49
    }
50
51
    /**
52
     * Unsets a specific env var
53
     *
54
     * @param string $envVar The env var to unset
55
     *
56
     * @return void
57
     */
58
    public function unsetEnvVar($envVar)
59
    {
60
        if (isset($this->envVars[$envVar])) {
61
            unset($this->envVars[$envVar]);
62
        }
63
    }
64
65
    /**
66
     * Returns a value for specific env var
67
     *
68
     * @param string $envVar The env var to get value for
69
     *
70
     * @throws \AppserverIo\Server\Exceptions\ServerException
71
     *
72
     * @return mixed The value to given env var
73
     */
74
    public function getEnvVar($envVar)
75
    {
76
        // check if var is set
77
        if (isset($this->envVars[$envVar])) {
78
            // return vars value
79
            return $this->envVars[$envVar];
80
        }
81
        // throw exception
82
        throw new ServerException("Env var '$envVar'' does not exist.", 500);
83
    }
84
85
    /**
86
     * Returns all the env vars as array key value pair format
87
     *
88
     * @return array The env vars as array
89
     */
90
    public function getEnvVars()
91
    {
92
        return $this->envVars;
93
    }
94
95
    /**
96
     * Checks if value exists for given env var
97
     *
98
     * @param string $envVar The env var to check
99
     *
100
     * @return boolean Weather it has envVar (true) or not (false)
101
     */
102
    public function hasEnvVar($envVar)
103
    {
104
        // check if var is set
105
        if (!isset($this->envVars[$envVar])) {
106
            return false;
107
        }
108
109
        return true;
110
    }
111
112
    /**
113
     * Clears the env vars storage
114
     *
115
     * @return void
116
     */
117
    public function clearEnvVars()
118
    {
119
        foreach ($this->envVars as $key => $value) {
120
            unset($this->envVars[$key]);
121
        }
122
    }
123
}
124

src/AppserverIo/Server/Traits/ModuleVarsArrayTrait.php 1 location

@@ 34-125 (lines=92) @@
31
 * @link      https://github.com/appserver-io/server
32
 * @link      http://www.appserver.io
33
 */
34
trait ModuleVarsArrayTrait
35
{
36
37
    /**
38
     * Sets a value to specific module var
39
     *
40
     * @param string $moduleVar The module var to set
41
     * @param string $value     The value to module var
42
     *
43
     * @return void
44
     */
45
    public function setModuleVar($moduleVar, $value)
46
    {
47
        if (!is_null($value)) {
48
            $this->moduleVars[$moduleVar] = $value;
49
        }
50
    }
51
52
    /**
53
     * Unsets a specific module var
54
     *
55
     * @param string $moduleVar The module var to unset
56
     *
57
     * @return void
58
     */
59
    public function unsetModuleVar($moduleVar)
60
    {
61
        if (isset($this->moduleVars[$moduleVar])) {
62
            unset($this->moduleVars[$moduleVar]);
63
        }
64
    }
65
66
    /**
67
     * Returns a value for specific module var
68
     *
69
     * @param string $moduleVar The module var to get value for
70
     *
71
     * @throws \AppserverIo\Server\Exceptions\ServerException
72
     *
73
     * @return mixed The value to given module var
74
     */
75
    public function getModuleVar($moduleVar)
76
    {
77
        // check if var is set
78
        if (isset($this->moduleVars[$moduleVar])) {
79
            // return vars value
80
            return $this->moduleVars[$moduleVar];
81
        }
82
        // throw exception
83
        throw new ServerException("Module var '$moduleVar'' does not exist.", 500);
84
    }
85
86
87
    /**
88
     * Returns all the module vars as array key value pair format
89
     *
90
     * @return array The module vars as array
91
     */
92
    public function getModuleVars()
93
    {
94
        return $this->moduleVars;
95
    }
96
97
    /**
98
     * Checks if value exists for given module var
99
     *
100
     * @param string $moduleVar The module var to check
101
     *
102
     * @return boolean Weather it has moduleVar (true) or not (false)
103
     */
104
    public function hasModuleVar($moduleVar)
105
    {
106
        // check if var is set
107
        if (!isset($this->moduleVars[$moduleVar])) {
108
            return false;
109
        }
110
111
        return true;
112
    }
113
114
    /**
115
     * Clears the module vars storage
116
     *
117
     * @return void
118
     */
119
    public function clearModuleVars()
120
    {
121
        foreach ($this->moduleVars as $key => $value) {
122
            unset($this->moduleVars[$key]);
123
        }
124
    }
125
}
126