diff options
author | Robin Appelman <robin@icewind.nl> | 2025-04-15 20:17:23 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2025-06-24 16:12:06 +0200 |
commit | 4bdc0751c0c422da70aa1ec75dee817794c65ae6 (patch) | |
tree | f9f1cbe938f043b8235f1d5070968506403f63a8 /lib/private/AppFramework | |
parent | bb632f0cfae8b0a6417be24666e8cb7587799c34 (diff) | |
download | nextcloud-server-container-optimizations.tar.gz nextcloud-server-container-optimizations.zip |
fix: use array_key_exists instead of isset in di containercontainer-optimizations
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/AppFramework')
-rw-r--r-- | lib/private/AppFramework/DependencyInjection/DIContainer.php | 2 | ||||
-rw-r--r-- | lib/private/AppFramework/Utility/SimpleContainer.php | 13 |
2 files changed, 8 insertions, 7 deletions
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index b31d6931459..1ec44348773 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -415,7 +415,7 @@ class DIContainer extends SimpleContainer implements IAppContainer { $name = $this->resolveAlias($name); $isServerClass = str_starts_with($name, 'OCP\\') || str_starts_with($name, 'OC\\'); - if ($isServerClass && !self::has($name)) { + if ($isServerClass && !$this->has($name)) { return $this->server->queryNoApps($name, $autoload); } diff --git a/lib/private/AppFramework/Utility/SimpleContainer.php b/lib/private/AppFramework/Utility/SimpleContainer.php index 9a8e5b2369f..69de3d2dae8 100644 --- a/lib/private/AppFramework/Utility/SimpleContainer.php +++ b/lib/private/AppFramework/Utility/SimpleContainer.php @@ -41,7 +41,7 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { public function has(string $id): bool { // If a service is no registered but is an existing class, we can probably load it - return isset($this->items[$id]) || isset($this->aliases[$id]) || class_exists($id); + return array_key_exists($id, $this->items) || array_key_exists($id, $this->aliases) || class_exists($id); } /** @@ -129,7 +129,7 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { $name = $this->sanitizeName($name); $name = $this->resolveAlias($name); - if (isset($this->items[$name])) { + if (array_key_exists($name, $this->items)) { $item = $this->items[$name]; if ($item instanceof ServiceFactory) { return $item->get(); @@ -145,7 +145,7 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { return $object; } - throw new QueryNotFoundException('Could not resolve ' . $name . '!'); + throw new QueryNotFoundException('Could not resolve ' . $name . '!' . get_class($this)); } /** @@ -189,6 +189,7 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { if ($alias === $target) { throw new QueryNotFoundException('Can\'t alias to self'); } + unset($this->items[$alias]); $this->aliases[$alias] = $target; } @@ -204,7 +205,7 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::has */ public function offsetExists($id): bool { - return isset($this->items[$id]) || isset($this->aliases[$id]); + return array_key_exists($id, $this->items) || array_key_exists($id, $this->aliases); } /** @@ -235,7 +236,7 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { * Check if we already have a resolved instance of $name */ public function isResolved($name): bool { - if (!isset($this->items[$name])) { + if (!array_key_exists($name, $this->items)) { return false; } $item = $this->items[$name]; @@ -247,7 +248,7 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { } protected function resolveAlias(string $name): string { - while (isset($this->aliases[$name])) { + while (array_key_exists($name, $this->aliases)) { $name = $this->aliases[$name]; } return $name; |