Ben zorluklar PHP bir fabrika sınıfta bir 'ayarlanabilir' davranışı uygulamak için nasıl bulma yaşıyorum.
I've got at class, which takes another class as an argument in its constructor. The argument class could take a number of arguments in its constructor. An instance of my main class could look something like this
$instance = new MyClass(new OtherClass(20, true));
$instance2 = new MyClass(new DifferentClass('test'));
This is rather clumsy and has a number of problems and therefore I would like to move this into a factory class. The problem is that this factory somehow needs to know how to instantiate the argument class, as this class can have any number of arguments in the constructor.
Tercihen böyle bir şey yapmak mümkün olmak istiyorum
$instance = Factory::build('OtherClass');
$instance2 = Factory::build('DifferentClass');
Ve fabrika bir yapılandırma dizi veya benzer argümanları almak izin.