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

Commit

Permalink
Merge branch 'hotfix/92'
Browse files Browse the repository at this point in the history
Close #92
  • Loading branch information
weierophinney committed Feb 1, 2016
2 parents aa89d30 + dfa83b0 commit bec350c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ All notable changes to this project will be documented in this file, in reverse
- [#90](https://github.com/zendframework/zend-servicemanager/pull/90) fixes
several examples in the configuration chapter of the documentation, ensuring
that the signatures are correct.
- [#92](https://github.com/zendframework/zend-servicemanager/pull/92) ensures
that alias resolution is skipped during configuration if no aliases are
present, and forward-ports the test from [#81](https://github.com/zendframework/zend-servicemanager/pull/81)
to validate v2/v3 compatibility for plugin managers.

## 3.0.2 - 2016-01-24

Expand Down
3 changes: 3 additions & 0 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ public function configure(array $config)

if (isset($config['aliases'])) {
$this->aliases = $config['aliases'] + $this->aliases;
}

if (! empty($this->aliases)) {
$this->resolveAliases($this->aliases);
}

Expand Down
7 changes: 7 additions & 0 deletions test/AbstractPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Zend\ServiceManager\ServiceManager;
use ZendTest\ServiceManager\TestAsset\InvokableObject;
use ZendTest\ServiceManager\TestAsset\SimplePluginManager;
use ZendTest\ServiceManager\TestAsset\V2v3PluginManager;

/**
* @covers \Zend\ServiceManager\AbstractPluginManager
Expand Down Expand Up @@ -367,4 +368,10 @@ public function testAbstractFactoryGetsCreationContext()
$pluginManager->addAbstractFactory($abstractFactory->reveal());
$this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo'));
}

public function testAliasPropertyResolves()
{
$pluginManager = new V2v3PluginManager(new ServiceManager());
$this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo'));
}
}
59 changes: 59 additions & 0 deletions test/TestAsset/V2v3PluginManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\ServiceManager\TestAsset;

use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Exception\InvalidServiceException;
use Zend\ServiceManager\Factory\InvokableFactory;

class V2v3PluginManager extends AbstractPluginManager
{
protected $aliases = [
'foo' => InvokableObject::class,
];

protected $factories = [
InvokableObject::class => InvokableFactory::class,
// Legacy (v2) due to alias resolution
'zendtestservicemanagertestassetinvokableobject' => InvokableFactory::class,
];

protected $instanceOf = InvokableObject::class;

protected $shareByDefault = false;

protected $sharedByDefault = false;


public function validate($plugin)
{
if ($plugin instanceof $this->instanceOf) {
return;
}

throw new InvalidServiceException(sprintf(
"'%s' is not an instance of '%s'",
get_class($plugin),
$this->instanceOf
));
}

/**
* {@inheritDoc}
*/
public function validatePlugin($plugin)
{
try {
$this->validate($plugin);
} catch (InvalidServiceException $e) {
throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
}
}
}

0 comments on commit bec350c

Please sign in to comment.