Share configuration between modules

devjoe
devjoe Posts: 3 🧑🏻‍🚀 - Cadet

Hi,
I want to access a configuration method from Pyz/Shared/ModuleA/ModuleAConfig.php with another module in the Yves-Layer. For example: Pyz/Yves/ModuleB/Controller/ModuleBController.
Here I want to access the config from the ModuleAConfig.php. How could I achieve this ?

I read somewhere in the documentation that the Shared-Layer is just for sharing configuration between the Layers but what If I need to share it between modules ? Thanks in advance!

Answers

  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 83 🏛 - Council (mod)

    How about setting that value in one of the config files and getting it in each Module config?

    public function getMyValue()

    {

    return $this→get(MyModuleShareConstants::MY_VALUE);

    }

  • devjoe
    devjoe Posts: 3 🧑🏻‍🚀 - Cadet

    @Hidran Arias Thanks for the suggestion.
    To give a better example: In ModuleAConfig.php I got the following method:
    public function getValues(): array
    {
    return explode(';', ModuleAConstants::MY_VALUE);
    }

    Now I want to access this method in multiple modules. What would be the best way ?

  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 83 🏛 - Council (mod)

    I wouldn't create a hard dependency among modules . If you're using that value in two different modules, maybe you should refactor your code. Extract that logic into a module and expose it through a facade that you can then provide in different modules through the dependency provider.
    According to Spryker's conventions: Whatever you need from some other module, you provide through the DependencyProvider.

    So, you would need to set that module config into the container in the Dependency provider and have access to it through the module's factory.

    I'd rather expose a method in ModuleA Facade to provide that value if you badly need to recycle that method.