Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/rector-strict.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
->withPaths([
$nextcloudDir . '/build/rector-strict.php',
$nextcloudDir . '/core/BackgroundJobs/ExpirePreviewsJob.php',
$nextcloudDir . '/lib/public/IContainer.php',
])
->withPreparedSets(
deadCode: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public function has($id): bool {
* @inheritDoc
* @param list<class-string> $chain
*/
public function query(string $name, bool $autoload = true, array $chain = []) {
public function query(string $name, bool $autoload = true, array $chain = []): mixed {
if ($name === 'AppName' || $name === 'appName') {
return $this->appName;
}
Expand Down
14 changes: 5 additions & 9 deletions lib/private/AppFramework/Utility/SimpleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@
* @inheritDoc
* @param list<class-string> $chain
*/
public function resolve($name, array $chain = []) {
public function resolve(string $name, array $chain = []): mixed {
$baseMsg = 'Could not resolve ' . $name . '!';
try {
$class = new ReflectionClass($name);

Check failure on line 126 in lib/private/AppFramework/Utility/SimpleContainer.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-security

TaintedCallable

lib/private/AppFramework/Utility/SimpleContainer.php:126:33: TaintedCallable: Detected tainted text (see https://psalm.dev/243)
if ($class->isInstantiable()) {
return $this->buildClass($class, $chain);
} else {
Expand All @@ -140,7 +140,7 @@
* @inheritDoc
* @param list<class-string> $chain
*/
public function query(string $name, bool $autoload = true, array $chain = []) {
public function query(string $name, bool $autoload = true, array $chain = []): mixed {
$name = $this->sanitizeName($name);
if (isset($this->container[$name])) {
return $this->container[$name];
Expand All @@ -161,15 +161,11 @@
throw new QueryNotFoundException('Could not resolve ' . $name . '!');
}

/**
* @param string $name
* @param mixed $value
*/
public function registerParameter($name, $value) {
public function registerParameter(string $name, mixed $value): void {
$this[$name] = $value;
}

public function registerService($name, Closure $closure, $shared = true) {
public function registerService(string $name, Closure $closure, bool $shared = true): void {
$wrapped = function () use ($closure) {
return $closure($this);
};
Expand All @@ -191,7 +187,7 @@
* @param string $alias the alias that should be registered
* @param string $target the target that should be resolved instead
*/
public function registerAlias($alias, $target): void {
public function registerAlias(string $alias, string $target): void {
$this->registerService($alias, function (ContainerInterface $container) use ($target): mixed {
return $container->get($target);
}, false);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/ServerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
if (!isset($this->hasNoAppContainer[$namespace])) {
$applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application';
if (class_exists($applicationClassName)) {
$app = new $applicationClassName();

Check failure on line 89 in lib/private/ServerContainer.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-security

TaintedCallable

lib/private/ServerContainer.php:89:17: TaintedCallable: Detected tainted text (see https://psalm.dev/243)
if (isset($this->appContainers[$namespace])) {
$this->appContainers[$namespace]->offsetSet($applicationClassName, $app);
return $this->appContainers[$namespace];
Expand Down Expand Up @@ -119,7 +119,7 @@
* @throws QueryException
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
*/
public function query(string $name, bool $autoload = true, array $chain = []) {
public function query(string $name, bool $autoload = true, array $chain = []): mixed {
$name = $this->sanitizeName($name);

if (str_starts_with($name, 'OCA\\')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace OCP\AppFramework\Bootstrap;

use OC\AppFramework\Utility\SimpleContainer;
use OCP\AppFramework\IAppContainer;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\Calendar\ICalendarProvider;
Expand Down Expand Up @@ -69,7 +68,7 @@ public function registerDashboardWidget(string $widgetClass): void;
*
* @param string $name
* @param callable $factory
* @psalm-param callable(SimpleContainer): mixed $factory
* @psalm-param callable(IContainer): mixed $factory
* @param bool $shared If set to true the factory result will be cached otherwise every query will call the factory again
*
* @return void
Expand Down
54 changes: 28 additions & 26 deletions lib/public/IContainer.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
// use OCP namespace for all classes that are considered public.
// This means that they should be used by apps instead of the internal Nextcloud classes

namespace OCP;

use Closure;
use OC\AppFramework\Utility\SimpleContainer;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
Expand All @@ -22,51 +22,56 @@
* IContainer is the basic interface to be used for any internal dependency injection mechanism
*
* @since 6.0.0
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface
*/
interface IContainer extends ContainerInterface {
/**
* Finds an entry of the container by its identifier and returns it.
*
* @template T
* @param class-string<T>|string $id Identifier of the entry to look for.
*
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
* @throws ContainerExceptionInterface Error while retrieving the entry.
*
* @return ($id is class-string<T> ? T : mixed) Entry.
* @since 34.0.0
*/
public function get(string $id);

/**
* @template T
*
* If a parameter is not registered in the container try to instantiate it
* by using reflection to find out how to build the class
* @param string $name the class name to resolve
* @psalm-param string|class-string<T> $name
* @return \stdClass
* @psalm-return ($name is class-string ? T : mixed)
* @param class-string<T>|string $name
* @return ($name is class-string<T> ? T : mixed)
* @since 8.2.0
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
* @deprecated 20.0.0 use {@see self::get()}
* @throws ContainerExceptionInterface if the class could not be found or instantiated
*/
public function resolve($name);
public function resolve(string $name): mixed;

/**
* Look up a service for a given name in the container.
*
* @template T
*
* @param string $name
* @psalm-param string|class-string<T> $name
* @param class-string<T>|string $name
* @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
* @return mixed
* @psalm-return ($name is class-string ? T : mixed)
* @return ($name is class-string<T> ? T : mixed)
* @throws ContainerExceptionInterface if the query could not be resolved
* @throws NotFoundExceptionInterface if the name could not be found within the container
* @since 6.0.0
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
* @deprecated 20.0.0 use {@see self::get()}
*/
public function query(string $name, bool $autoload = true);
public function query(string $name, bool $autoload = true): mixed;

/**
* A value is stored in the container with it's corresponding name
*
* @param string $name
* @param mixed $value
* @return void
* @since 6.0.0
* @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerParameter
*/
public function registerParameter($name, $value);
public function registerParameter(string $name, mixed $value): void;

/**
* A service is registered in the container where a closure is passed in which will actually
Expand All @@ -75,14 +80,11 @@ public function registerParameter($name, $value);
* memory and be reused on subsequent calls.
* In case the parameter is false the service will be recreated on every call.
*
* @param string $name
* @param \Closure(SimpleContainer): mixed $closure
* @param bool $shared
* @return void
* @param \Closure(IContainer): mixed $closure
* @since 6.0.0
* @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerService
*/
public function registerService($name, Closure $closure, $shared = true);
public function registerService(string $name, Closure $closure, bool $shared = true): void;

/**
* Shortcut for returning a service from a service under a different key,
Expand All @@ -93,5 +95,5 @@ public function registerService($name, Closure $closure, $shared = true);
* @since 8.2.0
* @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerServiceAlias
*/
public function registerAlias($alias, $target);
public function registerAlias(string $alias, string $target): void;
}
1 change: 1 addition & 0 deletions psalm-strict.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
>
<projectFiles>
<file name="core/BackgroundJobs/ExpirePreviewsJob.php"/>
<file name="lib/public/IContainer.php"/>
<ignoreFiles>
<directory name="apps/**/composer"/>
<directory name="apps/**/tests"/>
Expand Down
16 changes: 8 additions & 8 deletions tests/lib/Collaboration/Collaborators/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,22 @@ public function testSearch(
->willReturnCallback(function ($class) use ($searchResult, $userPlugin, $groupPlugin, $remotePlugin, $mailPlugin) {
if ($class === SearchResult::class) {
return $searchResult;
} elseif ($class === $userPlugin) {
} elseif ($class === 'user') {
return $userPlugin;
} elseif ($class === $groupPlugin) {
} elseif ($class === 'group') {
return $groupPlugin;
} elseif ($class === $remotePlugin) {
} elseif ($class === 'remote') {
return $remotePlugin;
} elseif ($class === $mailPlugin) {
} elseif ($class === 'mail') {
return $mailPlugin;
}
return null;
});

$this->search->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => $userPlugin]);
$this->search->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => $groupPlugin]);
$this->search->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => $remotePlugin]);
$this->search->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => $mailPlugin]);
$this->search->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => 'user']);
$this->search->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => 'group']);
$this->search->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => 'remote']);
$this->search->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => 'mail']);

[$results, $moreResults] = $this->search->search($searchTerm, $shareTypes, false, $perPage, $perPage * ($page - 1));

Expand Down
Loading