refactor(dav): fix psalm for dav endpoints

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
This commit is contained in:
Carl Schwan 2025-12-17 14:58:16 +01:00
parent 89fcefbfa0
commit 3555e00754
No known key found for this signature in database
GPG key ID: 02325448204E452A
8 changed files with 43 additions and 84 deletions

View file

@ -24,6 +24,7 @@ use OCA\DAV\Connector\Sabre\Principal;
use OCP\Accounts\IAccountManager;
use OCP\App\IAppManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IDBConnection;
@ -56,7 +57,7 @@ $principalBackend = new Principal(
Server::get(ProxyMapper::class),
Server::get(KnownUserService::class),
Server::get(IConfig::class),
\OC::$server->getL10NFactory(),
Server::get(IL10NFactory::class),
'principals/'
);
$db = Server::get(IDBConnection::class);
@ -84,7 +85,7 @@ $calDavBackend = new CalDavBackend(
);
$debugging = Server::get(IConfig::class)->getSystemValue('debug', false);
$sendInvitations = Server::get(IConfig::class)->getAppValue('dav', 'sendInvitations', 'yes') === 'yes';
$sendInvitations = Server::get(IAppConfig::class)->getValueBool('dav', 'sendInvitations', true);
// Root nodes
$principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
@ -102,6 +103,7 @@ $nodes = [
$server = new \Sabre\DAV\Server($nodes);
$server::$exposeVersion = false;
$server->httpRequest->setUrl(Server::get(IRequest::class)->getRequestUri());
/** @var string $baseuri defined in remote.php */
$server->setBaseUri($baseuri);
// Add plugins
@ -126,4 +128,4 @@ $server->addPlugin(Server::get(RateLimitingPlugin::class));
$server->addPlugin(Server::get(CalDavValidatePlugin::class));
// And off we go!
$server->exec();
$server->start();

View file

@ -30,6 +30,7 @@ use OCP\IRequest;
use OCP\ISession;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory as IL10nFactory;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
use Psr\Log\LoggerInterface;
@ -53,7 +54,7 @@ $principalBackend = new Principal(
Server::get(ProxyMapper::class),
Server::get(KnownUserService::class),
Server::get(IConfig::class),
\OC::$server->getL10NFactory(),
Server::get(IL10nFactory::class),
'principals/'
);
$db = Server::get(IDBConnection::class);
@ -85,9 +86,10 @@ $nodes = [
$server = new \Sabre\DAV\Server($nodes);
$server::$exposeVersion = false;
$server->httpRequest->setUrl(Server::get(IRequest::class)->getRequestUri());
/** @var string $baseuri defined in remote.php */
$server->setBaseUri($baseuri);
// Add plugins
$server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), \OC::$server->getL10N('dav')));
$server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), \OCP\Server::get(IL10nFactory::class)->get('dav')));
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
$server->addPlugin(new Plugin());
@ -104,4 +106,4 @@ $server->addPlugin(Server::get(CardDavRateLimitingPlugin::class));
$server->addPlugin(Server::get(CardDavValidatePlugin::class));
// And off we go!
$server->exec();
$server->start();

View file

