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

Commit 5ae2199

Browse files
committed
Merge branch 'weierophinney-feature/48' into develop
2 parents 4f88fe7 + ef7d0e1 commit 5ae2199

File tree

3 files changed

+7
-72
lines changed

3 files changed

+7
-72
lines changed

doc/book/migration.md

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -428,42 +428,6 @@ $alsoBetween = $container->build(Between::class, [
428428
The above two validators would be different instances, with their own
429429
configuration.
430430

431-
### has() no longer checks abstract factories by default
432-
433-
In v2, `has()` would also check abstract factories to see if any would match the
434-
service. Depending on the number of abstract factories present, this can be an
435-
expensive operation. As a result, in v3, we no longer check abstract factories
436-
*by default*.
437-
438-
However, you *can* tell the Service Manager to check them by passing an optional
439-
second argument to the method; a boolean is expected, and a `true` value
440-
indicates that abstract factories should be checked:
441-
442-
```php
443-
$container = new ServiceManager([
444-
'factories' => [
445-
'MyClass' => 'MyClass',
446-
],
447-
'abstract_factories' => [
448-
'AbstractFactoryThatAlwaysResolves',
449-
],
450-
]);
451-
```
452-
453-
Assuming that `AbstractFactoryThatAlwaysResolves` will resolve any service
454-
(don't ever do this!), the following behavior is expected:
455-
456-
```php
457-
$has = $container->has('MyClass'); // always true; factory is defined
458-
// for the service.
459-
$has = $container->has('AnotherClass'); // false; no factory is defined
460-
// for the service, and not
461-
// looking in abstract factories.
462-
$has = $container->has('AnotherClass', true); // true; no factory is defined for
463-
// the service, but we indicated
464-
// we'd look in abstract factories.
465-
```
466-
467431
## Factories
468432

469433
All factory interfaces were moved to a `Factory` subnamespace. Additionally, the

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)