67 'eventManager' =>
'wcmf\lib\core\EventManager',
68 'logger' =>
'wcmf\lib\core\Logger',
69 'logManager' =>
'wcmf\lib\core\LogManager',
70 'session' =>
'wcmf\lib\core\Session',
71 'configuration' =>
'wcmf\lib\config\Configuration',
72 'localization' =>
'wcmf\lib\i18n\Localization',
73 'message' =>
'wcmf\lib\i18n\Message',
74 'cache' =>
'wcmf\lib\io\Cache',
75 'persistenceFacade' =>
'wcmf\lib\persistence\PersistenceFacade',
76 'transaction' =>
'wcmf\lib\persistence\Transaction',
77 'concurrencyManager' =>
'wcmf\lib\persistence\concurrency\ConcurrencyManager',
78 'actionMapper' =>
'wcmf\lib\presentation\ActionMapper',
79 'request' =>
'wcmf\lib\presentation\Request',
80 'response' =>
'wcmf\lib\presentation\Response',
81 'listStrategies' =>
'wcmf\lib\presentation\control\lists\ListStrategy',
82 'formats' =>
'wcmf\lib\presentation\format\Format',
83 'formatter' =>
'wcmf\lib\presentation\format\Formatter',
84 'view' =>
'wcmf\lib\presentation\view\View',
85 'authenticationManager' =>
'wcmf\lib\security\AuthenticationManager',
86 'permissionManager' =>
'wcmf\lib\security\PermissionManager',
87 'principalFactory' =>
'wcmf\lib\security\principal\PrincipalFactory',
88 'user' =>
'wcmf\lib\security\principal\User',
89 'role' =>
'wcmf\lib\security\principal\Role',
118 if (in_array($name, $this->currentStack)) {
119 throw new \Exception(
"Circular dependency detected: ".join(
' - ', $this->currentStack).
" - [".$name.
"]");
121 $this->currentStack[] = $name;
124 $instanceKey =
sizeof($dynamicConfiguration) == 0 ? strtolower($name) :
125 strtolower($name.json_encode($dynamicConfiguration));
128 if (isset($this->instances[$instanceKey])) {
129 $instance = $this->instances[$instanceKey];
133 $staticConfiguration = $this->configuration->getSection($name,
true);
134 $configuration = array_merge($staticConfiguration, $dynamicConfiguration);
137 array_pop($this->currentStack);
147 ], $dynamicConfiguration);
160 ], $dynamicConfiguration);
170 $instanceKey = strtolower($name);
171 $this->instances[$instanceKey] = $instance;
178 $this->requiredInterfaces = array_merge($this->requiredInterfaces, $interfaces);
185 $this->instances = [];
224 if (class_exists($className)) {
228 $refClass = new \ReflectionClass($className);
229 if ($refClass->hasMethod(
'__construct')) {
230 $refConstructor = new \ReflectionMethod($className,
'__construct');
231 $refParameters = $refConstructor->getParameters();
232 foreach ($refParameters as $param) {
233 $paramName = $param->name;
234 $paramInstanceKey = strtolower($paramName);
235 if (isset($this->instances[$paramInstanceKey])) {
237 $cParams[$paramName] = $this->instances[$paramInstanceKey];
243 elseif ($this->configuration->hasSection($paramName)) {
245 $cParams[$paramName] = $this->
getInstance($paramName);
247 elseif (($paramClass = $param->getClass()) !=
null) {
250 $cParams[$paramName] = $this->
getInstanceOf($paramClass->name);
252 elseif (!$param->isDefaultValueAvailable()) {
254 '\' in
class \
''.$className.
'\' cannot be injected.
');
256 // delete resolved parameters from configuration
257 unset($configuration[$paramName]);
261 // create the instance
262 $obj = $refClass->newInstanceArgs($cParams);
264 // check against interface
265 $interface = $this->getInterface($name);
266 if ($interface != null && !($obj instanceof $interface)) {
267 throw new ConfigurationException('Class \
''.$className.
268 '\' is required to implement interface \
''.$interface.
'\'.
');
271 // register the instance if it is shared (default)
272 // NOTE we do this before setting the instance properties in order
273 // to allow to resolve circular dependencies (dependent objects that
274 // are injected into the current instance via property injection can
275 // already use this instance)
276 if (!isset($configuration['__shared
']) || $configuration['__shared
'] == 'true') {
277 $this->registerInstance($instanceKey, $obj);
280 // set the instance properties from the remaining configuration
281 foreach ($configuration as $key => $value) {
282 // exclude properties starting with __ and constructor parameters
283 if (strpos($key, '__
') !== 0 && !isset($cParams[$key])) {
284 $value = $this->resolveValue($value);
286 $setterName = $this->getSetterName($key);
287 if (method_exists($obj, $setterName)) {
288 $obj->$setterName($value);
298 throw new ConfigurationException('Class \
''.$className.
'\' is not found.
');
302 // the instance is a map
304 // get interface that map values should implement
305 $interface = $this->getInterface($name);
307 foreach ($configuration as $key => $value) {
308 // create instances for variables denoted by a leading $
309 if (strpos($value, '$
') === 0) {
310 $obj = $this->getInstance(preg_replace('/^\$/
', '', $value));
311 // check against interface
312 if ($interface != null && !($obj instanceof $interface)) {
313 throw new ConfigurationException('Class of \
''.$name.
'.'.$key.
314 '\' is required to implement interface \
''.$interface.
'\'.
');
316 $configuration[$key] = $obj;
319 // always register maps
320 $this->registerInstance($instanceKey, $configuration);
321 $instance = $configuration;
331 protected function resolveValue($value) {
332 // special treatments, if value is a string
333 if (is_string($value)) {
334 // replace variables denoted by a leading $
335 if (strpos($value, '$
') === 0) {
336 $value = $this->getInstance(preg_replace('/^\$/
', '', $value));
340 $lower = strtolower($value);
341 if ($lower === 'true') {
344 if ($lower === 'false') {
349 // special treatments, if value is an array
350 if (is_array($value)) {
352 $containsInstance = false;
353 // check for variables
354 foreach ($value as $val) {
355 if (is_string($val) && strpos($val, '$
') === 0) {
356 $result[] = $this->getInstance(preg_replace('/^\$/
', '', $val));
357 $containsInstance = true;
363 // only replace value, if the array containes an variable
364 if ($containsInstance) {
376 protected function getInterface($name) {
377 if (isset($this->requiredInterfaces[$name])) {
378 return $this->requiredInterfaces[$name];