@ -14,6 +14,7 @@ use OCA\DAV\Files\Sharing\FilesDropPlugin;
use OCA\DAV\Files\Sharing\PublicLinkCheckPlugin;
use OCA\DAV\Storage\PublicOwnerWrapper;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\App\IAppManager;
use OCP\BeforeSabrePubliclyLoadedEvent;
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
@ -26,16 +27,19 @@ use OCP\IRequest;
use OCP\ISession;
use OCP\ITagManager;
use OCP\IUserSession;
use OCP\L10N\IFactory as IL10nFactory;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
use Psr\Log\LoggerInterface;
// load needed apps
$RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging'];
Server::get(IAppManager::class)->loadApps($RUNTIME_APPTYPES);
OC_App::loadApps($RUNTIME_APPTYPES);
OC_Util::obEnd();
// Turn off output buffering to prevent memory problems
while (ob_get_level()) {
ob_end_clean();
}
Server::get(ISession::class)->close();
// Backends
@ -60,7 +64,7 @@ $serverFactory = new ServerFactory(
Server::get(IRequest::class),
Server::get(IPreview::class),
$eventDispatcher,
\OC::$server->getL10N('dav')
Server::get(IL10nFactory::class)->get('dav')
);
$requestUri = Server::get(IRequest::class)->getRequestUri();
@ -68,6 +72,7 @@ $requestUri = Server::get(IRequest::class)->getRequestUri();
$linkCheckPlugin = new PublicLinkCheckPlugin();
$filesDropPlugin = new FilesDropPlugin();
/** @var string $baseuri defined in public.php */
$server = $serverFactory->createServer(
true,
$baseuri,
@ -125,4 +130,4 @@ $event = new BeforeSabrePubliclyLoadedEvent($server);
$eventDispatcher->dispatchTyped($event);
// And off we go!
$server->exec();
$server->start();

View file

@ -19,6 +19,7 @@ use OCP\IRequest;
use OCP\ISession;
use OCP\ITagManager;
use OCP\IUserSession;
use OCP\L10N\IFactory as IL10nFactory;
use OCP\SabrePluginEvent;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
@ -31,7 +32,9 @@ if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
ignore_user_abort(true);
// Turn off output buffering to prevent memory problems
\OC_Util::obEnd();
while (ob_get_level()) {
ob_end_clean();
}
$dispatcher = Server::get(IEventDispatcher::class);
@ -45,7 +48,7 @@ $serverFactory = new ServerFactory(
Server::get(IRequest::class),
Server::get(IPreview::class),
$dispatcher,
\OC::$server->getL10N('dav')
Server::get(IL10nFactory::class)->get('dav')
);
// Backends
@ -68,6 +71,7 @@ $authPlugin->addBackend($bearerAuthPlugin);
$requestUri = Server::get(IRequest::class)->getRequestUri();
/** @var string $baseuri defined in remote.php */
$server = $serverFactory->createServer(false, $baseuri, $requestUri, $authPlugin, function () {
// use the view for the logged in user
return Filesystem::getView();
@ -80,4 +84,4 @@ $event = new SabrePluginAddEvent($server);
$dispatcher->dispatchTyped($event);
// And off we go!
$server->exec();
$server->start();

View file

@ -21,12 +21,15 @@ if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
ignore_user_abort(true);
// Turn off output buffering to prevent memory problems
\OC_Util::obEnd();
while (ob_get_level()) {
ob_end_clean();
}
$requestUri = Server::get(IRequest::class)->getRequestUri();
/** @var ServerFactory $serverFactory */
$serverFactory = Server::get(ServerFactory::class);
/** @var string $baseuri defined in remote.php */
$server = $serverFactory->createServer(
$baseuri,
$requestUri,
@ -37,4 +40,4 @@ $server = $serverFactory->createServer(
Server::get(IRequest::class)
);
$server->exec();
$server->start();

View file

@ -17,6 +17,7 @@ use OCA\DAV\Storage\PublicShareWrapper;
use OCA\DAV\Upload\ChunkingPlugin;
use OCA\DAV\Upload\ChunkingV2Plugin;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\App\IAppManager;
use OCP\BeforeSabrePubliclyLoadedEvent;
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
@ -41,8 +42,12 @@ use Sabre\DAV\Exception\NotFound;
// load needed apps
$RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging'];
OC_App::loadApps($RUNTIME_APPTYPES);
OC_Util::obEnd();
Server::get(IAppManager::class)->loadApps($RUNTIME_APPTYPES);
// Turn off output buffering to prevent memory problems
while (ob_get_level()) {
ob_end_clean();
}
$session = Server::get(ISession::class);
$request = Server::get(IRequest::class);

View file

@ -15,8 +15,11 @@ if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
ignore_user_abort(true);
// Turn off output buffering to prevent memory problems
\OC_Util::obEnd();
while (ob_get_level()) {
ob_end_clean();
}
$request = \OCP\Server::get(IRequest::class);
/** @var string $baseuri defined in remote.php */
$server = new Server($request, $baseuri);
$server->exec();

View file

@ -82,87 +82,23 @@
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/appinfo/v1/caldav.php">
<DeprecatedMethod>
<code><![CDATA[exec]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getL10NFactory]]></code>
</DeprecatedMethod>
<UndefinedGlobalVariable>
<code><![CDATA[$baseuri]]></code>
</UndefinedGlobalVariable>
</file>
<file src="apps/dav/appinfo/v1/carddav.php">
<DeprecatedMethod>
<code><![CDATA[exec]]></code>
<code><![CDATA[getL10N]]></code>
<code><![CDATA[getL10NFactory]]></code>
</DeprecatedMethod>
<UndefinedGlobalVariable>
<code><![CDATA[$baseuri]]></code>
</UndefinedGlobalVariable>
</file>
<file src="apps/dav/appinfo/v1/publicwebdav.php">
<DeprecatedClass>
<code><![CDATA[OC_Util::obEnd()]]></code>
</DeprecatedClass>
<DeprecatedMethod>
<code><![CDATA[OC_App::loadApps($RUNTIME_APPTYPES)]]></code>
<code><![CDATA[exec]]></code>
<code><![CDATA[getL10N]]></code>
</DeprecatedMethod>
<InternalMethod>
<code><![CDATA[Filesystem::logWarningWhenAddingStorageWrapper($previousLog)]]></code>
<code><![CDATA[Filesystem::logWarningWhenAddingStorageWrapper(false)]]></code>
<code><![CDATA[new View($node->getPath())]]></code>
</InternalMethod>
<UndefinedGlobalVariable>
<code><![CDATA[$baseuri]]></code>
</UndefinedGlobalVariable>
</file>
<file src="apps/dav/appinfo/v1/webdav.php">
<DeprecatedClass>
<code><![CDATA[\OC_Util::obEnd()]]></code>
</DeprecatedClass>
<DeprecatedMethod>
<code><![CDATA[dispatch]]></code>
<code><![CDATA[exec]]></code>
<code><![CDATA[getL10N]]></code>
</DeprecatedMethod>
<UndefinedGlobalVariable>
<code><![CDATA[$baseuri]]></code>
</UndefinedGlobalVariable>
</file>
<file src="apps/dav/appinfo/v2/direct.php">
<DeprecatedClass>
<code><![CDATA[\OC_Util::obEnd()]]></code>
</DeprecatedClass>
<DeprecatedMethod>
<code><![CDATA[exec]]></code>
</DeprecatedMethod>
<UndefinedGlobalVariable>
<code><![CDATA[$baseuri]]></code>
</UndefinedGlobalVariable>
</file>
<file src="apps/dav/appinfo/v2/publicremote.php">
<DeprecatedClass>
<code><![CDATA[OC_Util::obEnd()]]></code>
</DeprecatedClass>
<DeprecatedMethod>
<code><![CDATA[OC_App::loadApps($RUNTIME_APPTYPES)]]></code>
</DeprecatedMethod>
<InternalMethod>
<code><![CDATA[new View($node->getPath())]]></code>
</InternalMethod>
</file>
<file src="apps/dav/appinfo/v2/remote.php">
<DeprecatedClass>
<code><![CDATA[\OC_Util::obEnd()]]></code>
</DeprecatedClass>
<UndefinedGlobalVariable>
<code><![CDATA[$baseuri]]></code>
</UndefinedGlobalVariable>
</file>
<file src="apps/dav/lib/AppInfo/Application.php">
<DeprecatedMethod>
<code><![CDATA[register]]></code>
@ -663,7 +599,6 @@
<code><![CDATA[resolvePath]]></code>
<code><![CDATA[resolvePath]]></code>
<code><![CDATA[resolvePath]]></code>
<code><![CDATA[resolvePath]]></code>
<code><![CDATA[touch]]></code>
<code><![CDATA[unlink]]></code>
</InternalMethod>