Skip to content

fix - loadModule reinitializes modules if the module has already been… - #34

Open
nusphere wants to merge 3 commits into
laminas:2.18.xfrom
nusphere:bugfix_loadmodule_if_exists
Open

fix - loadModule reinitializes modules if the module has already been…#34
nusphere wants to merge 3 commits into
laminas:2.18.xfrom
nusphere:bugfix_loadmodule_if_exists

Conversation

@nusphere

@nusphere nusphere commented Apr 8, 2022

Copy link
Copy Markdown
Q A
Bugfix yes

Description

As descripted in #32 . there is an bug when loading a module with another loading name. there are currently 3 ways to load the same module via the module manager. the following options are available:

  • namespace (legacy way)
  • direct class string of the module class
  • an array with "free name (string)" (key) and a module class object (value)

if you use method 1 (namespace) and method 2 (class string) for the same module in an application, it will be loaded twice and reset the previous settings.

this pull request fixes the false behavior and prevents a module from being loaded twice.

fixes #32

nusphere added 3 commits April 8, 2022 15:10
… loaded laminas#32

Signed-off-by: Sebastian Hopfe <sebastian.hopfe@milchundzucker.de>
… loaded laminas#32

Signed-off-by: Sebastian Hopfe <sebastian.hopfe@milchundzucker.de>
Signed-off-by: Sebastian Hopfe <sebastian.hopfe@milchundzucker.de>
@nusphere

Copy link
Copy Markdown
Author

any review possible?

@froschdesign

Copy link
Copy Markdown
Member

@Xerkus
Can you look at this? Is the module manager still relevant at all?
Thanks in advance! 👍

@steffendietz

Copy link
Copy Markdown

Hi. Is there anything holding this fix back?

The target branch of this MR probably needs to be adjusted, given that 2 minor releases were published since this MR was opened.

@nusphere

nusphere commented Dec 7, 2022

Copy link
Copy Markdown
Author

@froschdesign - ping

@froschdesign froschdesign left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +103 to +129
public function testModuleLoadingBehaviorWithModuleClassStrings()
{
$moduleManager = new ModuleManager(['SomeModule'], $this->events);
$this->defaultListeners->attach($this->events);
$modules = $moduleManager->getLoadedModules();
self::assertSame(0, count($modules));
$modules = $moduleManager->getLoadedModules(true);
self::assertSame(1, count($modules));
$moduleManager->loadModules(); // should not cause any problems
$moduleManager->loadModule(Module::class); // should not cause any problems
$modules = $moduleManager->getLoadedModules(true); // BarModule already loaded so nothing happens
self::assertSame(1, count($modules));
}

public function testModuleLoadingBehaviorWithModuleClassStringsVersion2()
{
$moduleManager = new ModuleManager([Module::class], $this->events);
$this->defaultListeners->attach($this->events);
$modules = $moduleManager->getLoadedModules();
self::assertSame(0, count($modules));
$modules = $moduleManager->getLoadedModules(true);
self::assertSame(1, count($modules));
$moduleManager->loadModules(); // should not cause any problems
$moduleManager->loadModule('SomeModule'); // should not cause any problems
$modules = $moduleManager->getLoadedModules(true); // BarModule already loaded so nothing happens
self::assertSame(1, count($modules));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a data provider here and add some blank lines to break the wall of code / text.

Comment thread src/ModuleManager.php
* @param string $moduleName
* @return string
*/
private function getVerifiedModuleName($moduleName)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the types to the method because it is private and supported.

@Xerkus
Xerkus changed the base branch from 2.12.x to 2.18.x October 17, 2025 18:31
@Xerkus

Xerkus commented Oct 17, 2025

Copy link
Copy Markdown
Member

No matter how I look at this there is a BC break in any fix. It is incredibly brittle and was around for so long this way it is almost not worth fixing.

@Xerkus Xerkus added the Won't Fix This will not be worked on label Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Won't Fix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loadModule reinitializes modules if the module has already been loaded

5 participants