nextcloud/lib/private/appframework/utility/simplecontainer.php

48 lines
1.2 KiB
PHP
Raw Normal View History

2013-08-20 19:21:14 +04:00
<?php
namespace OC\AppFramework\Utility;
/**
* Class SimpleContainer
*
* SimpleContainer is a simple implementation of IContainer on basis of \Pimple
*/
2014-11-03 15:10:03 +03:00
class SimpleContainer extends \Pimple\Container implements \OCP\IContainer {
2013-08-20 19:21:14 +04:00
/**
* @param string $name name of the service to query for
* @return mixed registered service for the given $name
2013-08-20 19:21:14 +04:00
*/
public function query($name) {
return $this->offsetGet($name);
}
/**
* @param string $name
* @param mixed $value
*/
function registerParameter($name, $value) {
2013-08-20 19:21:14 +04:00
$this[$name] = $value;
}
/**
* The given closure is call the first time the given service is queried.
* The closure has to return the instance for the given service.
* Created instance will be cached in case $shared is true.
*
* @param string $name name of the service to register another backend for
* @param \Closure $closure the closure to be called on service creation
* @param bool $shared
2013-08-20 19:21:14 +04:00
*/
function registerService($name, \Closure $closure, $shared = true) {
2014-11-12 00:04:46 +03:00
if (isset($this[$name])) {
2014-11-03 15:10:03 +03:00
unset($this[$name]);
}
2013-08-20 19:21:14 +04:00
if ($shared) {
$this[$name] = $closure;
2014-11-03 15:10:03 +03:00
} else {
$this[$name] = parent::factory($closure);
2013-08-20 19:21:14 +04:00
}
}
}