simplecontainer.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace OC\AppFramework\Utility;
  3. // register 3rdparty autoloaders
  4. require_once __DIR__ . '/../../../../3rdparty/Pimple/Pimple.php';
  5. /**
  6. * Class SimpleContainer
  7. *
  8. * SimpleContainer is a simple implementation of IContainer on basis of \Pimple
  9. */
  10. class SimpleContainer extends \Pimple implements \OCP\IContainer {
  11. /**
  12. * @param string $name name of the service to query for
  13. * @return object registered service for the given $name
  14. */
  15. public function query($name) {
  16. return $this->offsetGet($name);
  17. }
  18. function registerParameter($name, $value)
  19. {
  20. $this[$name] = $value;
  21. }
  22. /**
  23. * The given closure is call the first time the given service is queried.
  24. * The closure has to return the instance for the given service.
  25. * Created instance will be cached in case $shared is true.
  26. *
  27. * @param string $name name of the service to register another backend for
  28. * @param callable $closure the closure to be called on service creation
  29. */
  30. function registerService($name, \Closure $closure, $shared = true)
  31. {
  32. if ($shared) {
  33. $this[$name] = \Pimple::share($closure);
  34. } else {
  35. $this[$name] = $closure;
  36. }
  37. }
  38. }