diff --git a/Classes/Domain/Model/Application.php b/Classes/Domain/Model/Application.php index 9bcd991a..a28304e7 100644 --- a/Classes/Domain/Model/Application.php +++ b/Classes/Domain/Model/Application.php @@ -61,9 +61,11 @@ public function getTitle(): string return $this->title; } - public function setTitle(string $title): void + public function setTitle(string $title): self { $this->title = $title; + + return $this; } public function getClientId(): string @@ -71,9 +73,11 @@ public function getClientId(): string return $this->id; } - public function setId(string $id): void + public function setId(string $id): self { $this->id = $id; + + return $this; } public function getClientSecret(): string @@ -81,9 +85,11 @@ public function getClientSecret(): string return $this->secret; } - public function setSecret(string $secret): void + public function setSecret(string $secret): self { $this->secret = $secret; + + return $this; } public function getDomain(): string @@ -91,9 +97,11 @@ public function getDomain(): string return $this->domain; } - public function setDomain(string $domain): void + public function setDomain(string $domain): self { $this->domain = $domain; + + return $this; } public function getFullDomain(): string @@ -115,9 +123,11 @@ public function getAudience(bool $asFullDomain = false): string return $this->audience; } - public function setAudience(string $audience): void + public function setAudience(string $audience): self { $this->audience = trim($audience, '/') . '/'; + + return $this; } public function getApiBasePath(): string @@ -130,9 +140,11 @@ public function isSingleLogOut(): bool return $this->singleLogOut; } - public function setSingleLogOut(bool $singleLogOut): void + public function setSingleLogOut(bool $singleLogOut): self { $this->singleLogOut = $singleLogOut; + + return $this; } public function getSignatureAlgorithm(): string @@ -140,9 +152,11 @@ public function getSignatureAlgorithm(): string return $this->signatureAlgorithm; } - public function setSignatureAlgorithm(string $signatureAlgorithm): void + public function setSignatureAlgorithm(string $signatureAlgorithm): self { $this->signatureAlgorithm = $signatureAlgorithm; + + return $this; } public function isCustomDomain(): bool @@ -155,8 +169,23 @@ public function hasApi(): bool return $this->api; } - public function setApi(bool $api): void + public function setApi(bool $api): self { $this->api = $api; + + return $this; + } + + public static function fromArray(array $data): self + { + return (new self()) + ->setTitle($data['title']) + ->setId($data['id']) + ->setSecret($data['secret']) + ->setDomain($data['domain']) + ->setAudience($data['audience']) + ->setSingleLogOut((bool)$data['single_log_out']) + ->setSignatureAlgorithm($data['signature_algorithm'] ?? '') + ->setApi((bool)$data['api']); } } diff --git a/Classes/Domain/Repository/ApplicationRepository.php b/Classes/Domain/Repository/ApplicationRepository.php index 6d4e4f3c..755e9cba 100644 --- a/Classes/Domain/Repository/ApplicationRepository.php +++ b/Classes/Domain/Repository/ApplicationRepository.php @@ -16,7 +16,6 @@ use Leuchtfeuer\Auth0\Domain\Model\Application; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; class ApplicationRepository { @@ -24,7 +23,22 @@ class ApplicationRepository public function findByUid(int $uid): ?Application { - return GeneralUtility::makeInstance(PersistenceManager::class)->getObjectByIdentifier($uid, Application::class); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable(self::TABLE_NAME); + $applicationArray = $queryBuilder + ->select('*') + ->from(self::TABLE_NAME) + ->where( + $queryBuilder->expr()->eq('uid', $uid) + ) + ->setMaxResults(1) + ->executeQuery()->fetchAllAssociative() ?? []; + + if (empty($applicationArray)) { + return null; + } + + return Application::fromArray($applicationArray[0]); } public function findAll(): array diff --git a/Classes/Utility/TokenUtility.php b/Classes/Utility/TokenUtility.php index 7382a2a5..58621cd3 100644 --- a/Classes/Utility/TokenUtility.php +++ b/Classes/Utility/TokenUtility.php @@ -31,7 +31,6 @@ use Leuchtfeuer\Auth0\Middleware\CallbackMiddleware; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; -use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\Utility\GeneralUtility;