The "servicemanager" is the actual container which instantiates, configures, and manages a number of objects. These "services" typically collaborate with one another, and thus have dependencies between themselves. These dependencies are reflected in the configuration data used by the ServiceManager.
For our sample we use two class class1 and class2. Class1 will be injected with an instance of Class2 and other simple values and values from the configuration.
<?php
class Class1 {
var $constructorObject;
var $constructorConfigValue;
var $constructorValue;
var $setterValue;
var $setterConfigValue;
function __constructor(&$object,$value,$configValue) {
$this->constructorObject=&$object;
$this->constructorValue = $value;
$this->constructorConfigValue=$configValue;
}
function & getConstructorClass2() {
return $this->constructorObject;
}
function getConstructorValue() {
return $this->constructorValue;
}
function getConstructorConfigValue() {
return $this->constructorConfigValue;
}
function setSetterClass2(&$class2) {
$thio->setterObject= &$class2;
}
function & getSetterClass2() {
return $this->constructorObject;
}
function setSetterValues($value,$configValue) {
$this->setterValue=$value;
$this->setterConfigValue=$configValue;
}
}
?>
------------------------------------------------
<?php
class Class2 {
}
?>
------------------------------------------------
[interfaces] class1=sample.application class1 class1 SINGLETON class2=sample.application class1 class1 SINGLETON [constructorInjection] class1.0.ref=class2 class1.1.value=constructor.value class1.2.config=test.test.test [setterInjection] class1.setterclass2.0.ref=class2 class1.settervalues.0.value=setter.value class1.settervalues.1.config=test.test.test [components] othermodul=sample.othermodul.dependencies.profile
$builder = singleton_singleton::getInstance('servicemanager_ServiceMangerBuilder');
$serviceManager = $builder->createServiceManager('module.namespace','context');
$object = $serviceManager->getServiceObject('interfaceKey');