Skip to content

Commit 2cdc81b

Browse files
committed
Refactor OC\Server::getRequest
Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com>
1 parent 9d1547f commit 2cdc81b

File tree

25 files changed

+63
-33
lines changed

25 files changed

+63
-33
lines changed

console.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
require_once __DIR__ . '/lib/versioncheck.php';
3535

3636
use OC\Console\Application;
37+
use OCP\IRequest;
3738
use Symfony\Component\Console\Input\ArgvInput;
3839
use Symfony\Component\Console\Output\ConsoleOutput;
3940

@@ -92,7 +93,7 @@ function exceptionHandler($exception) {
9293
$application = new Application(
9394
\OC::$server->getConfig(),
9495
\OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
95-
\OC::$server->getRequest(),
96+
\OC::$server->get(IRequest::class),
9697
\OC::$server->get(\Psr\Log\LoggerInterface::class),
9798
\OC::$server->query(\OC\MemoryInfo::class)
9899
);

index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*
3030
*/
3131
require_once __DIR__ . '/lib/versioncheck.php';
32+
33+
use OCP\IRequest;
3234
use Psr\Log\LoggerInterface;
3335

3436
try {
@@ -64,7 +66,7 @@
6466
OC_Template::printExceptionErrorPage($ex, 500);
6567
}
6668
} catch (\OC\User\LoginException $ex) {
67-
$request = \OC::$server->getRequest();
69+
$request = \OC::$server->get(IRequest::class);
6870
/**
6971
* Routes with the @CORS annotation and other API endpoints should
7072
* not return a webpage, so we only print the error page when html is accepted,

lib/private/AppFramework/App.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public static function main(string $controllerName, string $methodName, DIContai
216216
$expireDate,
217217
$container->getServer()->getWebRoot(),
218218
null,
219-
$container->getServer()->getRequest()->getServerProtocol() === 'https',
219+
$container->getServer()->get(IRequest::class)->getServerProtocol() === 'https',
220220
true,
221221
$sameSite
222222
);

lib/private/AppFramework/DependencyInjection/DIContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function __construct(string $appName, array $urlParams = [], ServerContai
179179
$this->registerService('Protocol', function (ContainerInterface $c) {
180180
/** @var \OC\Server $server */
181181
$server = $c->get(IServerContainer::class);
182-
$protocol = $server->getRequest()->getHttpProtocol();
182+
$protocol = $server->get(IRequest::class)->getHttpProtocol();
183183
return new Http($_SERVER, $protocol);
184184
});
185185

lib/private/Log.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use Nextcloud\LogNormalizer\Normalizer;
4141
use OCP\EventDispatcher\IEventDispatcher;
4242
use OCP\ILogger;
43+
use OCP\IRequest;
4344
use OCP\IUserSession;
4445
use OCP\Log\BeforeMessageLoggedEvent;
4546
use OCP\Log\IDataLogger;
@@ -263,7 +264,7 @@ public function getLogLevel($context) {
263264
if (!empty($logCondition)) {
264265
// check for secret token in the request
265266
if (isset($logCondition['shared_secret'])) {
266-
$request = \OC::$server->getRequest();
267+
$request = \OC::$server->get(IRequest::class);
267268

268269
if ($request->getMethod() === 'PUT' &&
269270
!str_contains($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded') &&

lib/private/Log/LogDetails.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
namespace OC\Log;
2727

2828
use OC\SystemConfig;
29+
use OCP\IRequest;
2930

3031
abstract class LogDetails {
3132
/** @var SystemConfig */
@@ -51,7 +52,7 @@ public function logDetails(string $app, $message, int $level): array {
5152
// apply timezone if $time is created from UNIX timestamp
5253
$time->setTimezone($timezone);
5354
}
54-
$request = \OC::$server->getRequest();
55+
$request = \OC::$server->get(IRequest::class);
5556
$reqId = $request->getId();
5657
$remoteAddr = $request->getRemoteAddress();
5758
// remove username/passwords from URLs before writing the to the log file

lib/private/Server.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ public function __construct($webRoot, \OC\Config $config) {
627627
$this->registerService(IFactory::class, function (Server $c) {
628628
return new \OC\L10N\Factory(
629629
$c->get(\OCP\IConfig::class),
630-
$c->getRequest(),
630+
$c->get(IRequest::class),
631631
$c->get(IUserSession::class),
632632
$c->get(ICacheFactory::class),
633633
\OC::$SERVERROOT
@@ -707,7 +707,7 @@ public function __construct($webRoot, \OC\Config $config) {
707707
$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
708708
$l10n = $this->get(IFactory::class)->get('lib');
709709
return new \OC\Activity\Manager(
710-
$c->getRequest(),
710+
$c->get(IRequest::class),
711711
$c->get(IUserSession::class),
712712
$c->get(\OCP\IConfig::class),
713713
$c->get(IValidator::class),
@@ -1161,7 +1161,7 @@ public function __construct($webRoot, \OC\Config $config) {
11611161
$classExists = false;
11621162
}
11631163

1164-
if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1164+
if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->get(IRequest::class)->getInsecureServerHost())) {
11651165
$imageManager = new ImageManager(
11661166
$c->get(\OCP\IConfig::class),
11671167
$c->getAppDataDir('theming'),

lib/private/Setup.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
use OCP\Defaults;
6161
use OCP\IGroup;
6262
use OCP\IL10N;
63+
use OCP\IRequest;
6364
use OCP\Security\ISecureRandom;
6465
use Psr\Log\LoggerInterface;
6566

@@ -313,7 +314,7 @@ public function install($options) {
313314
return $error;
314315
}
315316

316-
$request = \OC::$server->getRequest();
317+
$request = \OC::$server->get(IRequest::class);
317318

318319
//no errors, good
319320
if (isset($options['trusted_domains'])

lib/private/TemplateLayout.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use OCP\IConfig;
5353
use OCP\IInitialStateService;
5454
use OCP\INavigationManager;
55+
use OCP\IRequest;
5556
use OCP\IUserSession;
5657
use OCP\Support\Subscription\IRegistry;
5758
use OCP\Util;
@@ -251,7 +252,7 @@ public function __construct($renderAs, $appId = '') {
251252
}
252253

253254
try {
254-
$pathInfo = \OC::$server->getRequest()->getPathInfo();
255+
$pathInfo = \OC::$server->get(IRequest::class)->getPathInfo();
255256
} catch (\Exception $e) {
256257
$pathInfo = '';
257258
}

lib/private/User/Manager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OCP\ICacheFactory;
4343
use OCP\IConfig;
4444
use OCP\IGroup;
45+
use OCP\IRequest;
4546
use OCP\IUser;
4647
use OCP\IUserBackend;
4748
use OCP\IUserManager;
@@ -234,7 +235,7 @@ public function checkPassword($loginName, $password) {
234235
$result = $this->checkPasswordNoLogging($loginName, $password);
235236

236237
if ($result === false) {
237-
\OC::$server->getLogger()->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']);
238+
\OC::$server->getLogger()->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->get(IRequest::class)->getRemoteAddress(). '\')', ['app' => 'core']);
238239
}
239240

240241
return $result;

0 commit comments

Comments
 (0)