Skip to content
This repository

Adds an alias for ModuleManager and removes the duplicate service defini... #5146

Closed
wants to merge 2 commits into from

2 participants

Percy Hatcherson Matthew Weier O'Phinney
This page is out of date. Refresh to see the latest.
4 library/Zend/ModuleManager/Listener/LocatorRegistrationListener.php
@@ -69,10 +69,12 @@ public function onLoadModules(Event $e)
69 69 // Shared instance for module manager
70 70 $events->attach('Zend\Mvc\Application', MvcEvent::EVENT_BOOTSTRAP, function ($e) use ($moduleManager) {
71 71 $moduleClassName = get_class($moduleManager);
  72 + $moduleClassNameArray = explode('\\', $moduleClassName);
  73 + $moduleClassNameAlias = end($moduleClassNameArray);
72 74 $application = $e->getApplication();
73 75 $services = $application->getServiceManager();
74 76 if (!$services->has($moduleClassName)) {
75   - $services->setService($moduleClassName, $moduleManager);
  77 + $services->setAlias($moduleClassName, $moduleClassNameAlias);
76 78 }
77 79 }, 1000);
78 80
19 tests/ZendTest/ModuleManager/Listener/LocatorRegistrationListenerTest.php
@@ -122,4 +122,23 @@ public function testModuleClassIsRegisteredWithDiAndInjectedWithSharedInstances(
122 122 $this->assertInstanceOf('Zend\ModuleManager\ModuleManager', $sharedInstance2);
123 123 $this->assertSame($this->moduleManager, $locator->get('Foo\Bar')->moduleManager);
124 124 }
  125 +
  126 + public function testNoDuplicateServicesAreDefinedForModuleManager()
  127 + {
  128 + $locatorRegistrationListener = new LocatorRegistrationListener;
  129 + $this->moduleManager->getEventManager()->attachAggregate($locatorRegistrationListener);
  130 +
  131 + $this->moduleManager->loadModules();
  132 + $this->application->bootstrap();
  133 + $registeredServices = $this->application->getServiceManager()->getRegisteredServices();
  134 +
  135 + $aliases = $registeredServices['aliases'];
  136 + $instances = $registeredServices['instances'];
  137 +
  138 + $this->assertContains('zendmodulemanagermodulemanager', $aliases);
  139 + $this->assertFalse(in_array('modulemanager', $aliases));
  140 +
  141 + $this->assertContains('modulemanager', $instances);
  142 + $this->assertFalse(in_array('zendmodulemanagermodulemanager', $instances));
  143 + }
125 144 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.