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

Commit a5cfced

Browse files
authored
Merge pull request #269 from demiankatz/undefined-factory-fix
Undefined $factory notice fix
2 parents ba7069c + b660ae2 commit a5cfced

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 2.7.11 - TBD
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Changed
12+
13+
- Nothing.
14+
15+
### Deprecated
16+
17+
- Nothing.
18+
19+
### Removed
20+
21+
- Nothing.
22+
23+
### Fixed
24+
25+
- [#269](https://github.com/zendframework/zend-servicemanager/pull/269) fixes a
26+
regression whereby using static Callable strings caused an undefined variable
27+
notice.
28+
529
## 2.7.10 - 2017-12-05
630

731
### Added

src/AbstractPluginManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ protected function createServiceViaCallback($callable, $cName, $rName)
355355
} elseif (is_array($callable)) {
356356
// reset both rewinds and returns the value of the first array element
357357
$factory = reset($callable);
358+
} else {
359+
$factory = null;
358360
}
359361

360362
if ($factory instanceof Factory\InvokableFactory) {

test/AbstractPluginManagerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,16 @@ public function testV2v3PluginManager()
437437
$this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo'));
438438
}
439439

440+
public function testStaticFactoryMethod()
441+
{
442+
$pluginManager = new FooPluginManager(new Config([
443+
'factories' => [
444+
'Foo' => 'ZendTest\ServiceManager\TestAsset\FooStaticFactory::createService',
445+
],
446+
]));
447+
$this->assertInstanceOf(TestAsset\Foo::class, $pluginManager->get('foo'));
448+
}
449+
440450
public function testInvokableFactoryHasMutableOptions()
441451
{
442452
$pluginManager = new FooPluginManager($this->serviceManager);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\ServiceManager\TestAsset;
11+
12+
class FooStaticFactory
13+
{
14+
public static function createService()
15+
{
16+
return new Foo;
17+
}
18+
}

0 commit comments

Comments
 (0)