|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Borobudur-DependencyInjection package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Hexacodelabs <http://hexacodelabs.com> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Borobudur\DependencyInjection\Definition; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @author Iqbal Maulana <[email protected]> |
|
15
|
|
|
* @created 8/8/15 |
|
16
|
|
|
*/ |
|
17
|
|
|
class Property |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
private $properties = array(); |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Constructor. |
|
26
|
|
|
* |
|
27
|
|
|
* @param array $properties |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(array $properties = array()) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->properties = $properties; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Clear and replace with sets of properties. |
|
36
|
|
|
* |
|
37
|
|
|
* @param array $properties |
|
38
|
|
|
* |
|
39
|
|
|
* @return Property |
|
40
|
|
|
*/ |
|
41
|
|
|
public function replace(array $properties) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->properties = array(); |
|
44
|
|
|
|
|
45
|
|
|
return $this->add($properties); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Add parameter. |
|
50
|
|
|
* |
|
51
|
|
|
* @param array $properties |
|
52
|
|
|
* |
|
53
|
|
|
* @return static |
|
54
|
|
|
*/ |
|
55
|
|
|
public function add(array $properties) |
|
56
|
|
|
{ |
|
57
|
|
|
foreach ($properties as $name => $value) { |
|
58
|
|
|
$this->set($name, $value); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Set property. |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $name |
|
68
|
|
|
* @param mixed $value |
|
69
|
|
|
* |
|
70
|
|
|
* @return static |
|
71
|
|
|
*/ |
|
72
|
|
|
public function set($name, $value) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->properties[$name] = $value; |
|
75
|
|
|
|
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get property value. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $name |
|
83
|
|
|
* |
|
84
|
|
|
* @return mixed|null |
|
85
|
|
|
*/ |
|
86
|
|
|
public function get($name) |
|
87
|
|
|
{ |
|
88
|
|
|
if (array_key_exists($name, $this->properties)) { |
|
89
|
|
|
return $this->properties[$name]; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return null; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Check if has property with specified name. |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $name |
|
99
|
|
|
* |
|
100
|
|
|
* @return bool |
|
101
|
|
|
*/ |
|
102
|
|
|
public function has($name) |
|
103
|
|
|
{ |
|
104
|
|
|
return array_key_exists($name, $this->properties); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Get all properties. |
|
109
|
|
|
* |
|
110
|
|
|
* @return array |
|
111
|
|
|
*/ |
|
112
|
|
|
public function all() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->properties; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|