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

Commit

Permalink
Merge pull request #269 from demiankatz/undefined-factory-fix
Browse files Browse the repository at this point in the history
Undefined $factory notice fix
  • Loading branch information
Ocramius authored Jun 22, 2018
2 parents ba7069c + b660ae2 commit a5cfced
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

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

## 2.7.11 - TBD

### Added

- Nothing.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- [#269](https://github.com/zendframework/zend-servicemanager/pull/269) fixes a
regression whereby using static Callable strings caused an undefined variable
notice.

## 2.7.10 - 2017-12-05

### Added
Expand Down
2 changes: 2 additions & 0 deletions src/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ protected function createServiceViaCallback($callable, $cName, $rName)
} elseif (is_array($callable)) {
// reset both rewinds and returns the value of the first array element
$factory = reset($callable);
} else {
$factory = null;
}

if ($factory instanceof Factory\InvokableFactory) {
Expand Down
10 changes: 10 additions & 0 deletions test/AbstractPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,16 @@ public function testV2v3PluginManager()
$this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo'));
}

public function testStaticFactoryMethod()
{
$pluginManager = new FooPluginManager(new Config([
'factories' => [
'Foo' => 'ZendTest\ServiceManager\TestAsset\FooStaticFactory::createService',
],
]));
$this->assertInstanceOf(TestAsset\Foo::class, $pluginManager->get('foo'));
}

public function testInvokableFactoryHasMutableOptions()
{
$pluginManager = new FooPluginManager($this->serviceManager);
Expand Down
18 changes: 18 additions & 0 deletions test/TestAsset/FooStaticFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\ServiceManager\TestAsset;

class FooStaticFactory
{
public static function createService()
{
return new Foo;
}
}

0 comments on commit a5cfced

Please sign in to comment.