Merge pull request #52846 from nextcloud/refactor/ocp-deprecations

pull/52885/head
Kate 2025-05-15 18:05:06 +07:00 committed by GitHub
commit cf44995aac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 41 additions and 124 deletions

@ -1,68 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0"> <files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="lib/public/AppFramework/ApiController.php">
<NoInterfaceProperties>
<code><![CDATA[$this->request->server]]></code>
</NoInterfaceProperties>
</file>
<file src="lib/public/AppFramework/App.php"> <file src="lib/public/AppFramework/App.php">
<UndefinedClass> <UndefinedClass>
<code><![CDATA[\OC]]></code> <code><![CDATA[\OC]]></code>
</UndefinedClass> </UndefinedClass>
</file> </file>
<file src="lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php">
<UndefinedClass>
<code><![CDATA[\OC]]></code>
</UndefinedClass>
</file>
<file src="lib/public/AppFramework/Http/Response.php">
<UndefinedClass>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
</UndefinedClass>
</file>
<file src="lib/public/Defaults.php">
<UndefinedClass>
<code><![CDATA[\OC]]></code>
</UndefinedClass>
</file>
<file src="lib/public/Diagnostics/IQueryLogger.php">
<LessSpecificImplementedReturnType>
<code><![CDATA[mixed]]></code>
</LessSpecificImplementedReturnType>
</file>
<file src="lib/public/EventDispatcher/GenericEvent.php">
<MissingTemplateParam>
<code><![CDATA[ArrayAccess]]></code>
<code><![CDATA[IteratorAggregate]]></code>
</MissingTemplateParam>
</file>
<file src="lib/public/Files.php">
<UndefinedClass>
<code><![CDATA[\OC]]></code>
</UndefinedClass>
</file>
<file src="lib/public/L10N/ILanguageIterator.php">
<MissingTemplateParam>
<code><![CDATA[\Iterator]]></code>
</MissingTemplateParam>
</file>
<file src="lib/public/Util.php">
<UndefinedClass>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
<code><![CDATA[\OC]]></code>
</UndefinedClass>
</file>
</files> </files>

@ -3780,9 +3780,6 @@
<InvalidArgument> <InvalidArgument>
<code><![CDATA[microtime(true)]]></code> <code><![CDATA[microtime(true)]]></code>
</InvalidArgument> </InvalidArgument>
<InvalidReturnType>
<code><![CDATA[stopQuery]]></code>
</InvalidReturnType>
</file> </file>
<file src="lib/private/DirectEditing/Manager.php"> <file src="lib/private/DirectEditing/Manager.php">
<InvalidReturnType> <InvalidReturnType>
@ -4679,11 +4676,6 @@
<code><![CDATA[\Test\Util\User\Dummy]]></code> <code><![CDATA[\Test\Util\User\Dummy]]></code>
</UndefinedClass> </UndefinedClass>
</file> </file>
<file src="lib/public/AppFramework/ApiController.php">
<NoInterfaceProperties>
<code><![CDATA[$this->request->server]]></code>
</NoInterfaceProperties>
</file>
<file src="lib/public/AppFramework/Http/Response.php"> <file src="lib/public/AppFramework/Http/Response.php">
<LessSpecificReturnStatement> <LessSpecificReturnStatement>
<code><![CDATA[array_merge($mergeWith, $this->headers)]]></code> <code><![CDATA[array_merge($mergeWith, $this->headers)]]></code>
@ -4700,22 +4692,6 @@
<code><![CDATA[array{0: int, 1: int, 2: int}]]></code> <code><![CDATA[array{0: int, 1: int, 2: int}]]></code>
</MoreSpecificReturnType> </MoreSpecificReturnType>
</file> </file>
<file src="lib/public/Diagnostics/IQueryLogger.php">
<LessSpecificImplementedReturnType>
<code><![CDATA[mixed]]></code>
</LessSpecificImplementedReturnType>
</file>
<file src="lib/public/EventDispatcher/GenericEvent.php">
<MissingTemplateParam>
<code><![CDATA[ArrayAccess]]></code>
<code><![CDATA[IteratorAggregate]]></code>
</MissingTemplateParam>
</file>
<file src="lib/public/L10N/ILanguageIterator.php">
<MissingTemplateParam>
<code><![CDATA[\Iterator]]></code>
</MissingTemplateParam>
</file>
<file src="lib/public/Preview/BeforePreviewFetchedEvent.php"> <file src="lib/public/Preview/BeforePreviewFetchedEvent.php">
<LessSpecificReturnStatement> <LessSpecificReturnStatement>
<code><![CDATA[$this->mode]]></code> <code><![CDATA[$this->mode]]></code>

