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

Commit bec350c

Browse files
committed
Merge branch 'hotfix/92'
Close #92
2 parents aa89d30 + dfa83b0 commit bec350c

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ All notable changes to this project will be documented in this file, in reverse
2424
- [#90](https://github.com/zendframework/zend-servicemanager/pull/90) fixes
2525
several examples in the configuration chapter of the documentation, ensuring
2626
that the signatures are correct.
27+
- [#92](https://github.com/zendframework/zend-servicemanager/pull/92) ensures
28+
that alias resolution is skipped during configuration if no aliases are
29+
present, and forward-ports the test from [#81](https://github.com/zendframework/zend-servicemanager/pull/81)
30+
to validate v2/v3 compatibility for plugin managers.
2731

2832
## 3.0.2 - 2016-01-24
2933

src/ServiceManager.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ public function configure(array $config)
342342

343343
if (isset($config['aliases'])) {
344344
$this->aliases = $config['aliases'] + $this->aliases;
345+
}
346+
347+
if (! empty($this->aliases)) {
345348
$this->resolveAliases($this->aliases);
346349
}
347350

test/AbstractPluginManagerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Zend\ServiceManager\ServiceManager;
2323
use ZendTest\ServiceManager\TestAsset\InvokableObject;
2424
use ZendTest\ServiceManager\TestAsset\SimplePluginManager;
25+
use ZendTest\ServiceManager\TestAsset\V2v3PluginManager;
2526

2627
/**
2728
* @covers \Zend\ServiceManager\AbstractPluginManager
@@ -367,4 +368,10 @@ public function testAbstractFactoryGetsCreationContext()
367368
$pluginManager->addAbstractFactory($abstractFactory->reveal());
368369
$this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo'));
369370
}
371+
372+
public function testAliasPropertyResolves()
373+
{
374+
$pluginManager = new V2v3PluginManager(new ServiceManager());
375+
$this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo'));
376+
}
370377
}

test/TestAsset/V2v3PluginManager.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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) 2016 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+
use Zend\ServiceManager\AbstractPluginManager;
13+
use Zend\ServiceManager\Exception\InvalidServiceException;
14+
use Zend\ServiceManager\Factory\InvokableFactory;
15+
16+
class V2v3PluginManager extends AbstractPluginManager
17+
{
18+
protected $aliases = [
19+
'foo' => InvokableObject::class,
20+
];
21+
22+
protected $factories = [
23+
InvokableObject::class => InvokableFactory::class,
24+
// Legacy (v2) due to alias resolution
25+
'zendtestservicemanagertestassetinvokableobject' => InvokableFactory::class,
26+
];
27+
28+
protected $instanceOf = InvokableObject::class;
29+
30+
protected $shareByDefault = false;
31+
32+
protected $sharedByDefault = false;
33+
34+
35+
public function validate($plugin)
36+
{
37+
if ($plugin instanceof $this->instanceOf) {
38+
return;
39+
}
40+
41+
throw new InvalidServiceException(sprintf(
42+
"'%s' is not an instance of '%s'",
43+
get_class($plugin),
44+
$this->instanceOf
45+
));
46+
}
47+
48+
/**
49+
* {@inheritDoc}
50+
*/
51+
public function validatePlugin($plugin)
52+
{
53+
try {
54+
$this->validate($plugin);
55+
} catch (InvalidServiceException $e) {
56+
throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)