Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: 2.12.x
Choose a base branch
from

Conversation

nusphere
Copy link

@nusphere nusphere commented Apr 8, 2022

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
Copy link
Author

any review possible?

@froschdesign
Copy link
Member

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

@steffendietz
Copy link

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
Copy link
Author

nusphere commented Dec 7, 2022

@froschdesign - ping

Copy link
Member

@froschdesign froschdesign left a comment

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
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.

* @param string $moduleName
* @return string
*/
private function getVerifiedModuleName($moduleName)
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

loadModule reinitializes modules if the module has already been loaded
3 participants