Completed
Push — master ( 39986e...13eb1c )
by Christian
02:43
created

TensideJsonConfig::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file is part of tenside/core.
5
 *
6
 * (c) Christian Schiffler <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core
14
 * @author     Christian Schiffler <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core
18
 * @filesource
19
 */
20
21
namespace Tenside\Core\Config;
22
23
/**
24
 * Main tenside configuration (abstraction over tenside.json).
25
 */
26
class TensideJsonConfig extends SourceJson
27
{
28
    /**
29
     * Retrieve the secret.
30
     *
31
     * @return string|null
32
     */
33
    public function getSecret()
34
    {
35
        return $this->getIfNotNull('secret', null);
36
    }
37
38
    /**
39
     * Set the secret.
40
     *
41
     * @param string $secret The new secret.
42
     *
43
     * @return TensideJsonConfig
44
     */
45
    public function setSecret($secret)
46
    {
47
        $this->set('secret', $secret);
48
49
        return $this;
50
    }
51
52
    /**
53
     * Retrieve the domain.
54
     *
55
     * @return string|null
56
     */
57
    public function getLocalDomain()
58
    {
59
        return $this->getIfNotNull('domain', null);
60
    }
61
62
    /**
63
     * Set the domain.
64
     *
65
     * @param string $domain The new domain.
66
     *
67
     * @return TensideJsonConfig
68
     */
69
    public function setLocalDomain($domain)
70
    {
71
        $this->set('domain', $domain);
72
73
        return $this;
74
    }
75
76
    /**
77
     * Get the interpreter to use.
78
     *
79
     * @return string
80
     */
81
    public function getPhpCliBinary()
82
    {
83
        // If defined, override the php-cli interpreter.
84
        return $this->getIfNotNull('php_cli', 'php');
85
    }
86
87
    /**
88
     * Set the interpreter to use.
89
     *
90
     * @param string $binary The new interpreter to use.
91
     *
92
     * @return TensideJsonConfig
93
     */
94
    public function setPhpCliBinary($binary)
95
    {
96
        $this->set('php_cli', $binary);
97
98
        return $this;
99
    }
100
101
    /**
102
     * Retrieve the arguments to pass to the php process
103
     *
104
     * @return array|null
105
     */
106
    public function getPhpCliArguments()
107
    {
108
        return $this->getIfNotNull('php_cli_arguments', null);
109
    }
110
111
    /**
112
     * Set the arguments to use.
113
     *
114
     * @param array $arguments The new arguments to use.
115
     *
116
     * @return TensideJsonConfig
117
     */
118
    public function setPhpCliArguments($arguments)
119
    {
120
        $this->set('php_cli_arguments', $arguments);
121
122
        return $this;
123
    }
124
125
    /**
126
     * Add a command line argument.
127
     *
128
     * @param string $argument The argument to add.
129
     *
130
     * @return TensideJsonConfig
131
     */
132
    public function addCommandLineArgument($argument)
133
    {
134
        $args = (array) $this->getPhpCliArguments();
135
        $this->setPhpCliArguments(array_merge($args, [$argument]));
136
137
        return $this;
138
    }
139
140
    /**
141
     * Retrieve the additional environment variables.
142
     *
143
     * @return array|null
144
     */
145
    public function getPhpCliEnvironment()
146
    {
147
        return $this->getIfNotNull('php_cli_environment', null);
148
    }
149
150
    /**
151
     * Set the additional environment variables.
152
     *
153
     * @param array $variables The new arguments to use.
154
     *
155
     * @return TensideJsonConfig
156
     */
157
    public function setPhpCliEnvironment($variables)
158
    {
159
        $this->set('php_cli_environment', $variables);
160
161
        return $this;
162
    }
163
164
    /**
165
     * Check if forking is available.
166
     *
167
     * @return string|null
168
     */
169
    public function isForkingAvailable()
170
    {
171
        return $this->getIfNotNull('php_can_fork', false);
172
    }
173
174
    /**
175
     * Set the additional environment variables.
176
     *
177
     * @param bool $available The new arguments to use.
178
     *
179
     * @return TensideJsonConfig
180
     */
181
    public function setForkingAvailable($available)
182
    {
183
        $this->set('php_can_fork', $available);
184
185
        return $this;
186
    }
187
188
    /**
189
     * Obtain a value from if it is set or return the default value otherwise.
190
     *
191
     * @param string $key     The key to obtain.
192
     *
193
     * @param mixed  $default The default value to return if not set.
194
     *
195
     * @return mixed
196
     */
197
    private function getIfNotNull($key, $default = null)
198
    {
199
        return $this->has($key) ? $this->get($key) : $default;
200
    }
201
}
202