@@ -44,75 +44,75 @@ |
||
| 44 | 44 | * @deprecated 20.0.0 use \Psr\Container\ContainerInterface |
| 45 | 45 | */ |
| 46 | 46 | interface IContainer extends ContainerInterface { |
| 47 | - /** |
|
| 48 | - * @template T |
|
| 49 | - * |
|
| 50 | - * If a parameter is not registered in the container try to instantiate it |
|
| 51 | - * by using reflection to find out how to build the class |
|
| 52 | - * @param string $name the class name to resolve |
|
| 53 | - * @psalm-param string|class-string<T> $name |
|
| 54 | - * @return \stdClass |
|
| 55 | - * @psalm-return ($name is class-string ? T : mixed) |
|
| 56 | - * @since 8.2.0 |
|
| 57 | - * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get |
|
| 58 | - * @throws ContainerExceptionInterface if the class could not be found or instantiated |
|
| 59 | - * @throws QueryException if the class could not be found or instantiated |
|
| 60 | - */ |
|
| 61 | - public function resolve($name); |
|
| 47 | + /** |
|
| 48 | + * @template T |
|
| 49 | + * |
|
| 50 | + * If a parameter is not registered in the container try to instantiate it |
|
| 51 | + * by using reflection to find out how to build the class |
|
| 52 | + * @param string $name the class name to resolve |
|
| 53 | + * @psalm-param string|class-string<T> $name |
|
| 54 | + * @return \stdClass |
|
| 55 | + * @psalm-return ($name is class-string ? T : mixed) |
|
| 56 | + * @since 8.2.0 |
|
| 57 | + * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get |
|
| 58 | + * @throws ContainerExceptionInterface if the class could not be found or instantiated |
|
| 59 | + * @throws QueryException if the class could not be found or instantiated |
|
| 60 | + */ |
|
| 61 | + public function resolve($name); |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Look up a service for a given name in the container. |
|
| 65 | - * |
|
| 66 | - * @template T |
|
| 67 | - * |
|
| 68 | - * @param string $name |
|
| 69 | - * @psalm-param string|class-string<T> $name |
|
| 70 | - * @param bool $autoload Should we try to autoload the service. If we are trying to resolve built in types this makes no sense for example |
|
| 71 | - * @return mixed |
|
| 72 | - * @psalm-return ($name is class-string ? T : mixed) |
|
| 73 | - * @throws ContainerExceptionInterface if the query could not be resolved |
|
| 74 | - * @throws NotFoundExceptionInterface if the name could not be found within the container |
|
| 75 | - * @throws QueryException if the query could not be resolved |
|
| 76 | - * @since 6.0.0 |
|
| 77 | - * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get |
|
| 78 | - */ |
|
| 79 | - public function query(string $name, bool $autoload = true); |
|
| 63 | + /** |
|
| 64 | + * Look up a service for a given name in the container. |
|
| 65 | + * |
|
| 66 | + * @template T |
|
| 67 | + * |
|
| 68 | + * @param string $name |
|
| 69 | + * @psalm-param string|class-string<T> $name |
|
| 70 | + * @param bool $autoload Should we try to autoload the service. If we are trying to resolve built in types this makes no sense for example |
|
| 71 | + * @return mixed |
|
| 72 | + * @psalm-return ($name is class-string ? T : mixed) |
|
| 73 | + * @throws ContainerExceptionInterface if the query could not be resolved |
|
| 74 | + * @throws NotFoundExceptionInterface if the name could not be found within the container |
|
| 75 | + * @throws QueryException if the query could not be resolved |
|
| 76 | + * @since 6.0.0 |
|
| 77 | + * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get |
|
| 78 | + */ |
|
| 79 | + public function query(string $name, bool $autoload = true); |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * A value is stored in the container with it's corresponding name |
|
| 83 | - * |
|
| 84 | - * @param string $name |
|
| 85 | - * @param mixed $value |
|
| 86 | - * @return void |
|
| 87 | - * @since 6.0.0 |
|
| 88 | - * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerParameter |
|
| 89 | - */ |
|
| 90 | - public function registerParameter($name, $value); |
|
| 81 | + /** |
|
| 82 | + * A value is stored in the container with it's corresponding name |
|
| 83 | + * |
|
| 84 | + * @param string $name |
|
| 85 | + * @param mixed $value |
|
| 86 | + * @return void |
|
| 87 | + * @since 6.0.0 |
|
| 88 | + * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerParameter |
|
| 89 | + */ |
|
| 90 | + public function registerParameter($name, $value); |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * A service is registered in the container where a closure is passed in which will actually |
|
| 94 | - * create the service on demand. |
|
| 95 | - * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
| 96 | - * memory and be reused on subsequent calls. |
|
| 97 | - * In case the parameter is false the service will be recreated on every call. |
|
| 98 | - * |
|
| 99 | - * @param string $name |
|
| 100 | - * @param \Closure $closure |
|
| 101 | - * @param bool $shared |
|
| 102 | - * @return void |
|
| 103 | - * @since 6.0.0 |
|
| 104 | - * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerService |
|
| 105 | - */ |
|
| 106 | - public function registerService($name, Closure $closure, $shared = true); |
|
| 92 | + /** |
|
| 93 | + * A service is registered in the container where a closure is passed in which will actually |
|
| 94 | + * create the service on demand. |
|
| 95 | + * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
| 96 | + * memory and be reused on subsequent calls. |
|
| 97 | + * In case the parameter is false the service will be recreated on every call. |
|
| 98 | + * |
|
| 99 | + * @param string $name |
|
| 100 | + * @param \Closure $closure |
|
| 101 | + * @param bool $shared |
|
| 102 | + * @return void |
|
| 103 | + * @since 6.0.0 |
|
| 104 | + * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerService |
|
| 105 | + */ |
|
| 106 | + public function registerService($name, Closure $closure, $shared = true); |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Shortcut for returning a service from a service under a different key, |
|
| 110 | - * e.g. to tell the container to return a class when queried for an |
|
| 111 | - * interface |
|
| 112 | - * @param string $alias the alias that should be registered |
|
| 113 | - * @param string $target the target that should be resolved instead |
|
| 114 | - * @since 8.2.0 |
|
| 115 | - * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerServiceAlias |
|
| 116 | - */ |
|
| 117 | - public function registerAlias($alias, $target); |
|
| 108 | + /** |
|
| 109 | + * Shortcut for returning a service from a service under a different key, |
|
| 110 | + * e.g. to tell the container to return a class when queried for an |
|
| 111 | + * interface |
|
| 112 | + * @param string $alias the alias that should be registered |
|
| 113 | + * @param string $target the target that should be resolved instead |
|
| 114 | + * @since 8.2.0 |
|
| 115 | + * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerServiceAlias |
|
| 116 | + */ |
|
| 117 | + public function registerAlias($alias, $target); |
|
| 118 | 118 | } |
@@ -45,193 +45,193 @@ |
||
| 45 | 45 | * SimpleContainer is a simple implementation of a container on basis of Pimple |
| 46 | 46 | */ |
| 47 | 47 | class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { |
| 48 | - /** @var Container */ |
|
| 49 | - private $container; |
|
| 50 | - |
|
| 51 | - public function __construct() { |
|
| 52 | - $this->container = new Container(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @template T |
|
| 57 | - * @param class-string<T>|string $id |
|
| 58 | - * @return T|mixed |
|
| 59 | - * @psalm-template S as class-string<T>|string |
|
| 60 | - * @psalm-param S $id |
|
| 61 | - * @psalm-return (S is class-string<T> ? T : mixed) |
|
| 62 | - * @throws QueryException |
|
| 63 | - */ |
|
| 64 | - public function get(string $id) { |
|
| 65 | - return $this->query($id); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function has(string $id): bool { |
|
| 69 | - // If a service is no registered but is an existing class, we can probably load it |
|
| 70 | - return isset($this->container[$id]) || class_exists($id); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param ReflectionClass $class the class to instantiate |
|
| 75 | - * @return \stdClass the created class |
|
| 76 | - * @suppress PhanUndeclaredClassInstanceof |
|
| 77 | - */ |
|
| 78 | - private function buildClass(ReflectionClass $class) { |
|
| 79 | - $constructor = $class->getConstructor(); |
|
| 80 | - if ($constructor === null) { |
|
| 81 | - return $class->newInstance(); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - return $class->newInstanceArgs(array_map(function (ReflectionParameter $parameter) { |
|
| 85 | - $parameterType = $parameter->getType(); |
|
| 86 | - |
|
| 87 | - $resolveName = $parameter->getName(); |
|
| 88 | - |
|
| 89 | - // try to find out if it is a class or a simple parameter |
|
| 90 | - if ($parameterType !== null && ($parameterType instanceof ReflectionNamedType) && !$parameterType->isBuiltin()) { |
|
| 91 | - $resolveName = $parameterType->getName(); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - try { |
|
| 95 | - $builtIn = $parameter->hasType() && ($parameter->getType() instanceof ReflectionNamedType) |
|
| 96 | - && $parameter->getType()->isBuiltin(); |
|
| 97 | - return $this->query($resolveName, !$builtIn); |
|
| 98 | - } catch (QueryException $e) { |
|
| 99 | - // Service not found, use the default value when available |
|
| 100 | - if ($parameter->isDefaultValueAvailable()) { |
|
| 101 | - return $parameter->getDefaultValue(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if ($parameterType !== null && ($parameterType instanceof ReflectionNamedType) && !$parameterType->isBuiltin()) { |
|
| 105 | - $resolveName = $parameter->getName(); |
|
| 106 | - try { |
|
| 107 | - return $this->query($resolveName); |
|
| 108 | - } catch (QueryException $e2) { |
|
| 109 | - // don't lose the error we got while trying to query by type |
|
| 110 | - throw new QueryException($e->getMessage(), (int) $e->getCode(), $e); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - throw $e; |
|
| 115 | - } |
|
| 116 | - }, $constructor->getParameters())); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function resolve($name) { |
|
| 120 | - $baseMsg = 'Could not resolve ' . $name . '!'; |
|
| 121 | - try { |
|
| 122 | - $class = new ReflectionClass($name); |
|
| 123 | - if ($class->isInstantiable()) { |
|
| 124 | - return $this->buildClass($class); |
|
| 125 | - } else { |
|
| 126 | - throw new QueryException($baseMsg . |
|
| 127 | - ' Class can not be instantiated'); |
|
| 128 | - } |
|
| 129 | - } catch (ReflectionException $e) { |
|
| 130 | - // Class does not exist |
|
| 131 | - throw new QueryNotFoundException($baseMsg . ' ' . $e->getMessage()); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - public function query(string $name, bool $autoload = true) { |
|
| 136 | - $name = $this->sanitizeName($name); |
|
| 137 | - if (isset($this->container[$name])) { |
|
| 138 | - return $this->container[$name]; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if ($autoload) { |
|
| 142 | - $object = $this->resolve($name); |
|
| 143 | - $this->registerService($name, function () use ($object) { |
|
| 144 | - return $object; |
|
| 145 | - }); |
|
| 146 | - return $object; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - throw new QueryNotFoundException('Could not resolve ' . $name . '!'); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param string $name |
|
| 154 | - * @param mixed $value |
|
| 155 | - */ |
|
| 156 | - public function registerParameter($name, $value) { |
|
| 157 | - $this[$name] = $value; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * The given closure is call the first time the given service is queried. |
|
| 162 | - * The closure has to return the instance for the given service. |
|
| 163 | - * Created instance will be cached in case $shared is true. |
|
| 164 | - * |
|
| 165 | - * @param string $name name of the service to register another backend for |
|
| 166 | - * @param Closure $closure the closure to be called on service creation |
|
| 167 | - * @param bool $shared |
|
| 168 | - */ |
|
| 169 | - public function registerService($name, Closure $closure, $shared = true) { |
|
| 170 | - $wrapped = function () use ($closure) { |
|
| 171 | - return $closure($this); |
|
| 172 | - }; |
|
| 173 | - $name = $this->sanitizeName($name); |
|
| 174 | - if (isset($this[$name])) { |
|
| 175 | - unset($this[$name]); |
|
| 176 | - } |
|
| 177 | - if ($shared) { |
|
| 178 | - $this[$name] = $wrapped; |
|
| 179 | - } else { |
|
| 180 | - $this[$name] = $this->container->factory($wrapped); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Shortcut for returning a service from a service under a different key, |
|
| 186 | - * e.g. to tell the container to return a class when queried for an |
|
| 187 | - * interface |
|
| 188 | - * @param string $alias the alias that should be registered |
|
| 189 | - * @param string $target the target that should be resolved instead |
|
| 190 | - */ |
|
| 191 | - public function registerAlias($alias, $target) { |
|
| 192 | - $this->registerService($alias, function (ContainerInterface $container) use ($target) { |
|
| 193 | - return $container->get($target); |
|
| 194 | - }, false); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /* |
|
| 48 | + /** @var Container */ |
|
| 49 | + private $container; |
|
| 50 | + |
|
| 51 | + public function __construct() { |
|
| 52 | + $this->container = new Container(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @template T |
|
| 57 | + * @param class-string<T>|string $id |
|
| 58 | + * @return T|mixed |
|
| 59 | + * @psalm-template S as class-string<T>|string |
|
| 60 | + * @psalm-param S $id |
|
| 61 | + * @psalm-return (S is class-string<T> ? T : mixed) |
|
| 62 | + * @throws QueryException |
|
| 63 | + */ |
|
| 64 | + public function get(string $id) { |
|
| 65 | + return $this->query($id); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function has(string $id): bool { |
|
| 69 | + // If a service is no registered but is an existing class, we can probably load it |
|
| 70 | + return isset($this->container[$id]) || class_exists($id); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param ReflectionClass $class the class to instantiate |
|
| 75 | + * @return \stdClass the created class |
|
| 76 | + * @suppress PhanUndeclaredClassInstanceof |
|
| 77 | + */ |
|
| 78 | + private function buildClass(ReflectionClass $class) { |
|
| 79 | + $constructor = $class->getConstructor(); |
|
| 80 | + if ($constructor === null) { |
|
| 81 | + return $class->newInstance(); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + return $class->newInstanceArgs(array_map(function (ReflectionParameter $parameter) { |
|
| 85 | + $parameterType = $parameter->getType(); |
|
| 86 | + |
|
| 87 | + $resolveName = $parameter->getName(); |
|
| 88 | + |
|
| 89 | + // try to find out if it is a class or a simple parameter |
|
| 90 | + if ($parameterType !== null && ($parameterType instanceof ReflectionNamedType) && !$parameterType->isBuiltin()) { |
|
| 91 | + $resolveName = $parameterType->getName(); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + try { |
|
| 95 | + $builtIn = $parameter->hasType() && ($parameter->getType() instanceof ReflectionNamedType) |
|
| 96 | + && $parameter->getType()->isBuiltin(); |
|
| 97 | + return $this->query($resolveName, !$builtIn); |
|
| 98 | + } catch (QueryException $e) { |
|
| 99 | + // Service not found, use the default value when available |
|
| 100 | + if ($parameter->isDefaultValueAvailable()) { |
|
| 101 | + return $parameter->getDefaultValue(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if ($parameterType !== null && ($parameterType instanceof ReflectionNamedType) && !$parameterType->isBuiltin()) { |
|
| 105 | + $resolveName = $parameter->getName(); |
|
| 106 | + try { |
|
| 107 | + return $this->query($resolveName); |
|
| 108 | + } catch (QueryException $e2) { |
|
| 109 | + // don't lose the error we got while trying to query by type |
|
| 110 | + throw new QueryException($e->getMessage(), (int) $e->getCode(), $e); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + throw $e; |
|
| 115 | + } |
|
| 116 | + }, $constructor->getParameters())); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function resolve($name) { |
|
| 120 | + $baseMsg = 'Could not resolve ' . $name . '!'; |
|
| 121 | + try { |
|
| 122 | + $class = new ReflectionClass($name); |
|
| 123 | + if ($class->isInstantiable()) { |
|
| 124 | + return $this->buildClass($class); |
|
| 125 | + } else { |
|
| 126 | + throw new QueryException($baseMsg . |
|
| 127 | + ' Class can not be instantiated'); |
|
| 128 | + } |
|
| 129 | + } catch (ReflectionException $e) { |
|
| 130 | + // Class does not exist |
|
| 131 | + throw new QueryNotFoundException($baseMsg . ' ' . $e->getMessage()); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + public function query(string $name, bool $autoload = true) { |
|
| 136 | + $name = $this->sanitizeName($name); |
|
| 137 | + if (isset($this->container[$name])) { |
|
| 138 | + return $this->container[$name]; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if ($autoload) { |
|
| 142 | + $object = $this->resolve($name); |
|
| 143 | + $this->registerService($name, function () use ($object) { |
|
| 144 | + return $object; |
|
| 145 | + }); |
|
| 146 | + return $object; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + throw new QueryNotFoundException('Could not resolve ' . $name . '!'); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param string $name |
|
| 154 | + * @param mixed $value |
|
| 155 | + */ |
|
| 156 | + public function registerParameter($name, $value) { |
|
| 157 | + $this[$name] = $value; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * The given closure is call the first time the given service is queried. |
|
| 162 | + * The closure has to return the instance for the given service. |
|
| 163 | + * Created instance will be cached in case $shared is true. |
|
| 164 | + * |
|
| 165 | + * @param string $name name of the service to register another backend for |
|
| 166 | + * @param Closure $closure the closure to be called on service creation |
|
| 167 | + * @param bool $shared |
|
| 168 | + */ |
|
| 169 | + public function registerService($name, Closure $closure, $shared = true) { |
|
| 170 | + $wrapped = function () use ($closure) { |
|
| 171 | + return $closure($this); |
|
| 172 | + }; |
|
| 173 | + $name = $this->sanitizeName($name); |
|
| 174 | + if (isset($this[$name])) { |
|
| 175 | + unset($this[$name]); |
|
| 176 | + } |
|
| 177 | + if ($shared) { |
|
| 178 | + $this[$name] = $wrapped; |
|
| 179 | + } else { |
|
| 180 | + $this[$name] = $this->container->factory($wrapped); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Shortcut for returning a service from a service under a different key, |
|
| 186 | + * e.g. to tell the container to return a class when queried for an |
|
| 187 | + * interface |
|
| 188 | + * @param string $alias the alias that should be registered |
|
| 189 | + * @param string $target the target that should be resolved instead |
|
| 190 | + */ |
|
| 191 | + public function registerAlias($alias, $target) { |
|
| 192 | + $this->registerService($alias, function (ContainerInterface $container) use ($target) { |
|
| 193 | + return $container->get($target); |
|
| 194 | + }, false); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /* |
|
| 198 | 198 | * @param string $name |
| 199 | 199 | * @return string |
| 200 | 200 | */ |
| 201 | - protected function sanitizeName($name) { |
|
| 202 | - if (isset($name[0]) && $name[0] === '\\') { |
|
| 203 | - return ltrim($name, '\\'); |
|
| 204 | - } |
|
| 205 | - return $name; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::has |
|
| 210 | - */ |
|
| 211 | - public function offsetExists($id): bool { |
|
| 212 | - return $this->container->offsetExists($id); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get |
|
| 217 | - * @return mixed |
|
| 218 | - */ |
|
| 219 | - #[\ReturnTypeWillChange] |
|
| 220 | - public function offsetGet($id) { |
|
| 221 | - return $this->container->offsetGet($id); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @deprecated 20.0.0 use \OCP\IContainer::registerService |
|
| 226 | - */ |
|
| 227 | - public function offsetSet($id, $service): void { |
|
| 228 | - $this->container->offsetSet($id, $service); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @deprecated 20.0.0 |
|
| 233 | - */ |
|
| 234 | - public function offsetUnset($offset): void { |
|
| 235 | - $this->container->offsetUnset($offset); |
|
| 236 | - } |
|
| 201 | + protected function sanitizeName($name) { |
|
| 202 | + if (isset($name[0]) && $name[0] === '\\') { |
|
| 203 | + return ltrim($name, '\\'); |
|
| 204 | + } |
|
| 205 | + return $name; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::has |
|
| 210 | + */ |
|
| 211 | + public function offsetExists($id): bool { |
|
| 212 | + return $this->container->offsetExists($id); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get |
|
| 217 | + * @return mixed |
|
| 218 | + */ |
|
| 219 | + #[\ReturnTypeWillChange] |
|
| 220 | + public function offsetGet($id) { |
|
| 221 | + return $this->container->offsetGet($id); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @deprecated 20.0.0 use \OCP\IContainer::registerService |
|
| 226 | + */ |
|
| 227 | + public function offsetSet($id, $service): void { |
|
| 228 | + $this->container->offsetSet($id, $service); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @deprecated 20.0.0 |
|
| 233 | + */ |
|
| 234 | + public function offsetUnset($offset): void { |
|
| 235 | + $this->container->offsetUnset($offset); |
|
| 236 | + } |
|
| 237 | 237 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | return $class->newInstance(); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - return $class->newInstanceArgs(array_map(function (ReflectionParameter $parameter) { |
|
| 84 | + return $class->newInstanceArgs(array_map(function(ReflectionParameter $parameter) { |
|
| 85 | 85 | $parameterType = $parameter->getType(); |
| 86 | 86 | |
| 87 | 87 | $resolveName = $parameter->getName(); |
@@ -117,18 +117,18 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | public function resolve($name) { |
| 120 | - $baseMsg = 'Could not resolve ' . $name . '!'; |
|
| 120 | + $baseMsg = 'Could not resolve '.$name.'!'; |
|
| 121 | 121 | try { |
| 122 | 122 | $class = new ReflectionClass($name); |
| 123 | 123 | if ($class->isInstantiable()) { |
| 124 | 124 | return $this->buildClass($class); |
| 125 | 125 | } else { |
| 126 | - throw new QueryException($baseMsg . |
|
| 126 | + throw new QueryException($baseMsg. |
|
| 127 | 127 | ' Class can not be instantiated'); |
| 128 | 128 | } |
| 129 | 129 | } catch (ReflectionException $e) { |
| 130 | 130 | // Class does not exist |
| 131 | - throw new QueryNotFoundException($baseMsg . ' ' . $e->getMessage()); |
|
| 131 | + throw new QueryNotFoundException($baseMsg.' '.$e->getMessage()); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -140,13 +140,13 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | if ($autoload) { |
| 142 | 142 | $object = $this->resolve($name); |
| 143 | - $this->registerService($name, function () use ($object) { |
|
| 143 | + $this->registerService($name, function() use ($object) { |
|
| 144 | 144 | return $object; |
| 145 | 145 | }); |
| 146 | 146 | return $object; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - throw new QueryNotFoundException('Could not resolve ' . $name . '!'); |
|
| 149 | + throw new QueryNotFoundException('Could not resolve '.$name.'!'); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param bool $shared |
| 168 | 168 | */ |
| 169 | 169 | public function registerService($name, Closure $closure, $shared = true) { |
| 170 | - $wrapped = function () use ($closure) { |
|
| 170 | + $wrapped = function() use ($closure) { |
|
| 171 | 171 | return $closure($this); |
| 172 | 172 | }; |
| 173 | 173 | $name = $this->sanitizeName($name); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * @param string $target the target that should be resolved instead |
| 190 | 190 | */ |
| 191 | 191 | public function registerAlias($alias, $target) { |
| 192 | - $this->registerService($alias, function (ContainerInterface $container) use ($target) { |
|
| 192 | + $this->registerService($alias, function(ContainerInterface $container) use ($target) { |
|
| 193 | 193 | return $container->get($target); |
| 194 | 194 | }, false); |
| 195 | 195 | } |