Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 6a83199

Browse files
committed
Removed $checkAbstractFactories flag from has()
The flag breaks the LSP, and requires that a user know how a given service might be configured inside the container. Removing it provides easier interoperability, and removes unexpected false negative lookups.
1 parent 4f88fe7 commit 6a83199

File tree

2 files changed

+7
-36
lines changed

2 files changed

+7
-36
lines changed

src/ServiceManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ public function build($name, array $options = null)
211211
/**
212212
* {@inheritDoc}
213213
*/
214-
public function has($name, $checkAbstractFactories = false)
214+
public function has($name)
215215
{
216216
$name = isset($this->resolvedAliases[$name]) ? $this->resolvedAliases[$name] : $name;
217217
$found = isset($this->services[$name]) || isset($this->factories[$name]);
218218

219-
if ($found || !$checkAbstractFactories) {
219+
if ($found) {
220220
return $found;
221221
}
222222

test/CommonServiceLocatorBehaviorsTrait.php

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,7 @@ public function testCanCreateServiceWithAlias()
156156
$this->assertFalse($serviceManager->has('baz'));
157157
}
158158

159-
public function testCanCheckServiceExistenceWithoutCheckingAbstractFactories()
160-
{
161-
$serviceManager = $this->createContainer([
162-
'factories' => [
163-
stdClass::class => InvokableFactory::class
164-
]
165-
]);
166-
167-
$this->assertTrue($serviceManager->has(stdClass::class));
168-
$this->assertFalse($serviceManager->has(DateTime::class));
169-
}
170-
171-
public function testCanCheckServiceExistenceWithCheckingAbstractFactories()
159+
public function testCheckingServiceExistenceWithChecksAgainstAbstractFactories()
172160
{
173161
$serviceManager = $this->createContainer([
174162
'factories' => [
@@ -179,8 +167,8 @@ public function testCanCheckServiceExistenceWithCheckingAbstractFactories()
179167
]
180168
]);
181169

182-
$this->assertTrue($serviceManager->has(stdClass::class, true));
183-
$this->assertTrue($serviceManager->has(DateTime::class, true));
170+
$this->assertTrue($serviceManager->has(stdClass::class));
171+
$this->assertTrue($serviceManager->has(DateTime::class));
184172
}
185173

186174
public function testBuildNeverSharesInstances()
@@ -322,23 +310,6 @@ public function testHasReturnsTrueIfFactoryIsConfigured()
322310
$this->assertTrue($serviceManager->has(stdClass::class));
323311
}
324312

325-
/**
326-
* @group has
327-
*/
328-
public function testHasDoesNotCheckAbstractFactoriesByDefault()
329-
{
330-
$serviceManager = $this->createContainer([
331-
'factories' => [
332-
stdClass::class => InvokableFactory::class,
333-
],
334-
'abstract_factories' => [
335-
new SimpleAbstractFactory(),
336-
],
337-
]);
338-
339-
$this->assertFalse($serviceManager->has(DateTime::class));
340-
}
341-
342313
public function abstractFactories()
343314
{
344315
return [
@@ -351,15 +322,15 @@ public function abstractFactories()
351322
* @group has
352323
* @dataProvider abstractFactories
353324
*/
354-
public function testHasCanCheckAbstractFactoriesWhenRequested($abstractFactory, $expected)
325+
public function testHasChecksAgainstAbstractFactories($abstractFactory, $expected)
355326
{
356327
$serviceManager = $this->createContainer([
357328
'abstract_factories' => [
358329
$abstractFactory,
359330
],
360331
]);
361332

362-
$this->assertSame($expected, $serviceManager->has(DateTime::class, true));
333+
$this->assertSame($expected, $serviceManager->has(DateTime::class));
363334
}
364335

365336
/**

0 commit comments

Comments
 (0)