1
|
|
|
<?php namespace Comodojo\Foundation\Base; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Comodojo Foundation |
5
|
|
|
* @author Marco Giovinazzi <[email protected]> |
6
|
|
|
* @license MIT |
7
|
|
|
* |
8
|
|
|
* LICENSE: |
9
|
|
|
* |
10
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
11
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
12
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
13
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
14
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
15
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
16
|
|
|
* THE SOFTWARE. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
class Configuration { |
20
|
|
|
|
21
|
|
|
use ConfigurationParametersTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Create a configuration object from array of values |
25
|
|
|
* |
26
|
|
|
* @param array $configuration |
27
|
|
|
* @return self |
|
|
|
|
28
|
|
|
*/ |
29
|
8 |
|
public function __construct(array $configuration = []) { |
30
|
|
|
|
31
|
8 |
|
$this->parameters = array_merge($this->parameters, $configuration); |
32
|
|
|
|
33
|
8 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Check if a property is defined |
37
|
|
|
* |
38
|
|
|
* @deprecated |
39
|
|
|
* @see Configuration::has() |
40
|
|
|
* |
41
|
|
|
* @param string $property |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
2 |
|
public function isDefined($property) { |
45
|
|
|
|
46
|
2 |
|
return $this->has($property); |
47
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Merge a bundle of properties into actual configuration model |
52
|
|
|
* |
53
|
|
|
* @param array $properties |
54
|
|
|
* @return self |
55
|
|
|
*/ |
56
|
1 |
|
public function merge(array $properties) { |
57
|
|
|
|
58
|
1 |
|
$this->parameters = array_replace($this->parameters, $properties); |
59
|
|
|
|
60
|
1 |
|
return $this; |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public static function create(array $configuration = []) { |
65
|
|
|
|
66
|
1 |
|
return new Configuration($configuration); |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.