diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index 9631fce4cf..c73bc01db1 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -8,6 +8,7 @@ namespace OCA\Polls\Controller; +use OCA\Polls\Helper\Container; use OCA\Polls\Model\Settings\AppSettings; use OCA\Polls\Service\CommentService; use OCA\Polls\Service\MailService; @@ -20,7 +21,6 @@ use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\JSONResponse; use OCP\IRequest; -use OCP\Server; /** * @psalm-api @@ -47,7 +47,7 @@ public function __construct( #[FrontpageRoute(verb: 'GET', url: '/polls')] public function list(): JSONResponse { return $this->response(function () { - $appSettings = Server::get(AppSettings::class); + $appSettings = Container::queryClass(AppSettings::class); return [ 'list' => $this->pollService->list(), 'permissions' => [ diff --git a/lib/Cron/JanitorCron.php b/lib/Cron/JanitorCron.php index 0ff5954765..082233e8ef 100644 --- a/lib/Cron/JanitorCron.php +++ b/lib/Cron/JanitorCron.php @@ -15,11 +15,11 @@ use OCA\Polls\Db\PollMapper; use OCA\Polls\Db\ShareMapper; use OCA\Polls\Db\WatchMapper; +use OCA\Polls\Helper\Container; use OCA\Polls\Model\Settings\AppSettings; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; use OCP\ISession; -use OCP\Server; /** * @psalm-api @@ -39,7 +39,7 @@ public function __construct( ) { parent::__construct($time); parent::setInterval(86400); // run once a day - $this->appSettings = Server::get(AppSettings::class); + $this->appSettings = Container::queryClass(AppSettings::class); } /** diff --git a/lib/Db/EntityWithUser.php b/lib/Db/EntityWithUser.php index 805fd8e8b8..ed61b56777 100644 --- a/lib/Db/EntityWithUser.php +++ b/lib/Db/EntityWithUser.php @@ -8,11 +8,11 @@ namespace OCA\Polls\Db; +use OCA\Polls\Helper\Container; use OCA\Polls\Model\User\Anon; use OCA\Polls\Model\UserBase; use OCA\Polls\UserSession; use OCP\AppFramework\Db\Entity; -use OCP\Server; /** * @psalm-suppress UnusedProperty @@ -45,7 +45,7 @@ public function __construct() { * @return bool */ public function getCurrentUserIsEntityUser(): bool { - $userSession = Server::get(UserSession::class); + $userSession = Container::queryClass(UserSession::class); return $userSession->getCurrentUserId() === $this->getUserId(); } @@ -62,7 +62,7 @@ private function getEntityAnonymization(): bool { if ($this->getAnonymized() > 0) { // the poll is anonymized and unlocked - $userSession = Server::get(UserSession::class); + $userSession = Container::queryClass(UserSession::class); if ($this->getPollOwnerId() === $userSession->getCurrentUserId()) { // if the current user is the poll owner, don't anonymize the entity return false; @@ -98,7 +98,7 @@ public function getUser(): UserBase { return $user; } - $userMapper = (Server::get(UserMapper::class)); + $userMapper = (Container::queryClass(UserMapper::class)); $user = $userMapper->getParticipant($this->getUserId(), $this->getPollId()); return $user; diff --git a/lib/Db/Share.php b/lib/Db/Share.php index e7480f2bf5..aec4316848 100644 --- a/lib/Db/Share.php +++ b/lib/Db/Share.php @@ -10,8 +10,8 @@ use JsonSerializable; use OCA\Polls\AppConstants; +use OCA\Polls\Helper\Container; use OCP\IURLGenerator; -use OCP\Server; /** * @psalm-suppress UnusedProperty @@ -131,7 +131,7 @@ public function __construct() { $this->addType('locked', 'integer'); $this->addType('reminderSent', 'integer'); $this->addType('deleted', 'integer'); - $this->urlGenerator = Server::get(IURLGenerator::class); + $this->urlGenerator = Container::queryClass(IURLGenerator::class); } /** diff --git a/lib/Helper/Container.php b/lib/Helper/Container.php index 43ea1e2076..fba6ae6c97 100644 --- a/lib/Helper/Container.php +++ b/lib/Helper/Container.php @@ -17,18 +17,22 @@ use OCP\IL10N; use OCP\L10N\IFactory; use OCP\Server; +use Psr\Log\LoggerInterface; abstract class Container { /** * @param string $class * @return mixed - * @deprecated Use Server::get instead - * @psalm-suppress DeprecatedMethod */ public static function queryClass(string $class): mixed { return Server::get($class); } + /** @psalm-suppress PossiblyUnusedMethod */ + public static function logger(): LoggerInterface { + return Server::get(LoggerInterface::class); + } + public static function getPoll(int $pollId, bool $getDeleted = false): Poll { return Server::get(PollMapper::class)->get($pollId, $getDeleted); } diff --git a/lib/Model/UserBase.php b/lib/Model/UserBase.php index edf9ba725e..f5fbb37beb 100644 --- a/lib/Model/UserBase.php +++ b/lib/Model/UserBase.php @@ -26,7 +26,6 @@ use OCP\IDateTimeZone; use OCP\IGroupManager; use OCP\IL10N; -use OCP\Server; use OCP\Share\IShare; class UserBase implements JsonSerializable { @@ -69,10 +68,10 @@ public function __construct( protected string $timeZoneName = '', ) { $this->l10n = Container::getL10N(); - $this->groupManager = Server::get(IGroupManager::class); - $this->timeZone = Server::get(IDateTimeZone::class); - $this->userSession = Server::get(UserSession::class); - $this->appSettings = Server::get(AppSettings::class); + $this->groupManager = Container::queryClass(IGroupManager::class); + $this->timeZone = Container::queryClass(IDateTimeZone::class); + $this->userSession = Container::queryClass(UserSession::class); + $this->appSettings = Container::queryClass(AppSettings::class); } public function getId(): string {