Skip to content

Commit

Permalink
Refactor runtimexceptions to exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed Mar 6, 2024
1 parent b444d32 commit 0951625
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Exception/NoAuthTokenFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

namespace Pimcore\Bundle\StudioApiBundle\Exception;

use RuntimeException;
use Exception;

final class NoAuthTokenFound extends RuntimeException
final class NoAuthTokenFound extends Exception
{
}
4 changes: 2 additions & 2 deletions src/Exception/NoRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

namespace Pimcore\Bundle\StudioApiBundle\Exception;

use RuntimeException;
use Exception;

final class NoRequestException extends RuntimeException
final class NoRequestException extends Exception
{
}
4 changes: 2 additions & 2 deletions src/Exception/NonPublicTranslationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

namespace Pimcore\Bundle\StudioApiBundle\Exception;

use RuntimeException;
use Exception;

final class NonPublicTranslationException extends RuntimeException
final class NonPublicTranslationException extends Exception
{
}
3 changes: 3 additions & 0 deletions src/Security/Trait/PublicTranslationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ trait PublicTranslationTrait
{
private const ARRAY_KEYS_INDEX = 'keys';

/**
* @throws NonPublicTranslationException
*/
private function voteOnTranslation(InputBag $payload): bool
{
$parameters = $payload->all();
Expand Down
6 changes: 6 additions & 0 deletions src/Security/Trait/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ trait RequestTrait

private const AUTHORIZATION_HEADER = 'Authorization';

/**
* @throws NoAuthTokenFound
*/
private function getAuthToken(Request $request): string
{
$authToken = $request->headers->get(self::AUTHORIZATION_HEADER);
Expand All @@ -37,6 +40,9 @@ private function getAuthToken(Request $request): string
return $this->removeBearerPrefix($authToken);
}

/**
* @throws NoRequestException
*/
private function getCurrentRequest(RequestStack $requestStack): Request
{
$request = $requestStack->getCurrentRequest();
Expand Down
11 changes: 11 additions & 0 deletions src/Security/Voter/PublicTokenVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

namespace Pimcore\Bundle\StudioApiBundle\Security\Voter;

use Pimcore\Bundle\StudioApiBundle\Exception\NoAuthTokenFound;
use Pimcore\Bundle\StudioApiBundle\Exception\NonPublicTranslationException;
use Pimcore\Bundle\StudioApiBundle\Exception\NoRequestException;
use Pimcore\Bundle\StudioApiBundle\Security\Trait\PublicTranslationTrait;
use Pimcore\Bundle\StudioApiBundle\Security\Trait\RequestTrait;
use Pimcore\Bundle\StudioApiBundle\Service\SecurityServiceInterface;
Expand Down Expand Up @@ -44,6 +47,11 @@ protected function supports(string $attribute, mixed $subject): bool
return $attribute === self::SUPPORTED_ATTRIBUTE && in_array((string)$subject, self::SUPPORTED_SUBJECTS, true);
}

/**
* @throws NoRequestException
* @throws NoAuthTokenFound
* @throws NonPublicTranslationException
*/
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{

Expand All @@ -58,6 +66,9 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter
return $this->voteOnRequest($request, $subject);
}

/**
* @throws NonPublicTranslationException
*/
private function voteOnRequest(Request $request, string $subject): bool
{
return match ($subject) {
Expand Down
5 changes: 4 additions & 1 deletion src/Security/Voter/TokenVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace Pimcore\Bundle\StudioApiBundle\Security\Voter;

use Pimcore\Bundle\StudioApiBundle\Exception\NoAuthTokenFound;
use Pimcore\Bundle\StudioApiBundle\Exception\NoRequestException;
use Pimcore\Bundle\StudioApiBundle\Security\Trait\RequestTrait;
use Pimcore\Bundle\StudioApiBundle\Service\SecurityServiceInterface;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -44,7 +46,8 @@ protected function supports(string $attribute, mixed $subject): bool
}

/**
* @inheritDoc
* @throws NoRequestException
* @throws NoAuthTokenFound
*/
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
Expand Down

0 comments on commit 0951625

Please sign in to comment.