2013-08-17 05:16:48 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2025-06-16 12:00:28 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2013-08-17 05:16:48 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-08-17 05:16:48 -04:00
|
|
|
*/
|
2025-06-16 12:00:28 -04:00
|
|
|
|
2013-08-17 05:16:48 -04:00
|
|
|
namespace OC\AppFramework\DependencyInjection;
|
|
|
|
|
|
2013-10-22 23:57:34 -04:00
|
|
|
use OC\AppFramework\Http;
|
2013-08-17 05:16:48 -04:00
|
|
|
use OC\AppFramework\Http\Dispatcher;
|
2015-01-22 14:26:46 -05:00
|
|
|
use OC\AppFramework\Http\Output;
|
2025-07-01 05:11:07 -04:00
|
|
|
use OC\AppFramework\Middleware\AdditionalScriptsMiddleware;
|
|
|
|
|
use OC\AppFramework\Middleware\CompressionMiddleware;
|
2025-02-10 10:42:48 -05:00
|
|
|
use OC\AppFramework\Middleware\FlowV2EphemeralSessionsMiddleware;
|
2013-08-17 05:16:48 -04:00
|
|
|
use OC\AppFramework\Middleware\MiddlewareDispatcher;
|
2025-07-01 05:11:07 -04:00
|
|
|
use OC\AppFramework\Middleware\NotModifiedMiddleware;
|
2016-07-20 03:43:02 -04:00
|
|
|
use OC\AppFramework\Middleware\OCSMiddleware;
|
2025-07-01 05:11:07 -04:00
|
|
|
use OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware;
|
|
|
|
|
use OC\AppFramework\Middleware\Security\BruteForceMiddleware;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OC\AppFramework\Middleware\Security\CORSMiddleware;
|
2025-07-01 05:11:07 -04:00
|
|
|
use OC\AppFramework\Middleware\Security\CSPMiddleware;
|
|
|
|
|
use OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware;
|
|
|
|
|
use OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware;
|
2017-04-12 16:14:11 -04:00
|
|
|
use OC\AppFramework\Middleware\Security\RateLimitingMiddleware;
|
2025-07-01 05:11:07 -04:00
|
|
|
use OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware;
|
|
|
|
|
use OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware;
|
2016-05-11 05:23:25 -04:00
|
|
|
use OC\AppFramework\Middleware\Security\SecurityMiddleware;
|
2014-10-21 08:53:10 -04:00
|
|
|
use OC\AppFramework\Middleware\SessionMiddleware;
|
2020-07-16 13:11:47 -04:00
|
|
|
use OC\AppFramework\ScopedPsrLogger;
|
2013-08-20 11:21:14 -04:00
|
|
|
use OC\AppFramework\Utility\SimpleContainer;
|
2016-05-11 05:23:25 -04:00
|
|
|
use OC\Core\Middleware\TwoFactorMiddleware;
|
2022-02-02 03:57:50 -05:00
|
|
|
use OC\Diagnostics\EventLogger;
|
2025-06-19 08:02:30 -04:00
|
|
|
use OC\Log\PsrLoggerAdapter;
|
2017-03-19 18:14:47 -04:00
|
|
|
use OC\ServerContainer;
|
2021-07-22 05:41:29 -04:00
|
|
|
use OC\Settings\AuthorizedGroupMapper;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\WorkflowEngine\Manager;
|
2025-08-08 10:30:58 -04:00
|
|
|
use OCP\App\IAppManager;
|
2017-03-21 05:00:02 -04:00
|
|
|
use OCP\AppFramework\Http\IOutput;
|
2013-08-20 19:02:15 -04:00
|
|
|
use OCP\AppFramework\IAppContainer;
|
2017-03-22 05:33:30 -04:00
|
|
|
use OCP\AppFramework\QueryException;
|
2020-05-02 09:34:28 -04:00
|
|
|
use OCP\AppFramework\Services\IAppConfig;
|
2020-05-07 04:13:06 -04:00
|
|
|
use OCP\AppFramework\Services\IInitialState;
|
2018-11-01 06:29:29 -04:00
|
|
|
use OCP\AppFramework\Utility\IControllerMethodReflector;
|
2025-06-19 08:02:30 -04:00
|
|
|
use OCP\Files\AppData\IAppDataFactory;
|
2017-03-21 05:00:02 -04:00
|
|
|
use OCP\Files\Folder;
|
2016-09-08 09:20:39 -04:00
|
|
|
use OCP\Files\IAppData;
|
2019-05-22 04:48:51 -04:00
|
|
|
use OCP\Group\ISubAdmin;
|
2020-07-14 03:18:39 -04:00
|
|
|
use OCP\IConfig;
|
2020-09-25 08:47:14 -04:00
|
|
|
use OCP\IDBConnection;
|
2024-06-20 12:44:52 -04:00
|
|
|
use OCP\IGroupManager;
|
2017-03-21 05:00:02 -04:00
|
|
|
use OCP\IL10N;
|
2018-11-23 05:11:10 -05:00
|
|
|
use OCP\INavigationManager;
|
2018-11-01 06:29:29 -04:00
|
|
|
use OCP\IRequest;
|
2017-03-19 17:20:56 -04:00
|
|
|
use OCP\IServerContainer;
|
2025-06-17 09:00:01 -04:00
|
|
|
use OCP\ISession;
|
2018-11-23 05:11:10 -05:00
|
|
|
use OCP\IURLGenerator;
|
2017-03-21 05:00:02 -04:00
|
|
|
use OCP\IUserSession;
|
2024-07-17 09:25:51 -04:00
|
|
|
use OCP\Security\Ip\IRemoteAddress;
|
2020-07-13 05:18:14 -04:00
|
|
|
use Psr\Container\ContainerInterface;
|
2020-07-16 13:11:47 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2014-12-13 13:28:20 -05:00
|
|
|
class DIContainer extends SimpleContainer implements IAppContainer {
|
2025-08-06 10:11:25 -04:00
|
|
|
protected string $appName;
|
2025-06-16 12:00:28 -04:00
|
|
|
private array $middleWares = [];
|
|
|
|
|
private ServerContainer $server;
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2024-03-28 11:13:19 -04:00
|
|
|
public function __construct(string $appName, array $urlParams = [], ?ServerContainer $server = null) {
|
2015-07-24 07:43:50 -04:00
|
|
|
parent::__construct();
|
2022-11-16 12:54:25 -05:00
|
|
|
$this->appName = $appName;
|
2025-06-16 12:00:28 -04:00
|
|
|
$this->registerParameter('appName', $appName);
|
|
|
|
|
$this->registerParameter('urlParams', $urlParams);
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2025-06-16 12:00:28 -04:00
|
|
|
/** @deprecated 32.0.0 */
|
|
|
|
|
$this->registerDeprecatedAlias('Request', IRequest::class);
|
2018-11-01 06:29:29 -04:00
|
|
|
|
2017-03-19 17:20:56 -04:00
|
|
|
if ($server === null) {
|
2017-03-19 18:14:47 -04:00
|
|
|
$server = \OC::$server;
|
2017-03-19 17:20:56 -04:00
|
|
|
}
|
2017-03-19 18:14:47 -04:00
|
|
|
$this->server = $server;
|
2017-03-19 17:20:56 -04:00
|
|
|
$this->server->registerAppContainer($appName, $this);
|
2015-12-18 05:43:39 -05:00
|
|
|
|
2015-04-29 16:29:45 -04:00
|
|
|
// aliases
|
2024-09-18 17:51:06 -04:00
|
|
|
/** @deprecated 26.0.0 inject $appName */
|
2025-06-16 12:00:28 -04:00
|
|
|
$this->registerDeprecatedAlias('AppName', 'appName');
|
2024-09-18 17:51:06 -04:00
|
|
|
/** @deprecated 26.0.0 inject $webRoot*/
|
2025-06-16 12:00:28 -04:00
|
|
|
$this->registerDeprecatedAlias('WebRoot', 'webRoot');
|
2024-09-18 17:51:06 -04:00
|
|
|
/** @deprecated 26.0.0 inject $userId */
|
2025-06-16 12:00:28 -04:00
|
|
|
$this->registerDeprecatedAlias('UserId', 'userId');
|
2015-04-29 16:29:45 -04:00
|
|
|
|
2014-12-13 13:28:20 -05:00
|
|
|
/**
|
|
|
|
|
* Core services
|
|
|
|
|
*/
|
2025-06-16 12:00:28 -04:00
|
|
|
/* Cannot be an alias because Output is not in OCA */
|
|
|
|
|
$this->registerService(IOutput::class, fn (ContainerInterface $c): IOutput => new Output($c->get('webRoot')));
|
2015-01-22 14:26:46 -05:00
|
|
|
|
2020-04-09 07:53:40 -04:00
|
|
|
$this->registerService(Folder::class, function () {
|
2016-05-09 04:02:07 -04:00
|
|
|
return $this->getServer()->getUserFolder();
|
|
|
|
|
});
|
|
|
|
|
|
2025-06-16 12:00:28 -04:00
|
|
|
$this->registerService(IAppData::class, function (ContainerInterface $c): IAppData {
|
2025-06-19 08:02:30 -04:00
|
|
|
return $c->get(IAppDataFactory::class)->get($c->get('appName'));
|
2016-09-08 09:20:39 -04:00
|
|
|
});
|
|
|
|
|
|
2020-07-13 05:18:14 -04:00
|
|
|
$this->registerService(IL10N::class, function (ContainerInterface $c) {
|
2025-06-16 12:00:28 -04:00
|
|
|
return $this->getServer()->getL10N($c->get('appName'));
|
2014-12-13 13:28:20 -05:00
|
|
|
});
|
|
|
|
|
|
2020-07-16 13:11:47 -04:00
|
|
|
// Log wrappers
|
2025-06-19 08:02:30 -04:00
|
|
|
$this->registerService(LoggerInterface::class, function (ContainerInterface $c) {
|
|
|
|
|
/* Cannot be an alias because it uses LoggerInterface so it would infinite loop */
|
|
|
|
|
return new ScopedPsrLogger(
|
|
|
|
|
$c->get(PsrLoggerAdapter::class),
|
|
|
|
|
$c->get('appName')
|
|
|
|
|
);
|
|
|
|
|
});
|
2018-09-04 04:05:25 -04:00
|
|
|
|
2018-11-23 05:11:10 -05:00
|
|
|
$this->registerService(IServerContainer::class, function () {
|
2015-01-22 09:33:09 -05:00
|
|
|
return $this->getServer();
|
2014-12-13 13:28:20 -05:00
|
|
|
});
|
2025-06-16 12:00:28 -04:00
|
|
|
/** @deprecated 32.0.0 */
|
|
|
|
|
$this->registerDeprecatedAlias('ServerContainer', IServerContainer::class);
|
2014-12-13 13:28:20 -05:00
|
|
|
|
2025-06-16 12:00:28 -04:00
|
|
|
$this->registerAlias(\OCP\WorkflowEngine\IManager::class, Manager::class);
|
2016-07-27 05:46:09 -04:00
|
|
|
|
2025-06-19 10:37:32 -04:00
|
|
|
$this->registerService(ContainerInterface::class, fn (ContainerInterface $c) => $c);
|
2025-06-16 12:00:28 -04:00
|
|
|
$this->registerDeprecatedAlias(IAppContainer::class, ContainerInterface::class);
|
2015-10-20 04:32:53 -04:00
|
|
|
|
2014-12-13 13:28:20 -05:00
|
|
|
// commonly used attributes
|
2025-06-17 09:00:01 -04:00
|
|
|
$this->registerService('userId', function (ContainerInterface $c): ?string {
|
|
|
|
|
return $c->get(ISession::class)->get('user_id');
|
2014-12-13 13:28:20 -05:00
|
|
|
});
|
|
|
|
|
|
2025-06-16 12:00:28 -04:00
|
|
|
$this->registerService('webRoot', function (ContainerInterface $c): string {
|
2020-07-13 05:18:14 -04:00
|
|
|
return $c->get(IServerContainer::class)->getWebRoot();
|
2014-12-13 13:28:20 -05:00
|
|
|
});
|
|
|
|
|
|
2025-06-16 12:00:28 -04:00
|
|
|
$this->registerService('OC_Defaults', function (ContainerInterface $c): object {
|
2023-08-29 19:54:23 -04:00
|
|
|
return $c->get(IServerContainer::class)->get('ThemingDefaults');
|
2017-02-24 14:09:09 -05:00
|
|
|
});
|
|
|
|
|
|
2025-06-16 12:00:28 -04:00
|
|
|
/** @deprecated 32.0.0 */
|
|
|
|
|
$this->registerDeprecatedAlias('Protocol', Http::class);
|
|
|
|
|
$this->registerService(Http::class, function (ContainerInterface $c) {
|
|
|
|
|
$protocol = $c->get(IRequest::class)->getHttpProtocol();
|
2015-10-30 13:05:30 -04:00
|
|
|
return new Http($_SERVER, $protocol);
|
2013-08-17 05:16:48 -04:00
|
|
|
});
|
|
|
|
|
|
2025-06-16 12:00:28 -04:00
|
|
|
/** @deprecated 32.0.0 */
|
|
|
|
|
$this->registerDeprecatedAlias('Dispatcher', Dispatcher::class);
|
|
|
|
|
$this->registerService(Dispatcher::class, function (ContainerInterface $c) {
|
2014-05-06 10:29:19 -04:00
|
|
|
return new Dispatcher(
|
2025-08-06 10:12:44 -04:00
|
|
|
$c->get(Http::class),
|
2020-07-13 05:18:14 -04:00
|
|
|
$c->get(MiddlewareDispatcher::class),
|
|
|
|
|
$c->get(IControllerMethodReflector::class),
|
2020-09-25 08:47:14 -04:00
|
|
|
$c->get(IRequest::class),
|
|
|
|
|
$c->get(IConfig::class),
|
|
|
|
|
$c->get(IDBConnection::class),
|
2022-02-02 03:57:50 -05:00
|
|
|
$c->get(LoggerInterface::class),
|
2022-12-15 04:37:27 -05:00
|
|
|
$c->get(EventLogger::class),
|
|
|
|
|
$c,
|
2014-05-06 10:29:19 -04:00
|
|
|
);
|
2013-08-17 05:16:48 -04:00
|
|
|
});
|
|
|
|
|
|
2016-07-22 04:11:53 -04:00
|
|
|
/**
|
|
|
|
|
* App Framework default arguments
|
|
|
|
|
*/
|
|
|
|
|
$this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
|
|
|
|
|
$this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
|
|
|
|
|
$this->registerParameter('corsMaxAge', 1728000);
|
2013-08-17 05:16:48 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Middleware
|
|
|
|
|
*/
|
2025-06-16 12:00:28 -04:00
|
|
|
/** @deprecated 32.0.0 */
|
|
|
|
|
$this->registerDeprecatedAlias('MiddlewareDispatcher', MiddlewareDispatcher::class);
|
2020-07-13 05:18:14 -04:00
|
|
|
$this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) {
|
|
|
|
|
$server = $this->getServer();
|
2018-11-23 05:11:10 -05:00
|
|
|
|
|
|
|
|
$dispatcher = new MiddlewareDispatcher();
|
2020-04-02 08:07:40 -04:00
|
|
|
|
2025-07-01 05:11:07 -04:00
|
|
|
$dispatcher->registerMiddleware($c->get(CompressionMiddleware::class));
|
|
|
|
|
$dispatcher->registerMiddleware($c->get(NotModifiedMiddleware::class));
|
|
|
|
|
$dispatcher->registerMiddleware($c->get(ReloadExecutionMiddleware::class));
|
|
|
|
|
$dispatcher->registerMiddleware($c->get(SameSiteCookieMiddleware::class));
|
|
|
|
|
$dispatcher->registerMiddleware($c->get(CORSMiddleware::class));
|
|
|
|
|
$dispatcher->registerMiddleware($c->get(OCSMiddleware::class));
|
2017-01-17 05:51:10 -05:00
|
|
|
|
2025-02-27 07:12:55 -05:00
|
|
|
$dispatcher->registerMiddleware($c->get(FlowV2EphemeralSessionsMiddleware::class));
|
2021-03-02 13:34:20 -05:00
|
|
|
|
2018-11-23 05:11:10 -05:00
|
|
|
$securityMiddleware = new SecurityMiddleware(
|
2020-07-13 05:18:14 -04:00
|
|
|
$c->get(IRequest::class),
|
|
|
|
|
$c->get(IControllerMethodReflector::class),
|
|
|
|
|
$c->get(INavigationManager::class),
|
|
|
|
|
$c->get(IURLGenerator::class),
|
2025-06-16 12:00:28 -04:00
|
|
|
$c->get(LoggerInterface::class),
|
|
|
|
|
$c->get('appName'),
|
2018-01-13 08:13:59 -05:00
|
|
|
$server->getUserSession()->isLoggedIn(),
|
2024-06-20 12:44:52 -04:00
|
|
|
$c->get(IGroupManager::class),
|
|
|
|
|
$c->get(ISubAdmin::class),
|
2025-08-08 10:30:58 -04:00
|
|
|
$c->get(IAppManager::class),
|
2021-07-22 05:41:29 -04:00
|
|
|
$server->getL10N('lib'),
|
|
|
|
|
$c->get(AuthorizedGroupMapper::class),
|
2025-06-16 12:00:28 -04:00
|
|
|
$c->get(IUserSession::class),
|
2024-07-17 09:25:51 -04:00
|
|
|
$c->get(IRemoteAddress::class),
|
2014-05-06 10:29:19 -04:00
|
|
|
);
|
2018-11-23 05:11:10 -05:00
|
|
|
$dispatcher->registerMiddleware($securityMiddleware);
|
2025-07-01 05:11:07 -04:00
|
|
|
$dispatcher->registerMiddleware($c->get(CSPMiddleware::class));
|
|
|
|
|
$dispatcher->registerMiddleware($c->get(FeaturePolicyMiddleware::class));
|
|
|
|
|
$dispatcher->registerMiddleware($c->get(PasswordConfirmationMiddleware::class));
|
|
|
|
|
$dispatcher->registerMiddleware($c->get(TwoFactorMiddleware::class));
|
|
|
|
|
$dispatcher->registerMiddleware($c->get(BruteForceMiddleware::class));
|
2025-01-17 09:01:07 -05:00
|
|
|
$dispatcher->registerMiddleware($c->get(RateLimitingMiddleware::class));
|
2025-07-01 05:11:07 -04:00
|
|
|
$dispatcher->registerMiddleware($c->get(PublicShareMiddleware::class));
|
|
|
|
|
$dispatcher->registerMiddleware($c->get(AdditionalScriptsMiddleware::class));
|
2017-09-22 06:21:44 -04:00
|
|
|
|
2023-01-23 05:27:28 -05:00
|
|
|
$coordinator = $c->get(\OC\AppFramework\Bootstrap\Coordinator::class);
|
|
|
|
|
$registrationContext = $coordinator->getRegistrationContext();
|
|
|
|
|
if ($registrationContext !== null) {
|
2025-06-16 12:00:28 -04:00
|
|
|
$appId = $this->get('appName');
|
2023-01-23 05:27:28 -05:00
|
|
|
foreach ($registrationContext->getMiddlewareRegistrations() as $middlewareRegistration) {
|
2023-01-23 11:11:39 -05:00
|
|
|
if ($middlewareRegistration->getAppId() === $appId
|
|
|
|
|
|| $middlewareRegistration->isGlobal()) {
|
2023-01-23 05:27:28 -05:00
|
|
|
$dispatcher->registerMiddleware($c->get($middlewareRegistration->getService()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-23 05:11:10 -05:00
|
|
|
foreach ($this->middleWares as $middleWare) {
|
2020-07-13 05:18:14 -04:00
|
|
|
$dispatcher->registerMiddleware($c->get($middleWare));
|
2013-09-27 11:15:26 -04:00
|
|
|
}
|
|
|
|
|
|
2025-07-01 05:11:07 -04:00
|
|
|
$dispatcher->registerMiddleware($c->get(SessionMiddleware::class));
|
2013-08-17 05:16:48 -04:00
|
|
|
return $dispatcher;
|
|
|
|
|
});
|
|
|
|
|
|
2025-06-16 12:00:28 -04:00
|
|
|
$this->registerAlias(IAppConfig::class, \OC\AppFramework\Services\AppConfig::class);
|
|
|
|
|
$this->registerAlias(IInitialState::class, \OC\AppFramework\Services\InitialState::class);
|
2013-08-17 05:16:48 -04:00
|
|
|
}
|
|
|
|
|
|
2013-08-20 19:02:15 -04:00
|
|
|
/**
|
2013-08-31 15:34:29 -04:00
|
|
|
* @return \OCP\IServerContainer
|
2013-08-20 19:02:15 -04:00
|
|
|
*/
|
2017-07-23 15:03:26 -04:00
|
|
|
public function getServer() {
|
2017-03-19 17:20:56 -04:00
|
|
|
return $this->server;
|
2013-08-20 19:02:15 -04:00
|
|
|
}
|
2013-09-25 04:30:48 -04:00
|
|
|
|
|
|
|
|
/**
|
2014-04-09 17:59:57 -04:00
|
|
|
* @param string $middleWare
|
2013-09-25 04:30:48 -04:00
|
|
|
*/
|
2025-06-16 12:00:28 -04:00
|
|
|
public function registerMiddleWare($middleWare): bool {
|
2019-05-06 05:28:18 -04:00
|
|
|
if (in_array($middleWare, $this->middleWares, true) !== false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-01-25 16:36:03 -05:00
|
|
|
$this->middleWares[] = $middleWare;
|
2025-06-16 12:00:28 -04:00
|
|
|
return true;
|
2013-09-25 04:30:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* used to return the appname of the set application
|
|
|
|
|
* @return string the name of your application
|
|
|
|
|
*/
|
2017-07-23 15:03:26 -04:00
|
|
|
public function getAppName() {
|
2025-06-16 12:00:28 -04:00
|
|
|
return $this->query('appName');
|
2013-09-25 04:30:48 -04:00
|
|
|
}
|
2013-10-06 18:33:54 -04:00
|
|
|
|
|
|
|
|
/**
|
2024-09-18 17:51:06 -04:00
|
|
|
* @deprecated 12.0.0 use IUserSession->isLoggedIn()
|
2013-10-06 18:33:54 -04:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2017-07-23 15:03:26 -04:00
|
|
|
public function isLoggedIn() {
|
2017-03-02 10:52:05 -05:00
|
|
|
return \OC::$server->getUserSession()->isLoggedIn();
|
2013-10-06 18:33:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-09-18 17:51:06 -04:00
|
|
|
* @deprecated 12.0.0 use IGroupManager->isAdmin($userId)
|
2013-10-06 18:33:54 -04:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2017-07-23 15:03:26 -04:00
|
|
|
public function isAdminUser() {
|
2013-10-06 18:33:54 -04:00
|
|
|
$uid = $this->getUserId();
|
|
|
|
|
return \OC_User::isAdminUser($uid);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-16 12:00:28 -04:00
|
|
|
private function getUserId(): string {
|
2015-01-22 09:33:09 -05:00
|
|
|
return $this->getServer()->getSession()->get('user_id');
|
2013-10-06 18:33:54 -04:00
|
|
|
}
|
|
|
|
|
|
2015-07-22 07:04:56 -04:00
|
|
|
/**
|
|
|
|
|
* Register a capability
|
|
|
|
|
*
|
|
|
|
|
* @param string $serviceName e.g. 'OCA\Files\Capabilities'
|
|
|
|
|
*/
|
|
|
|
|
public function registerCapability($serviceName) {
|
2020-04-09 07:53:40 -04:00
|
|
|
$this->query('OC\CapabilitiesManager')->registerCapability(function () use ($serviceName) {
|
2015-07-22 07:04:56 -04:00
|
|
|
return $this->query($serviceName);
|
|
|
|
|
});
|
2016-10-28 15:46:28 -04:00
|
|
|
}
|
2014-12-13 13:28:20 -05:00
|
|
|
|
2020-07-13 05:18:14 -04:00
|
|
|
public function has($id): bool {
|
|
|
|
|
if (parent::has($id)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->server->has($id, true)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-30 08:20:15 -04:00
|
|
|
public function query(string $name, bool $autoload = true) {
|
2022-11-16 12:54:25 -05:00
|
|
|
if ($name === 'AppName' || $name === 'appName') {
|
|
|
|
|
return $this->appName;
|
|
|
|
|
}
|
2022-11-16 14:21:33 -05:00
|
|
|
|
|
|
|
|
$isServerClass = str_starts_with($name, 'OCP\\') || str_starts_with($name, 'OC\\');
|
|
|
|
|
if ($isServerClass && !$this->has($name)) {
|
|
|
|
|
return $this->getServer()->query($name, $autoload);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 05:33:30 -04:00
|
|
|
try {
|
|
|
|
|
return $this->queryNoFallback($name);
|
2017-09-12 05:54:13 -04:00
|
|
|
} catch (QueryException $firstException) {
|
|
|
|
|
try {
|
2019-05-30 08:20:15 -04:00
|
|
|
return $this->getServer()->query($name, $autoload);
|
2017-09-12 05:54:13 -04:00
|
|
|
} catch (QueryException $secondException) {
|
|
|
|
|
if ($firstException->getCode() === 1) {
|
|
|
|
|
throw $secondException;
|
|
|
|
|
}
|
|
|
|
|
throw $firstException;
|
|
|
|
|
}
|
2017-03-22 05:33:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws QueryException if the query could not be resolved
|
|
|
|
|
*/
|
|
|
|
|
public function queryNoFallback($name) {
|
2017-03-17 09:25:35 -04:00
|
|
|
$name = $this->sanitizeName($name);
|
2017-03-19 17:09:47 -04:00
|
|
|
|
2017-03-19 18:14:47 -04:00
|
|
|
if ($this->offsetExists($name)) {
|
2017-03-17 09:25:35 -04:00
|
|
|
return parent::query($name);
|
2022-11-21 05:40:34 -05:00
|
|
|
} elseif ($this->appName === 'settings' && str_starts_with($name, 'OC\\Settings\\')) {
|
2020-07-13 05:18:14 -04:00
|
|
|
return parent::query($name);
|
2022-11-21 05:40:34 -05:00
|
|
|
} elseif ($this->appName === 'core' && str_starts_with($name, 'OC\\Core\\')) {
|
2020-07-13 05:18:14 -04:00
|
|
|
return parent::query($name);
|
2022-11-21 05:40:34 -05:00
|
|
|
} elseif (str_starts_with($name, \OC\AppFramework\App::buildAppNamespace($this->appName) . '\\')) {
|
2020-07-13 05:18:14 -04:00
|
|
|
return parent::query($name);
|
2025-07-01 05:11:07 -04:00
|
|
|
} elseif (
|
|
|
|
|
str_starts_with($name, 'OC\\AppFramework\\Services\\')
|
|
|
|
|
|| str_starts_with($name, 'OC\\AppFramework\\Middleware\\')
|
|
|
|
|
) {
|
2025-06-17 09:00:01 -04:00
|
|
|
/* AppFramework services are scoped to the application */
|
|
|
|
|
return parent::query($name);
|
2017-03-17 09:25:35 -04:00
|
|
|
}
|
|
|
|
|
|
2017-03-22 05:33:30 -04:00
|
|
|
throw new QueryException('Could not resolve ' . $name . '!'
|
2017-09-12 05:54:13 -04:00
|
|
|
. ' Class can not be instantiated', 1);
|
2015-07-22 07:04:56 -04:00
|
|
|
}
|
2013-08-17 05:16:48 -04:00
|
|
|
}
|