We are currently writing a module in Zend Framework 2.
I have some problems finding documentation on this, but I know that this is possible.
I have 3 classes in the hierarchy that I would like to configure through dependency injection. Let me name these classes; ClassA, ClassB and ClassC.
ClassA contains an array of ClassB instances, and ClassB contains an array of ClassC instances. Each instance of ClassB must be created using different parameters. The same goes for ClassC. Parameters for all 3 classes are passed through the constructor (this can also be processed using the setter, if necessary).
<?php
class ClassA {
protected $arrClassBInstances = array();
public function __construct( $arrClassBInstances ) {
$this->arrClassBInstances = $arrClassBInstances;
}
}
class ClassB {
protected $arrClassCInstances = array();
protected $someOtherParam = "";
public function __construct( $arrClassCInstances, $someOtherParam ) {
$this->arrClassBInstances = $arrClassCInstances;
$this->someOtherParam = $someOtherParam;
}
}
class ClassC {
protected $someParam = "";
public function __construct( $someParam ) {
$this->someParam = $someParam;
}
}
, . -, ? , ClassB, ClassC. ZF2 DiC - .
-, . , ClassB ClassA?
, DiC DI .config.php.