|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sensorario\Container\Objects; |
|
4
|
|
|
|
|
5
|
|
|
class Service |
|
6
|
|
|
{ |
|
7
|
|
|
private $params; |
|
8
|
|
|
|
|
9
|
6 |
|
private function __construct(array $params) |
|
10
|
|
|
{ |
|
11
|
6 |
|
$this->params = $params; |
|
12
|
6 |
|
} |
|
13
|
|
|
|
|
14
|
6 |
|
public static function box(array $params) |
|
15
|
|
|
{ |
|
16
|
6 |
|
return new self($params); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
6 |
|
public function getParams() |
|
20
|
|
|
{ |
|
21
|
6 |
|
return isset($this->params['services'][$this->getName()]['params']) |
|
22
|
6 |
|
? $this->params['services'][$this->getName()]['params'] |
|
23
|
6 |
|
: array(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
6 |
|
public function getMethods() |
|
27
|
|
|
{ |
|
28
|
6 |
|
return isset($this->params['services'][$this->getName()]['methods']) |
|
29
|
6 |
|
? $this->params['services'][$this->getName()]['methods'] |
|
30
|
6 |
|
: array(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
5 |
|
public function getClass() |
|
34
|
|
|
{ |
|
35
|
5 |
|
$argument = Argument::fromString($this->params['name']); |
|
36
|
5 |
|
$serviceName = $argument->getServiceName(); |
|
37
|
5 |
|
return $this->params['services'][$serviceName]['class']; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
public function getServicesConfiguration() |
|
41
|
|
|
{ |
|
42
|
1 |
|
return $this->params['services']; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
6 |
|
public function getName() |
|
46
|
|
|
{ |
|
47
|
6 |
|
return $this->params['name']; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function isConstructorEmpty() |
|
51
|
|
|
{ |
|
52
|
|
|
return array() == $this->getParams(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
6 |
|
public function isConstructorInjection() |
|
56
|
|
|
{ |
|
57
|
6 |
|
return array() == $this->getMethods() |
|
58
|
6 |
|
&& array() != $this->getParams(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
5 |
|
public function isMethodInjection() |
|
62
|
|
|
{ |
|
63
|
5 |
|
return array() != $this->getMethods() |
|
64
|
5 |
|
&& array() == $this->getParams(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
5 |
|
public function classNotExists() |
|
68
|
|
|
{ |
|
69
|
5 |
|
return !class_exists($this->getClass()); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|