From e8d73e1c9ab70506ee93c7186aa7ec0ccbe2d704 Mon Sep 17 00:00:00 2001 From: AndrolGenhald Date: Tue, 14 Jun 2016 15:55:29 -0500 Subject: [PATCH 1/5] Added test for issue #126 --- test/AbstractPluginManagerTest.php | 15 +++++++++++++++ test/TestAsset/Baz.php | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/TestAsset/Baz.php diff --git a/test/AbstractPluginManagerTest.php b/test/AbstractPluginManagerTest.php index 1787e60b..0661cb03 100644 --- a/test/AbstractPluginManagerTest.php +++ b/test/AbstractPluginManagerTest.php @@ -12,11 +12,13 @@ use Interop\Container\ContainerInterface; use ReflectionClass; use ReflectionObject; +use Zend\ServiceManager\AbstractPluginManager; use Zend\ServiceManager\Config; use Zend\ServiceManager\Exception\InvalidArgumentException; use Zend\ServiceManager\Exception\RuntimeException; use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\ServiceManager; +use ZendTest\ServiceManager\TestAsset\Baz; use ZendTest\ServiceManager\TestAsset\FooPluginManager; use ZendTest\ServiceManager\TestAsset\InvokableObject; use ZendTest\ServiceManager\TestAsset\MockSelfReturningDelegatorFactory; @@ -138,6 +140,19 @@ public function testCallableObjectWithMutableCreationOptions() $method->invoke($this->pluginManager, $callable, 'foo', 'bar'); } + public function testInvokableFactoryOptionsAffectMultipleInstantiations() + { + /** @var $pluginManager AbstractPluginManager */ + $pluginManager = $this->getMockForAbstractClass('Zend\ServiceManager\AbstractPluginManager'); + $pluginManager->setFactory(Baz::class, InvokableFactory::class); + $pluginManager->setShared(Baz::class, false); + $creationOptions = ['key1' => 'value1']; + $plugin1 = $pluginManager->get(Baz::class, $creationOptions); + $plugin2 = $pluginManager->get(Baz::class); + + $this->assertNotEquals($plugin1, $plugin2); + } + public function testValidatePluginIsCalledWithDelegatorFactoryIfItsAService() { $pluginManager = $this->getMockForAbstractClass('Zend\ServiceManager\AbstractPluginManager'); diff --git a/test/TestAsset/Baz.php b/test/TestAsset/Baz.php new file mode 100644 index 00000000..d0285ab1 --- /dev/null +++ b/test/TestAsset/Baz.php @@ -0,0 +1,20 @@ +options = $options; + } +} From c56f494d0948697ac2867d0b2aa4eb877a395c37 Mon Sep 17 00:00:00 2001 From: AndrolGenhald Date: Tue, 14 Jun 2016 15:56:45 -0500 Subject: [PATCH 2/5] AbstractPluginManager always call setCreationOptions on factory --- src/AbstractPluginManager.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/AbstractPluginManager.php b/src/AbstractPluginManager.php index c6bd9ac5..8943b6d3 100644 --- a/src/AbstractPluginManager.php +++ b/src/AbstractPluginManager.php @@ -319,12 +319,12 @@ protected function createServiceViaCallback($callable, $cName, $rName) } // duck-type MutableCreationOptionsInterface for forward compatibility - if (isset($factory) - && method_exists($factory, 'setCreationOptions') - && is_array($this->creationOptions) - && !empty($this->creationOptions) - ) { - $factory->setCreationOptions($this->creationOptions); + if (isset($factory) && method_exists($factory, 'setCreationOptions')) { + if (is_array($this->creationOptions)) { + $factory->setCreationOptions($this->creationOptions); + } else { + $factory->setCreationOptions([]); + } } return parent::createServiceViaCallback($callable, $cName, $rName); From 2e8bc1292a6527daf2b1986fb78e2124799406eb Mon Sep 17 00:00:00 2001 From: AndrolGenhald Date: Tue, 14 Jun 2016 18:52:53 -0500 Subject: [PATCH 3/5] Added special case to AbstractPluginManager for InvokableFactory --- src/AbstractPluginManager.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/AbstractPluginManager.php b/src/AbstractPluginManager.php index 8943b6d3..59200381 100644 --- a/src/AbstractPluginManager.php +++ b/src/AbstractPluginManager.php @@ -11,6 +11,7 @@ use Interop\Container\ContainerInterface; use Exception as BaseException; +use Zend\ServiceManager\Factory\InvokableFactory; /** * ServiceManager implementation for managing plugins @@ -319,12 +320,14 @@ protected function createServiceViaCallback($callable, $cName, $rName) } // duck-type MutableCreationOptionsInterface for forward compatibility - if (isset($factory) && method_exists($factory, 'setCreationOptions')) { - if (is_array($this->creationOptions)) { - $factory->setCreationOptions($this->creationOptions); - } else { - $factory->setCreationOptions([]); - } + if (isset($factory) + && method_exists($factory, 'setCreationOptions') + && is_array($this->creationOptions) + && !empty($this->creationOptions) + ) { + $factory->setCreationOptions($this->creationOptions); + } elseif ($factory instanceof InvokableFactory) { + $factory->setCreationOptions([]); } return parent::createServiceViaCallback($callable, $cName, $rName); From 6fb009c43f40f497275ef7fdf1a5c7c0ebd78f44 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 1 Sep 2016 14:01:01 -0500 Subject: [PATCH 4/5] Remove unneeded import - resolve the class relative to the current namespace --- src/AbstractPluginManager.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AbstractPluginManager.php b/src/AbstractPluginManager.php index 59200381..4d2781ed 100644 --- a/src/AbstractPluginManager.php +++ b/src/AbstractPluginManager.php @@ -11,7 +11,6 @@ use Interop\Container\ContainerInterface; use Exception as BaseException; -use Zend\ServiceManager\Factory\InvokableFactory; /** * ServiceManager implementation for managing plugins @@ -326,7 +325,7 @@ protected function createServiceViaCallback($callable, $cName, $rName) && !empty($this->creationOptions) ) { $factory->setCreationOptions($this->creationOptions); - } elseif ($factory instanceof InvokableFactory) { + } elseif ($factory instanceof Factory\InvokableFactory) { $factory->setCreationOptions([]); } From 24aa9be08212f7f73caf5aa3c363fcbdf0d489f6 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 1 Sep 2016 14:03:04 -0500 Subject: [PATCH 5/5] Added CHANGELOG for #127 --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b8a7ff4..8539a4c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.7.7 - TBD +## 2.7.7 - 2016-09-01 ### Added @@ -18,7 +18,10 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#127](https://github.com/zendframework/zend-servicemanager/pull/127) fixes + how the `AbstractPluingManager` handles `$options` arrays passed when + retrieving a plugin when that plugin resolves to the `InvokableFactory`, + ensuring subsequent calls with different options are created correctly. ## 2.7.6 - 2016-04-27