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

Commit ae43877

Browse files
committed
Merge branch 'hotfix/206' into develop
Forward port #206
2 parents 087ea0d + dadcf2b commit ae43877

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ All notable changes to this project will be documented in this file, in reverse
3636

3737
### Fixed
3838

39-
- Nothing.
39+
- [#206](https://github.com/zendframework/zend-servicemanager/pull/206) fixes an
40+
issue where by callables in `Class::method` notation were not being honored
41+
under PHP 5.6.
4042

4143
## 3.3.0 - 2017-03-01
4244

src/ServiceManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,12 @@ private function getFactory($name)
684684
if ($lazyLoaded) {
685685
$this->factories[$name] = $factory;
686686
}
687+
// PHP 5.6 fails on 'class::method' callables unless we explode them:
688+
if (PHP_MAJOR_VERSION < 7
689+
&& is_string($factory) && strpos($factory, '::') !== false
690+
) {
691+
$factory = explode('::', $factory);
692+
}
687693
return $factory;
688694
}
689695

test/ServiceManagerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,20 @@ public function testSetAliasShouldWorkWithRecursiveAlias()
267267
self::assertSame($service, $alias);
268268
self::assertSame($service, $headAlias);
269269
}
270+
271+
public static function sampleFactory()
272+
{
273+
return new stdClass();
274+
}
275+
276+
public function testFactoryMayBeStaticMethodDescribedByCallableString()
277+
{
278+
$config = [
279+
'factories' => [
280+
stdClass::class => 'ZendTest\ServiceManager\ServiceManagerTest::sampleFactory',
281+
]
282+
];
283+
$serviceManager = new SimpleServiceManager($config);
284+
$this->assertEquals(stdClass::class, get_class($serviceManager->get(stdClass::class)));
285+
}
270286
}

0 commit comments

Comments
 (0)