Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Controller/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +21,6 @@
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\Server;

/**
* @psalm-api
Expand All @@ -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' => [
Expand Down
4 changes: 2 additions & 2 deletions lib/Cron/JanitorCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/Db/EntityWithUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

use JsonSerializable;
use OCA\Polls\AppConstants;
use OCA\Polls\Helper\Container;
use OCP\IURLGenerator;
use OCP\Server;

/**
* @psalm-suppress UnusedProperty
Expand Down Expand Up @@ -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);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions lib/Helper/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 4 additions & 5 deletions lib/Model/UserBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use OCP\IDateTimeZone;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\Server;
use OCP\Share\IShare;

class UserBase implements JsonSerializable {
Expand Down Expand Up @@ -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 {
Expand Down