@ -58,9 +58,8 @@ abstract class ApiController extends Controller {
#[PublicPage] #[PublicPage]
#[NoAdminRequired] #[NoAdminRequired]
public function preflightedCors() { public function preflightedCors() {
if (isset($this->request->server['HTTP_ORIGIN'])) { $origin = $this->request->getHeader('origin');
$origin = $this->request->server['HTTP_ORIGIN']; if ($origin === '') {
} else {
$origin = '*'; $origin = '*';
} }

@ -10,6 +10,8 @@ declare(strict_types=1);
namespace OCP\AppFramework; namespace OCP\AppFramework;
use OC\ServerContainer; use OC\ServerContainer;
use OCP\IConfig;
use OCP\Server;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/** /**
@ -44,7 +46,7 @@ class App {
* @since 6.0.0 * @since 6.0.0
*/ */
public function __construct(string $appName, array $urlParams = []) { public function __construct(string $appName, array $urlParams = []) {
$runIsSetupDirectly = \OC::$server->getConfig()->getSystemValueBool('debug') $runIsSetupDirectly = Server::get(IConfig::class)->getSystemValueBool('debug')
&& !ini_get('zend.exception_ignore_args'); && !ini_get('zend.exception_ignore_args');
if ($runIsSetupDirectly) { if ($runIsSetupDirectly) {
@ -71,7 +73,7 @@ class App {
} }
if (!$setUpViaQuery && $applicationClassName !== \OCP\AppFramework\App::class) { if (!$setUpViaQuery && $applicationClassName !== \OCP\AppFramework\App::class) {
\OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), [ Server::get(LoggerInterface::class)->error($e->getMessage(), [
'app' => $appName, 'app' => $appName,
'exception' => $e, 'exception' => $e,
]); ]);

@ -30,8 +30,7 @@ class RedirectToDefaultAppResponse extends RedirectResponse {
* @deprecated 23.0.0 Use RedirectResponse() with IURLGenerator::linkToDefaultPageUrl() instead * @deprecated 23.0.0 Use RedirectResponse() with IURLGenerator::linkToDefaultPageUrl() instead
*/ */
public function __construct(int $status = Http::STATUS_SEE_OTHER, array $headers = []) { public function __construct(int $status = Http::STATUS_SEE_OTHER, array $headers = []) {
/** @var IURLGenerator $urlGenerator */ $urlGenerator = \OCP\Server::get(IURLGenerator::class);
$urlGenerator = \OC::$server->get(IURLGenerator::class);
parent::__construct($urlGenerator->linkToDefaultPageUrl(), $status, $headers); parent::__construct($urlGenerator->linkToDefaultPageUrl(), $status, $headers);
} }
} }

@ -93,7 +93,6 @@ class Response {
// Set expires header // Set expires header
$expires = new \DateTime(); $expires = new \DateTime();
/** @var ITimeFactory $time */
$time = \OCP\Server::get(ITimeFactory::class); $time = \OCP\Server::get(ITimeFactory::class);
$expires->setTimestamp($time->getTime()); $expires->setTimestamp($time->getTime());
$expires->add(new \DateInterval('PT' . $cacheSeconds . 'S')); $expires->add(new \DateInterval('PT' . $cacheSeconds . 'S'));
@ -184,10 +183,10 @@ class Response {
if ($this->status === Http::STATUS_NOT_MODIFIED if ($this->status === Http::STATUS_NOT_MODIFIED
&& stripos($name, 'x-') === 0) { && stripos($name, 'x-') === 0) {
/** @var IConfig $config */ /** @var IConfig $config */
$config = \OC::$server->get(IConfig::class); $config = \OCP\Server::get(IConfig::class);
if ($config->getSystemValueBool('debug', false)) { if ($config->getSystemValueBool('debug', false)) {
\OC::$server->get(LoggerInterface::class)->error('Setting custom header on a 304 is not supported (Header: {header})', [ \OCP\Server::get(LoggerInterface::class)->error('Setting custom header on a 304 is not supported (Header: {header})', [
'header' => $name, 'header' => $name,
]); ]);
} }
@ -229,7 +228,7 @@ class Response {
/** /**
* @psalm-suppress UndefinedClass * @psalm-suppress UndefinedClass
*/ */
$request = \OC::$server->get(IRequest::class); $request = \OCP\Server::get(IRequest::class);
$mergeWith = [ $mergeWith = [
'X-Request-Id' => $request->getId(), 'X-Request-Id' => $request->getId(),
'Cache-Control' => 'no-cache, no-store, must-revalidate', 'Cache-Control' => 'no-cache, no-store, must-revalidate',

@ -29,7 +29,7 @@ class Defaults {
*/ */
public function __construct(?\OC_Defaults $defaults = null) { public function __construct(?\OC_Defaults $defaults = null) {
if ($defaults === null) { if ($defaults === null) {
$defaults = \OC::$server->get('ThemingDefaults'); $defaults = \OCP\Server::get('ThemingDefaults');
} }
$this->defaults = $defaults; $this->defaults = $defaults;
} }

@ -31,7 +31,7 @@ interface IQueryLogger extends SQLLogger {
* Mark the end of the current active query. Ending query should store \OCP\Diagnostics\IQuery to * Mark the end of the current active query. Ending query should store \OCP\Diagnostics\IQuery to
* be returned with getQueries() method. * be returned with getQueries() method.
* *
* @return mixed * @return void
* @since 8.0.0 * @since 8.0.0
*/ */
public function stopQuery(); public function stopQuery();

@ -18,10 +18,12 @@ use function array_key_exists;
/** /**
* Class GenericEvent * Class GenericEvent
* *
* convenience reimplementation of \Symfony\Component\GenericEvent against * convenience re-implementation of \Symfony\Component\GenericEvent against
* \OCP\EventDispatcher\Event * \OCP\EventDispatcher\Event
* *
* @since 18.0.0 * @since 18.0.0
* @template-implements ArrayAccess<array-key, mixed>
* @template-implements IteratorAggregate<array-key, mixed>
* @deprecated 22.0.0 use \OCP\EventDispatcher\Event * @deprecated 22.0.0 use \OCP\EventDispatcher\Event
*/ */
class GenericEvent extends Event implements ArrayAccess, IteratorAggregate { class GenericEvent extends Event implements ArrayAccess, IteratorAggregate {

@ -9,6 +9,8 @@
namespace OCP; namespace OCP;
use OCP\Files\IMimeTypeDetector;
/** /**
* This class provides access to the internal filesystem abstraction layer. Use * This class provides access to the internal filesystem abstraction layer. Use
* this class exclusively if you want to access files * this class exclusively if you want to access files
@ -67,7 +69,7 @@ class Files {
* @deprecated 14.0.0 * @deprecated 14.0.0
*/ */
public static function getMimeType($path) { public static function getMimeType($path) {
return \OC::$server->getMimeTypeDetector()->detect($path); return Server::get(IMimeTypeDetector::class)->detect($path);
} }
/** /**

@ -16,7 +16,7 @@ use OCP\FullTextSearch\Model\IIndexDocument;
* This is mostly used by 3rd party apps that want to complete the IIndexDocument * This is mostly used by 3rd party apps that want to complete the IIndexDocument
* with more information about a file before its index: * with more information about a file before its index:
* *
* \OC::$server->getEventDispatcher()->addListener( * \OCP\Server::get(IEventDispatcher::class)->addListener(
* '\OCA\Files_FullTextSearch::onFileIndexing', * '\OCA\Files_FullTextSearch::onFileIndexing',
* function(GenericEvent $e) { * function(GenericEvent $e) {
* //@var \OCP\Files\Node $file * //@var \OCP\Files\Node $file

@ -21,7 +21,7 @@ namespace OCP\L10N;
* if settings are not present or truncating is not applicable, the iterator * if settings are not present or truncating is not applicable, the iterator
* skips to the next valid item itself * skips to the next valid item itself
* *
* * @template-extends \Iterator<int, string>
* @since 14.0.0 * @since 14.0.0
*/ */
interface ILanguageIterator extends \Iterator { interface ILanguageIterator extends \Iterator {
@ -36,10 +36,8 @@ interface ILanguageIterator extends \Iterator {
* Move forward to next element * Move forward to next element
* *
* @since 14.0.0 * @since 14.0.0
* @return void
*/ */
#[\ReturnTypeWillChange] public function next(): void;
public function next();
/** /**
* Return the key of the current element * Return the key of the current element

@ -14,7 +14,7 @@ namespace OCP\Mail;
* *
* Example usage: * Example usage:
* *
* $mailer = \OC::$server->get(\OCP\Mail\IMailer::class); * $mailer = \OCP\Server::get(\OCP\Mail\IMailer::class);
* $message = $mailer->createMessage(); * $message = $mailer->createMessage();
* $message->setSubject('Your Subject'); * $message->setSubject('Your Subject');
* $message->setFrom(['cloud@domain.org' => 'Nextcloud Notifier']); * $message->setFrom(['cloud@domain.org' => 'Nextcloud Notifier']);

@ -17,7 +17,7 @@ use OCP\DataCollector\IDataCollector;
* *
* ```php * ```php
* <?php * <?php
* $profiler = \OC::$server->get(IProfiler::class); * $profiler = \OCP\Server::get(IProfiler::class);
* $profiles = $profiler->find('/settings/users', 10); * $profiles = $profiler->find('/settings/users', 10);
* ``` * ```
* *

@ -13,8 +13,8 @@ namespace OCP\Security;
* it will use the secret defined in config.php as key. Additionally the message will be HMAC'd. * it will use the secret defined in config.php as key. Additionally the message will be HMAC'd.
* *
* Usage: * Usage:
* $encryptWithDefaultPassword = \OC::$server->getCrypto()->encrypt('EncryptedText'); * $encryptWithDefaultPassword = \OCP\Server::get(ICrypto::class)->encrypt('EncryptedText');
* $encryptWithCustomPassword = \OC::$server->getCrypto()->encrypt('EncryptedText', 'password'); * $encryptWithCustomPassword = \OCP\Server::get(ICrypto::class)->encrypt('EncryptedText', 'password');
* *
* @since 8.0.0 * @since 8.0.0
*/ */

@ -19,10 +19,10 @@ namespace OCP\Security;
* *
* Usage: * Usage:
* // Hashing a message * // Hashing a message
* $hash = \OC::$server->get(\OCP\Security\IHasher::class)->hash('MessageToHash'); * $hash = \OCP\Server::get(\OCP\Security\IHasher::class)->hash('MessageToHash');
* // Verifying a message - $newHash will contain the newly calculated hash * // Verifying a message - $newHash will contain the newly calculated hash
* $newHash = null; * $newHash = null;
* var_dump(\OC::$server->get(\OCP\Security\IHasher::class)->verify('a', '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', $newHash)); * var_dump(\OCP\Server::get(\OCP\Security\IHasher::class)->verify('a', '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', $newHash));
* var_dump($newHash); * var_dump($newHash);
* *
* @since 8.0.0 * @since 8.0.0

@ -14,7 +14,7 @@ namespace OCP\Security;
* use a fallback. * use a fallback.
* *
* Usage: * Usage:
* \OC::$server->get(ISecureRandom::class)->generate(10); * \OCP\Server::get(ISecureRandom::class)->generate(10);
* *
* @since 8.0.0 * @since 8.0.0
*/ */

@ -51,7 +51,7 @@ class Util {
return $subscriptionRegistry->delegateHasExtendedSupport(); return $subscriptionRegistry->delegateHasExtendedSupport();
} catch (ContainerExceptionInterface $e) { } catch (ContainerExceptionInterface $e) {
} }
return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false); return \OCP\Server::get(IConfig::class)->getSystemValueBool('extendedSupport', false);
} }
/** /**
@ -60,7 +60,7 @@ class Util {
* @since 8.1.0 * @since 8.1.0
*/ */
public static function setChannel($channel) { public static function setChannel($channel) {
\OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel); \OCP\Server::get(IConfig::class)->setSystemValue('updater.release.channel', $channel);
} }
/** /**
@ -182,7 +182,7 @@ class Util {
*/ */
public static function getScripts(): array { public static function getScripts(): array {
// Sort scriptDeps into sortedScriptDeps // Sort scriptDeps into sortedScriptDeps
$scriptSort = \OC::$server->get(AppScriptSort::class); $scriptSort = \OCP\Server::get(AppScriptSort::class);
$sortedScripts = $scriptSort->sort(self::$scripts, self::$scriptDeps); $sortedScripts = $scriptSort->sort(self::$scripts, self::$scriptDeps);
// Flatten array and remove duplicates // Flatten array and remove duplicates
@ -209,7 +209,7 @@ class Util {
*/ */
public static function addTranslations($application, $languageCode = null, $init = false) { public static function addTranslations($application, $languageCode = null, $init = false) {
if (is_null($languageCode)) { if (is_null($languageCode)) {
$languageCode = \OC::$server->get(IFactory::class)->findLanguage($application); $languageCode = \OCP\Server::get(IFactory::class)->findLanguage($application);
} }
if (!empty($application)) { if (!empty($application)) {
$path = "$application/l10n/$languageCode"; $path = "$application/l10n/$languageCode";
@ -247,7 +247,7 @@ class Util {
* @since 4.0.0 - parameter $args was added in 4.5.0 * @since 4.0.0 - parameter $args was added in 4.5.0
*/ */
public static function linkToAbsolute($app, $file, $args = []) { public static function linkToAbsolute($app, $file, $args = []) {
$urlGenerator = \OC::$server->getURLGenerator(); $urlGenerator = \OCP\Server::get(IURLGenerator::class);
return $urlGenerator->getAbsoluteURL( return $urlGenerator->getAbsoluteURL(
$urlGenerator->linkTo($app, $file, $args) $urlGenerator->linkTo($app, $file, $args)
); );
@ -260,7 +260,7 @@ class Util {
* @since 4.0.0 * @since 4.0.0
*/ */
public static function linkToRemote($service) { public static function linkToRemote($service) {
$urlGenerator = \OC::$server->getURLGenerator(); $urlGenerator = \OCP\Server::get(IURLGenerator::class);
$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
return $urlGenerator->getAbsoluteURL( return $urlGenerator->getAbsoluteURL(
$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
@ -273,7 +273,7 @@ class Util {
* @since 5.0.0 * @since 5.0.0
*/ */
public static function getServerHostName() { public static function getServerHostName() {
$host_name = \OC::$server->getRequest()->getServerHost(); $host_name = \OCP\Server::get(IRequest::class)->getServerHost();
// strip away port number (if existing) // strip away port number (if existing)
$colon_pos = strpos($host_name, ':'); $colon_pos = strpos($host_name, ':');
if ($colon_pos != false) { if ($colon_pos != false) {
@ -299,13 +299,13 @@ class Util {
* @since 5.0.0 * @since 5.0.0
*/ */
public static function getDefaultEmailAddress(string $user_part): string { public static function getDefaultEmailAddress(string $user_part): string {
$config = \OC::$server->getConfig(); $config = \OCP\Server::get(IConfig::class);
$user_part = $config->getSystemValueString('mail_from_address', $user_part); $user_part = $config->getSystemValueString('mail_from_address', $user_part);
$host_name = self::getServerHostName(); $host_name = self::getServerHostName();
$host_name = $config->getSystemValueString('mail_domain', $host_name); $host_name = $config->getSystemValueString('mail_domain', $host_name);
$defaultEmailAddress = $user_part . '@' . $host_name; $defaultEmailAddress = $user_part . '@' . $host_name;
$mailer = \OC::$server->get(IMailer::class); $mailer = \OCP\Server::get(IMailer::class);
if ($mailer->validateMailAddress($defaultEmailAddress)) { if ($mailer->validateMailAddress($defaultEmailAddress)) {
return $defaultEmailAddress; return $defaultEmailAddress;
} }
@ -447,7 +447,7 @@ class Util {
*/ */
public static function callRegister() { public static function callRegister() {
if (self::$token === '') { if (self::$token === '') {
self::$token = \OC::$server->get(CsrfTokenManager::class)->getToken()->getEncryptedValue(); self::$token = \OCP\Server::get(CsrfTokenManager::class)->getToken()->getEncryptedValue();
} }
return self::$token; return self::$token;
} }
@ -582,7 +582,7 @@ class Util {
*/ */
public static function needUpgrade() { public static function needUpgrade() {
if (!isset(self::$needUpgradeCache)) { if (!isset(self::$needUpgradeCache)) {
self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig()); self::$needUpgradeCache = \OC_Util::needUpgrade(\OCP\Server::get(\OC\SystemConfig::class));
} }
return self::$needUpgradeCache; return self::$needUpgradeCache;
} }