This repository was archived by the owner on Feb 6, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,16 @@ public function get($name)
166
166
return $ this ->services [$ requestedName ];
167
167
}
168
168
169
+ // Next, if the alias should be shared, and we have cached the resolved
170
+ // service, use it.
171
+ if ($ requestedName !== $ name
172
+ && (! isset ($ this ->shared [$ requestedName ]) || $ this ->shared [$ requestedName ])
173
+ && isset ($ this ->services [$ name ])
174
+ ) {
175
+ $ this ->services [$ requestedName ] = $ this ->services [$ name ];
176
+ return $ this ->services [$ name ];
177
+ }
178
+
169
179
// At this point, we need to create the instance; we use the resolved
170
180
// name for that.
171
181
$ object = $ this ->doCreate ($ name );
Original file line number Diff line number Diff line change @@ -221,4 +221,23 @@ public function testSharedServicesReferencingAliasShouldBeHonored()
221
221
222
222
$ this ->assertNotSame ($ instance1 , $ instance2 );
223
223
}
224
+
225
+ public function testAliasToAnExplicitServiceShouldWork ()
226
+ {
227
+ $ config = [
228
+ 'aliases ' => [
229
+ 'Invokable ' => InvokableObject::class,
230
+ ],
231
+ 'services ' => [
232
+ InvokableObject::class => new InvokableObject (),
233
+ ],
234
+ ];
235
+
236
+ $ serviceManager = new ServiceManager ($ config );
237
+
238
+ $ service = $ serviceManager ->get (InvokableObject::class);
239
+ $ alias = $ serviceManager ->get ('Invokable ' );
240
+
241
+ $ this ->assertSame ($ service , $ alias );
242
+ }
224
243
}
You can’t perform that action at this time.
0 commit comments