]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make the bootstrap context return ContainerInterface instances
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Thu, 16 Jul 2020 15:06:17 +0000 (17:06 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Tue, 21 Jul 2020 18:42:24 +0000 (20:42 +0200)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
lib/private/AppFramework/Bootstrap/BootContext.php
lib/private/AppFramework/Bootstrap/FunctionInjector.php
lib/public/AppFramework/App.php
lib/public/AppFramework/Bootstrap/IBootContext.php

index d206884c0b7fe20a9a6ed57306e66f427413b227..7c2582a7269bf70a7572f799387eca3f7afa121d 100644 (file)
@@ -26,24 +26,24 @@ declare(strict_types=1);
 namespace OC\AppFramework\Bootstrap;
 
 use OCP\AppFramework\Bootstrap\IBootContext;
-use OCP\AppFramework\IAppContainer;
 use OCP\IServerContainer;
+use Psr\Container\ContainerInterface;
 
 class BootContext implements IBootContext {
 
-       /** @var IAppContainer */
+       /** @var ContainerInterface */
        private $appContainer;
 
-       public function __construct(IAppContainer $appContainer) {
+       public function __construct(ContainerInterface $appContainer) {
                $this->appContainer = $appContainer;
        }
 
-       public function getAppContainer(): IAppContainer {
+       public function getAppContainer(): ContainerInterface {
                return $this->appContainer;
        }
 
-       public function getServerContainer(): IServerContainer {
-               return $this->appContainer->getServer();
+       public function getServerContainer(): ContainerInterface {
+               return $this->appContainer->get(IServerContainer::class);
        }
 
        public function injectFn(callable $fn) {
index cb1dc7d3f37516911d4594e33f8f5ce54de3cb00..25c1fbc0be6640ae46b860ee7e776c426f0339d7 100644 (file)
@@ -27,17 +27,17 @@ namespace OC\AppFramework\Bootstrap;
 
 use Closure;
 use OCP\AppFramework\QueryException;
-use OCP\IContainer;
+use Psr\Container\ContainerInterface;
 use ReflectionFunction;
 use ReflectionParameter;
 use function array_map;
 
 class FunctionInjector {
 
-       /** @var IContainer */
+       /** @var ContainerInterface */
        private $container;
 
-       public function __construct(IContainer $container) {
+       public function __construct(ContainerInterface $container) {
                $this->container = $container;
        }
 
@@ -47,14 +47,14 @@ class FunctionInjector {
                        // First we try by type (more likely these days)
                        if (($type = $param->getType()) !== null) {
                                try {
-                                       return $this->container->query($type->getName());
+                                       return $this->container->get($type->getName());
                                } catch (QueryException $ex) {
                                        // Ignore and try name as well
                                }
                        }
                        // Second we try by name (mostly for primitives)
                        try {
-                               return $this->container->query($param->getName());
+                               return $this->container->get($param->getName());
                        } catch (QueryException $ex) {
                                // As a last resort we pass `null` if allowed
                                if ($type !== null && $type->allowsNull()) {
index 2f55fd451406340121cc50019438a588fcd3b937..de1cbcb64e82988321364c8a62721e6c949bffa3 100644 (file)
@@ -120,6 +120,7 @@ class App {
        /**
         * @return IAppContainer
         * @since 6.0.0
+        * @todo make this return a ContainerInterface as well
         */
        public function getContainer(): IAppContainer {
                return $this->container;
index ee0bef6a5fad2cf2ec65f4cdf60f71c4f59fd42c..86232cef4ad1e5018b8bb07b5d4db0f86e560272 100644 (file)
@@ -41,20 +41,20 @@ interface IBootContext {
         *
         * Useful to register and query app-specific services
         *
-        * @return IAppContainer|ContainerInterface
+        * @return ContainerInterface|IAppContainer
         * @since 20.0.0
         */
-       public function getAppContainer(): IAppContainer;
+       public function getAppContainer(): ContainerInterface;
 
        /**
         * Get hold of the server DI container
         *
         * Useful to register and query system-wide services
         *
-        * @return IServerContainer
+        * @return ContainerInterface|IServerContainer
         * @since 20.0.0
         */
-       public function getServerContainer(): IServerContainer;
+       public function getServerContainer(): ContainerInterface;
 
        /**
         * Invoke the given callable and inject all parameters based on their types