Share configuration between modules
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
-
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);
}
0 -
@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 ?0 -
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.
1
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 69 Spryker News
- 896 Developer Corner
- 758 Spryker Development
- 83 Spryker Dev Environment
- 361 Spryker Releases
- 3 Oryx frontend framework
- 34 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 23 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 68 Spryker Safari Questions
- 50 Random