-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathService.php
More file actions
176 lines (155 loc) · 3.23 KB
/
Service.php
File metadata and controls
176 lines (155 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
namespace Rad\DependencyInjection;
/**
* Service
*
* @package Rad\DependencyInjection
*/
class Service
{
protected $name;
protected $definition;
protected $locked = false;
protected $shared = false;
protected $resolved = false;
protected $resolvedDefinition;
/**
* Rad\DependencyInjection\Service constructor
*
* @param string $name
* @param callable|object|string $definition
* @param bool $shared
* @param bool $locked
*/
public function __construct($name, $definition, $shared = false, $locked = false)
{
$this->name = $name;
$this->definition = $definition;
$this->shared = (bool)$shared;
$this->locked = (bool)$locked;
}
/**
* Set service name
*
* @param string $name
*
* @return Service
*/
public function setName($name)
{
$this->name = (string)$name;
return $this;
}
/**
* Get service name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set service definition
*
* @param callable|object|string $definition
*
* @return Service
*/
public function setDefinition($definition)
{
$this->definition = $definition;
return $this;
}
/**
* Get service definition
*
* @return callable|object|string
*/
public function getDefinition()
{
return $this->definition;
}
/**
* Set locked
*
* @param boolean $locked
*
* @return Service
*/
public function setLocked($locked)
{
$this->locked = (bool)$locked;
return $this;
}
/**
* Check service is locked
*
* @return boolean
*/
public function isLocked()
{
return $this->locked;
}
/**
* Set shared
*
* @param boolean $shared
*
* @return Service
*/
public function setShared($shared)
{
$this->shared = (bool)$shared;
return $this;
}
/**
* Check service is shared
*
* @return boolean
*/
public function isShared()
{
return $this->shared;
}
/**
* Set resolved
*
* @param boolean $resolved
*
* @return Service
*/
public function setResolved($resolved)
{
$this->resolved = (bool)$resolved;
return $this;
}
/**
* Check service is resolved
*
* @return boolean
*/
public function isResolved()
{
return $this->resolved;
}
/**
* Resolve service
*
* @param Container $container
* @param array $args
*
* @return mixed|object
* @throws Exception
*/
public function resolve(Container $container, array $args = [])
{
if ($this->resolvedDefinition && $this->shared === true) {
return $this->resolvedDefinition;
}
$definitionResolver = new DefinitionResolver($container);
$this->resolvedDefinition = $definitionResolver->resolver($this->definition, $args);
$this->resolved = true;
return $this->resolvedDefinition;
}
}