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

Commit 30dc75a

Browse files
committed
Merge branch 'hotfix/206'
Close #206
2 parents fc81dee + dadcf2b commit 30dc75a

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
@@ -18,7 +18,9 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

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

2325
## 3.3.0 - 2017-03-01
2426

src/ServiceManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,12 @@ private function getFactory($name)
668668
if ($lazyLoaded) {
669669
$this->factories[$name] = $factory;
670670
}
671+
// PHP 5.6 fails on 'class::method' callables unless we explode them:
672+
if (PHP_MAJOR_VERSION < 7
673+
&& is_string($factory) && strpos($factory, '::') !== false
674+
) {
675+
$factory = explode('::', $factory);
676+
}
671677
return $factory;
672678
}
673679

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
$this->assertSame($service, $alias);
268268
$this->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)