假设我们有以下接口:
interface FooInterface {
//...
}
我们有两个实现此接口的类:
class Foo implements FooInterface {
//...
}
class Bar implements FooInterface {
//...
}
在symfony中,我想注入接口,每当我在类的构造函数中使用FooInterface作为DI时,我都想要特定的类"foo".例如.
class SomeClass {
public function __construct(FooInterface $foo) { ... }
}
到目前为止一切顺利,现在我只想在测试环境中注入类"Bar".(.env APP_ENV=测试)
有没有全局配置可以用来指定将根据环境注入哪个类?