Skip to content

Commit

Permalink
fixup! Use PSR container interface and deprecate our own abstraction
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Jul 16, 2020
1 parent f994f98 commit 8f432e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 9 additions & 6 deletions lib/private/AppFramework/Utility/SimpleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,17 @@ public function registerParameter($name, $value) {
* @param bool $shared
*/
public function registerService($name, Closure $closure, $shared = true) {
$wrapped = function() use ($closure) {
return $closure($this);
};
$name = $this->sanitizeName($name);
if (isset($this[$name])) {
unset($this[$name]);
}
if ($shared) {
$this[$name] = $closure;
$this[$name] = $wrapped;
} else {
$this[$name] = $this->container->factory($closure);
$this[$name] = $this->container->factory($wrapped);
}
}

Expand Down Expand Up @@ -192,27 +195,27 @@ protected function sanitizeName($name) {
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::has
*/
public function offsetExists($id) {
return $this->container->has($id);
return $this->container->offsetExists($id);
}

/**
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
*/
public function offsetGet($id) {
return $this->container->get($id);
return $this->container->offsetGet($id);
}

/**
* @deprecated 20.0.0 use \OCP\IContainer::registerService
*/
public function offsetSet($id, $service) {
$this->container->add($id, $service);
$this->container->offsetSet($id, $service);
}

/**
* @deprecated 20.0.0
*/
public function offsetUnset($offset) {
throw new Exception("Not implemented");
$this->container->offsetUnset($offset);
}
}
8 changes: 4 additions & 4 deletions lib/private/ServerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ public function has($id, bool $noRecursion = false): bool {
public function query(string $name, bool $autoload = true) {
$name = $this->sanitizeName($name);

if (parent::has($name)) {
return parent::get($name);
}
//if (parent::has($name)) {
// return parent::get($name);
//}

// In case the service starts with OCA\ we try to find the service in
// the apps container first.
if (($appContainer = $this->getAppContainerForService($name) !== null)) {
if (($appContainer = $this->getAppContainerForService($name)) !== null) {
try {
return $appContainer->queryNoFallback($name);
} catch (QueryException $e) {
Expand Down

0 comments on commit 8f432e7

Please sign in to comment.