From 8f432e77cac10774658680168c708e33e45dc944 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 16 Jul 2020 09:34:16 +0200 Subject: [PATCH] fixup! Use PSR container interface and deprecate our own abstraction Signed-off-by: Christoph Wurst --- .../AppFramework/Utility/SimpleContainer.php | 15 +++++++++------ lib/private/ServerContainer.php | 8 ++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/private/AppFramework/Utility/SimpleContainer.php b/lib/private/AppFramework/Utility/SimpleContainer.php index 722207eda851b..ec6484dfd7cc2 100644 --- a/lib/private/AppFramework/Utility/SimpleContainer.php +++ b/lib/private/AppFramework/Utility/SimpleContainer.php @@ -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); } } @@ -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); } } diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index 1c0c63555030f..446f4faed1018 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -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) {