D
D
Daria Motorina2020-03-21 14:59:30
symfony
Daria Motorina, 2020-03-21 14:59:30

Is it bad practice to access env parameters without going through the config?

I am writing an automation for clicking pages in a browser using symfony 5.0. Pages are taken out in conditional PageObject classes. A number of pages need settings, which I pass through .env => config/services.yaml => class constructors. Bottom line - when I create a script for working with a page in a method of another class, then I need to pass all the parameters through the constructor of the script class. I read about setter injection, but it only works with class arguments, not regular string arguments.
Can I access these parameters directly through $_ENV inside the PageObject methods, thereby getting rid of passing parameters along the class chain, or is this option bad and more literate?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Zyabirov, 2020-03-21
@glaphire

I would probably not advise doing this, because it, in fact, differs little from using global variables. Why not inject your script class into another class through a constructor in the same way? I think that this is the best solution, especially since you don’t have to write anything to the configs to implement your script class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question