1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Veto. |
4
|
|
|
* PHP Microframework. |
5
|
|
|
* |
6
|
|
|
* @author Damien Walsh <[email protected]> |
7
|
|
|
* @copyright Damien Walsh 2013-2014 |
8
|
|
|
* @version 0.1 |
9
|
|
|
* @package veto |
10
|
|
|
*/ |
11
|
|
|
namespace Veto\DependencyInjection; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Definition |
15
|
|
|
* |
16
|
|
|
* Data carrier class that defines the properties of a service. |
17
|
|
|
*/ |
18
|
|
|
class Definition |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The name of the service. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $name; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The FQCN of the service. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $className; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Whether or not the service is One Shot. |
36
|
|
|
* |
37
|
|
|
* @var boolean |
38
|
|
|
*/ |
39
|
|
|
private $isOneShot; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Parameters to be passed when the service is constructed. |
43
|
|
|
* |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
private $parameters; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Methods to call after the service is constructed. |
50
|
|
|
* |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
private $calls; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Initialise a definition from a name and an array of configuration. |
57
|
|
|
* |
58
|
|
|
* @param string $serviceName |
59
|
|
|
* @param array $configuration |
60
|
|
|
* @return self |
61
|
|
|
*/ |
62
|
|
|
public static function initWithArray($serviceName, array $configuration) |
63
|
|
|
{ |
64
|
|
|
$definition = new self; |
65
|
|
|
$definition->setName($serviceName); |
66
|
|
|
|
67
|
|
|
foreach ($configuration as $key => $value) { |
68
|
|
|
switch ($key) { |
69
|
|
|
|
70
|
|
|
case 'class': |
71
|
|
|
$definition->setClassName($value); |
72
|
|
|
break; |
73
|
|
|
|
74
|
|
|
case 'one_shot': |
75
|
|
|
$definition->setIsOneShot((boolval($value))); |
76
|
|
|
break; |
77
|
|
|
|
78
|
|
|
case 'parameters': |
79
|
|
|
$definition->setParameters($value); |
80
|
|
|
break; |
81
|
|
|
|
82
|
|
|
case 'calls': |
83
|
|
|
$definition->setCalls($value); |
84
|
|
|
break; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $definition; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
public function getName() |
95
|
|
|
{ |
96
|
|
|
return $this->name; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string $name |
101
|
|
|
* @return Definition |
102
|
|
|
*/ |
103
|
|
|
public function setName($name) |
104
|
|
|
{ |
105
|
|
|
$this->name = $name; |
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getClassName() |
113
|
|
|
{ |
114
|
|
|
return $this->className; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string $className |
119
|
|
|
* @return Definition |
120
|
|
|
*/ |
121
|
|
|
public function setClassName($className) |
122
|
|
|
{ |
123
|
|
|
$this->className = $className; |
124
|
|
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return boolean |
129
|
|
|
*/ |
130
|
|
|
public function isOneShot() |
131
|
|
|
{ |
132
|
|
|
return $this->isOneShot; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param boolean $isOneShot |
137
|
|
|
* @return Definition |
138
|
|
|
*/ |
139
|
|
|
public function setIsOneShot($isOneShot) |
140
|
|
|
{ |
141
|
|
|
$this->isOneShot = $isOneShot; |
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return array |
147
|
|
|
*/ |
148
|
|
|
public function getParameters() |
149
|
|
|
{ |
150
|
|
|
return $this->parameters; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param array $parameters |
155
|
|
|
* @return Definition |
156
|
|
|
*/ |
157
|
|
|
public function setParameters($parameters) |
158
|
|
|
{ |
159
|
|
|
$this->parameters = $parameters; |
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return array |
165
|
|
|
*/ |
166
|
|
|
public function getCalls() |
167
|
|
|
{ |
168
|
|
|
return $this->calls; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param array $calls |
173
|
|
|
* @return Definition |
174
|
|
|
*/ |
175
|
|
|
public function setCalls($calls) |
176
|
|
|
{ |
177
|
|
|
$this->calls = $calls; |
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|