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

Commit 5347f90

Browse files
committed
Merge branch 'hotfix/updated-dependencies'
Close #52
2 parents d9ad104 + 464fb5b commit 5347f90

12 files changed

+102
-63
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ before_install:
5353
- if [[ $ZEND_EVENTMANAGER_VERSION == '' ]]; then composer require --no-update "zendframework/zend-eventmanager:^3.0" ; fi
5454
- if [[ $ZEND_SERVICEMANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$ZEND_SERVICEMANAGER_VERSION" ; fi
5555
- if [[ $ZEND_SERVICEMANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi
56-
- if [[ $ZEND_SERVICEMANAGER_VERSION == '' ]]; then composer remove --dev --no-update zendframework/zend-modulemanager zendframework/zend-mvc zendframework/zend-session ; fi
5756

5857
install:
5958
- travis_retry composer install --no-interaction --ignore-platform-reqs

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
## 2.6.4 - TBD
5+
## 2.6.4 - 2016-03-02
66

77
### Added
88

@@ -18,7 +18,15 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

21-
- Nothing.
21+
- [#52](https://github.com/zendframework/zend-view/pull/52) fixes several issues
22+
detected after re-enabling tests skipped when executed against
23+
zend-servicemanager/zend-eventmanager v3:
24+
- `HelperPluginManager` now implements an `EventManagerAware` initializer.
25+
- `Zend\View\Helper\Navigation\AbstractHelper` now contains logic to ensure
26+
that when an `EventManager` instance is lazy-loaded, it composes a
27+
`SharedEventManager`.
28+
- The `FlashMessenger` factory now correctly pulls the `config` service, not
29+
the `Config` service (former is both backwards- and forwards compatible).
2230

2331
## 2.6.3 - 2016-02-22
2432

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
"zendframework/zend-i18n": "^2.6",
3131
"zendframework/zend-json": "^2.6.1",
3232
"zendframework/zend-log": "^2.7",
33-
"zendframework/zend-modulemanager": "^2.5",
34-
"zendframework/zend-mvc": "^2.6.1",
33+
"zendframework/zend-modulemanager": "^2.7.1",
34+
"zendframework/zend-mvc": "^2.7",
3535
"zendframework/zend-navigation": "^2.5",
3636
"zendframework/zend-paginator": "^2.5",
3737
"zendframework/zend-permissions-acl": "^2.6",
3838
"zendframework/zend-serializer": "^2.6.1",
39-
"zendframework/zend-session": "^2.5",
39+
"zendframework/zend-session": "^2.6.2",
4040
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
4141
"zendframework/zend-uri": "^2.5",
4242
"fabpot/php-cs-fixer": "1.7.*",

src/Helper/Navigation/AbstractHelper.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
use Interop\Container\ContainerInterface;
1313
use RecursiveIteratorIterator;
14+
use ReflectionClass;
1415
use ReflectionProperty;
1516
use Zend\EventManager\EventManager;
1617
use Zend\EventManager\EventManagerAwareInterface;
1718
use Zend\EventManager\EventManagerInterface;
19+
use Zend\EventManager\SharedEventManager;
1820
use Zend\I18n\Translator\TranslatorInterface as Translator;
1921
use Zend\I18n\Translator\TranslatorAwareInterface;
2022
use Zend\Navigation;
@@ -524,7 +526,7 @@ public function setEventManager(EventManagerInterface $events)
524526
public function getEventManager()
525527
{
526528
if (null === $this->events) {
527-
$this->setEventManager(new EventManager());
529+
$this->setEventManager($this->createEventManager());
528530
}
529531

530532
return $this->events;
@@ -960,4 +962,22 @@ protected function setDefaultListeners()
960962
['Zend\View\Helper\Navigation\Listener\AclListener', 'accept']
961963
);
962964
}
965+
966+
/**
967+
* Create and return an event manager instance.
968+
*
969+
* Ensures that the returned event manager has a shared manager
970+
* composed.
971+
*
972+
* @return EventManager
973+
*/
974+
private function createEventManager()
975+
{
976+
$r = new ReflectionClass(EventManager::class);
977+
if ($r->hasMethod('setSharedManager')) {
978+
return new EventManager();
979+
}
980+
981+
return new EventManager(new SharedEventManager());
982+
}
963983
}

src/Helper/Service/FlashMessengerFactory.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __invoke(ContainerInterface $container, $name, array $options =
3636

3737
$helper->setPluginFlashMessenger($flashMessenger);
3838

39-
$config = $container->get('Config');
39+
$config = $container->get('config');
4040
if (isset($config['view_helper_config']['flashmessenger'])) {
4141
$configHelper = $config['view_helper_config']['flashmessenger'];
4242
if (isset($configHelper['message_open_format'])) {
@@ -54,13 +54,15 @@ public function __invoke(ContainerInterface $container, $name, array $options =
5454
}
5555

5656
/**
57-
* Create service
57+
* Create service (v2)
5858
*
59-
* @param ServiceLocatorInterface $serviceLocator
60-
* @return mixed
59+
* @param ServiceLocatorInterface $container
60+
* @param string $normalizedName
61+
* @param string $requestedName
62+
* @return FlashMessenger
6163
*/
62-
public function createService(ServiceLocatorInterface $serviceLocator, $rName = null, $cName = null)
64+
public function createService(ServiceLocatorInterface $container, $normalizedName = null, $requestedName = null)
6365
{
64-
return $this($serviceLocator, $cName);
66+
return $this($container, $requestedName);
6567
}
6668
}

src/HelperPluginManager.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
namespace Zend\View;
1111

1212
use Interop\Container\ContainerInterface;
13+
use Zend\EventManager\EventManagerAwareInterface;
14+
use Zend\EventManager\SharedEventManagerInterface;
1315
use Zend\I18n\Translator\TranslatorAwareInterface;
1416
use Zend\ServiceManager\AbstractPluginManager;
1517
use Zend\ServiceManager\Exception\InvalidServiceException;
@@ -243,6 +245,7 @@ public function __construct($configOrContainerInstance = null, array $v3config =
243245
{
244246
$this->initializers[] = [$this, 'injectRenderer'];
245247
$this->initializers[] = [$this, 'injectTranslator'];
248+
$this->initializers[] = [$this, 'injectEventManager'];
246249

247250
parent::__construct($configOrContainerInstance, $v3config);
248251
}
@@ -340,6 +343,44 @@ public function injectTranslator($first, $second)
340343
}
341344
}
342345

346+
/**
347+
* Inject a helper instance with the registered event manager
348+
*
349+
* @param ContainerInterface|Helper\HelperInterface $first helper instance
350+
* under zend-servicemanager v2, ContainerInterface under v3.
351+
* @param ContainerInterface|Helper\HelperInterface $second
352+
* ContainerInterface under zend-servicemanager v3, helper instance
353+
* under v2. Ignored regardless.
354+
*/
355+
public function injectEventManager($first, $second)
356+
{
357+
if ($first instanceof ContainerInterface) {
358+
// v3 usage
359+
$container = $first;
360+
$helper = $second;
361+
} else {
362+
// v2 usage; grab the parent container
363+
$container = $second->getServiceLocator();
364+
$helper = $first;
365+
}
366+
367+
if (! $container) {
368+
// Under zend-navigation v2.5, the navigation PluginManager is
369+
// always lazy-loaded, which means it never has a parent
370+
// container.
371+
return;
372+
}
373+
374+
if (! $helper instanceof EventManagerAwareInterface) {
375+
return;
376+
}
377+
378+
$events = $helper->getEventManager();
379+
if (! $events || ! $events->getSharedManager() instanceof SharedEventManagerInterface) {
380+
$helper->setEventManager($container->get('EventManager'));
381+
}
382+
}
383+
343384
/**
344385
* Validate the plugin is of the expected type (v3).
345386
*

test/Helper/Navigation/AbstractTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,6 @@ abstract class AbstractTest extends \PHPUnit_Framework_TestCase
8686
*/
8787
protected function setUp()
8888
{
89-
if (! class_exists(ServiceManagerConfig::class)) {
90-
$this->markTestSkipped(
91-
'Skipping zend-mvc-related tests until that component is updated '
92-
. 'to be forwards-compatible with zend-eventmanager, zend-stdlib, '
93-
. 'and zend-servicemanager v3.'
94-
);
95-
}
96-
9789
$cwd = __DIR__;
9890

9991
// read navigation config

test/Helper/Navigation/BreadcrumbsTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public function testHelperEntryPointWithContainerParam()
6767

6868
public function testHelperEntryPointWithContainerStringParam()
6969
{
70-
$pm = new \Zend\View\HelperPluginManager();
71-
$pm->setServiceLocator($this->serviceManager);
70+
$pm = new \Zend\View\HelperPluginManager($this->serviceManager);
7271
$this->_helper->setServiceLocator($pm);
7372

7473
$returned = $this->_helper->__invoke('nav1');

test/Helper/Navigation/NavigationTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function testAcceptAclShouldReturnGracefullyWithUnknownResource()
7575
public function testShouldProxyToMenuHelperByDefault()
7676
{
7777
$this->_helper->setContainer($this->_nav1);
78+
$this->_helper->setServiceLocator(new ServiceManager());
7879

7980
// result
8081
$expected = $this->_getExpected('menu/default1.html');
@@ -95,6 +96,7 @@ public function testInjectingContainer()
9596
{
9697
// setup
9798
$this->_helper->setContainer($this->_nav2);
99+
$this->_helper->setServiceLocator(new ServiceManager());
98100
$expected = [
99101
'menu' => $this->_getExpected('menu/default2.html'),
100102
'breadcrumbs' => $this->_getExpected('bc/default.html')
@@ -112,6 +114,7 @@ public function testInjectingContainer()
112114
public function testDisablingContainerInjection()
113115
{
114116
// setup
117+
$this->_helper->setServiceLocator(new ServiceManager());
115118
$this->_helper->setInjectContainer(false);
116119
$this->_helper->menu()->setContainer(null);
117120
$this->_helper->breadcrumbs()->setContainer(null);
@@ -132,6 +135,7 @@ public function testDisablingContainerInjection()
132135

133136
public function testMultipleNavigationsAndOneMenuDisplayedTwoTimes()
134137
{
138+
$this->_helper->setServiceLocator(new ServiceManager());
135139
$expected = $this->_helper->setContainer($this->_nav1)->menu()->getContainer();
136140
$this->_helper->setContainer($this->_nav2)->menu()->getContainer();
137141
$actual = $this->_helper->setContainer($this->_nav1)->menu()->getContainer();
@@ -161,6 +165,7 @@ public function testInjectingAcl()
161165
$acl = $this->_getAcl();
162166
$this->_helper->setAcl($acl['acl']);
163167
$this->_helper->setRole($acl['role']);
168+
$this->_helper->setServiceLocator(new ServiceManager());
164169

165170
$expected = $this->_getExpected('menu/acl.html');
166171
$actual = $this->_helper->render();
@@ -175,6 +180,7 @@ public function testDisablingAclInjection()
175180
$this->_helper->setAcl($acl['acl']);
176181
$this->_helper->setRole($acl['role']);
177182
$this->_helper->setInjectAcl(false);
183+
$this->_helper->setServiceLocator(new ServiceManager());
178184

179185
$expected = $this->_getExpected('menu/default1.html');
180186
$actual = $this->_helper->render();
@@ -189,6 +195,7 @@ public function testInjectingTranslator()
189195
}
190196

191197
$this->_helper->setTranslator($this->_getTranslator());
198+
$this->_helper->setServiceLocator(new ServiceManager());
192199

193200
$expected = $this->_getExpected('menu/translated.html');
194201
$actual = $this->_helper->render();
@@ -200,6 +207,7 @@ public function testDisablingTranslatorInjection()
200207
{
201208
$this->_helper->setTranslator($this->_getTranslator());
202209
$this->_helper->setInjectTranslator(false);
210+
$this->_helper->setServiceLocator(new ServiceManager());
203211

204212
$expected = $this->_getExpected('menu/default1.html');
205213
$actual = $this->_helper->render();
@@ -230,6 +238,7 @@ public function testSpecifyingDefaultProxy()
230238
$actual = [];
231239

232240
// result
241+
$this->_helper->setServiceLocator(new ServiceManager());
233242
$this->_helper->setDefaultProxy('breadcrumbs');
234243
$actual['breadcrumbs'] = $this->_helper->render($this->_nav1);
235244
$this->_helper->setDefaultProxy('menu');
@@ -416,6 +425,7 @@ public function testPageIdShouldBeNormalized()
416425
. ' </li>' . $nl
417426
. '</ul>';
418427

428+
$this->_helper->setServiceLocator(new ServiceManager());
419429
$actual = $this->_helper->render($container);
420430

421431
$this->assertEquals($expected, $actual);
@@ -440,6 +450,7 @@ public function testRenderInvisibleItem()
440450
]
441451
]);
442452

453+
$this->_helper->setServiceLocator(new ServiceManager());
443454
$render = $this->_helper->menu()->render($container);
444455

445456
$this->assertNotContains('p2', $render);
@@ -558,7 +569,7 @@ public function testMultipleNavigationsWithSameHelperAndSameContainer()
558569

559570
public function testSetPluginManagerAndView()
560571
{
561-
$pluginManager = new Navigation\PluginManager();
572+
$pluginManager = new Navigation\PluginManager(new ServiceManager());
562573
$view = new PhpRenderer();
563574

564575
$helper = new $this->_helperName;

test/Helper/UrlIntegrationTest.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ class UrlIntegrationTest extends \PHPUnit_Framework_TestCase
2424
{
2525
protected function setUp()
2626
{
27-
if (! class_exists(PluginFlashMessenger::class)) {
28-
$this->markTestSkipped(
29-
'Skipping zend-mvc-related tests until that component is updated '
30-
. 'to be forwards-compatible with zend-eventmanager, zend-stdlib, '
31-
. 'and zend-servicemanager v3.'
32-
);
33-
}
34-
35-
3627
$config = [
3728
'router' => [
3829
'routes' => [
@@ -66,12 +57,12 @@ protected function setUp()
6657

6758
$serviceConfig = $this->readAttribute(new ServiceListenerFactory, 'defaultServiceConfig');
6859

69-
$this->serviceManager = new ServiceManager(new ServiceManagerConfig($serviceConfig));
70-
$this->serviceManager
71-
->setAllowOverride(true)
72-
->setService('Config', $config)
73-
->setAlias('Configuration', 'Config')
74-
->setAllowOverride(false);
60+
$this->serviceManager = new ServiceManager();
61+
(new ServiceManagerConfig($serviceConfig))->configureServiceManager($this->serviceManager);
62+
$this->serviceManager->setAllowOverride(true);
63+
$this->serviceManager->setService('config', $config);
64+
$this->serviceManager->setAlias('Configure', 'config');
65+
$this->serviceManager->setAllowOverride(false);
7566
}
7667

7768
public function testUrlHelperWorksUnderNormalHttpParadigms()

0 commit comments

Comments
 (0)