What are the Slack Archives?
It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.
Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..
Is there a best-practice on where to put cross-module constants in the Spryker architecture? I am ha
Is there a best-practice on where to put cross-module constants in the Spryker architecture? I am having a case in a project now where I need to use one constant value in several (by itself independent) modules - any suggestions?
Comments
-
I am currently thinking about two options:
1. Create aFeatureAbcConstants
class in one of those modules, leading to e.g. using the constants asPyz\Zed\ProductLabel\FeatureAbcConstants::MY_NICE_CONSTANT
. This is a contradiction to "don't create direct dependencies between modules".
2. Create a new namespaceMyCompany
and drop the constant in a class there, so e.g.MyCompany\Constants\FeatureAbsConstant::MY_NICE_CONSTANT
and reference this from the Spryker modules... this seems like the "cleaner" solution, although it feels a bit dirty to create a completely new top-level namespace.. the advantage here is that those "project-level" constants would be outside of the normal module-layer of Spryker0 -
The third one:
You can create a constant in both modules. In main module you create just a constant, in others add@uses
tag in dockblock with reference to main module0 -
@UR1QYK8MC thanks for the answer, but this creates duplicate code, and my experience is that then someone just changes it at one place, and forgets the other one? 😄
0 -
that’s why you need
@uses
. But I agree with you. I personally think that on project level you can simple live with dependencies between modules and use constant from another module0 -
Agree 100% here:
on project level you can simple live with dependencies between modules
don’t over-complicate your code with de-coupling things too much. In Spryker de-coupling is important, since there many projects out there with different modules combination.
Project - is a concrete implementation, where simplicity and readability of the code - is the most important thing.
SOLID - is a very important principle, but don’t go to it’s extreme, find a “golden middle”
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 75 Spryker News
- 924 Developer Corner
- 783 Spryker Development
- 88 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 25 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
- 70 Spryker Safari Questions
- 50 Random