0

I'm using the PHP League Container and I want to implement a strategy pattern.

I want to connect to an external service with a different client class depending on the $version parameter that is passed to my adapter. I want to pass the client in to the adapter as a dependency.

How can I get PHP league container to replace the definition of an interface with a new class at runtime?

Andy
  • 2,095
  • 1
  • 29
  • 59
  • 1
    I'm not really good at names of specific patterns, but I'd think this would lend itself better to a factory pattern which would be much easier to test. The factory is a first-class object in your system, it inspects the provided version, and then doles out the appropriate class as needed. – Chris Haas May 12 '23 at 18:10

0 Answers0