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
|
|
|
|
*/
|
2013-08-31 23:34:29 +04:00
|
|
|
class SimpleContainer extends \Pimple implements \OCP\IContainer {
|
2013-08-20 19:21:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name name of the service to query for
|
|
|
|
* @return object registered service for the given $name
|
|
|
|
*/
|
|
|
|
public function query($name) {
|
|
|
|
return $this->offsetGet($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
function registerParameter($name, $value)
|
|
|
|
{
|
|
|
|
$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
|
2014-02-06 19:30:58 +04:00
|
|
|
* @param \Closure $closure the closure to be called on service creation
|
2013-08-20 19:21:14 +04:00
|
|
|
*/
|
|
|
|
function registerService($name, \Closure $closure, $shared = true)
|
|
|
|
{
|
|
|
|
if ($shared) {
|
|
|
|
$this[$name] = \Pimple::share($closure);
|
|
|
|
} else {
|
|
|
|
$this[$name] = $closure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|