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 hasParams() |
20
|
|
|
{ |
21
|
6 |
|
return isset($this->params['services'][$this->getName()]['params']); |
22
|
|
|
} |
23
|
|
|
|
24
|
6 |
|
public function getParams() |
25
|
|
|
{ |
26
|
6 |
|
return $this->hasParams() |
27
|
6 |
|
? $this->params['services'][$this->getName()]['params'] |
28
|
6 |
|
: array(); |
29
|
|
|
} |
30
|
|
|
|
31
|
6 |
|
public function hasMethods() |
32
|
|
|
{ |
33
|
6 |
|
return isset($this->params['services'][$this->getName()]['methods']); |
34
|
|
|
} |
35
|
|
|
|
36
|
6 |
|
public function getMethods() |
37
|
|
|
{ |
38
|
6 |
|
return $this->hasMethods() |
39
|
6 |
|
? $this->params['services'][$this->getName()]['methods'] |
40
|
6 |
|
: array(); |
41
|
|
|
} |
42
|
|
|
|
43
|
6 |
|
public function getClass() |
44
|
|
|
{ |
45
|
6 |
|
$argument = Argument::fromString($this->params['name']); |
46
|
6 |
|
$serviceName = $argument->getServiceName(); |
47
|
6 |
|
return $this->params['services'][$serviceName]['class']; |
48
|
|
|
} |
49
|
|
|
|
50
|
2 |
|
public function getServicesConfiguration() |
51
|
|
|
{ |
52
|
2 |
|
return $this->params['services']; |
53
|
|
|
} |
54
|
|
|
|
55
|
6 |
|
public function getName() |
56
|
|
|
{ |
57
|
6 |
|
return $this->params['name']; |
58
|
|
|
} |
59
|
|
|
|
60
|
6 |
|
public function hasMethodInjection() |
61
|
|
|
{ |
62
|
6 |
|
return array() == $this->getMethods() |
63
|
6 |
|
&& array() != $this->getParams(); |
64
|
|
|
} |
65
|
|
|
|
66
|
6 |
|
public function hasSimpleInjection() |
67
|
|
|
{ |
68
|
6 |
|
return array() != $this->getMethods() |
69
|
6 |
|
&& array() == $this->getParams(); |
70
|
|
|
} |
71
|
|
|
|
72
|
6 |
|
public function classNotExists() |
73
|
|
|
{ |
74
|
6 |
|
return !class_exists($this->getClass()); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|