如何将单元中的行为调整为全局配置值

If we want to write S.O.L.I.D. code what's the best way to condition behavior inside a loosely coupled and testable unit to some global configuration value?

Is it better to inject some sort of object containing the information or just reference a global static/singleton?

I'm working with PHP but i guess this question is language agnostic.

Thanks in advance.

If you have two different behaviors depending on a global state / configuration, then I would probably refactor out a strategy (strategy pattern) and then inject the strategy.

It would then be the job of main to inject the correct strategy depending of the configuration.

If the strategy depends on a changing configuration i.e. a configuration that changes at runtime, then the strategy should be wrapped in a provider/supplier. (probably not the case for php)

An alternativ could be to have a generic feature-toggle type that is injected. The toggle can then be setup from main to return true or false. With a toggle object you can have more complex logic then with a simple boolean, but it depends on the usecase.

But i don't like the alternative, because it would be simpler i the class didn't know about two different behaviors.