mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2024-12-04 23:17:19 +01:00
Prepared refactoring of exceptions
This commit is contained in:
parent
0e1d5ea024
commit
48a98cfc63
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\RequestManagement\Action;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Infinito\Domain\ReInfinito\Management\RequestedActionStackInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Infinito\Exception\AllreadySetException;
|
||||
use Infinito\Exception\NotSetException;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class RequestedActionStack implements RequestedActionStackInterface
|
||||
{
|
||||
/**
|
||||
* @var RequestedActionInterface[]|Collection
|
||||
*/
|
||||
private $requestedActions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->requestedActions = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\ReInfinito\Management\RequestedActionStackInterface::containesRequestedAction()
|
||||
*/
|
||||
public function containesRequestedAction(string $actionType): bool
|
||||
{
|
||||
return $this->requestedActions->containsKey($actionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\ReInfinito\Management\RequestedActionStackInterface::addRequestedAction()
|
||||
*/
|
||||
public function addRequestedAction(RequestedActionInterface $requestedAction): void
|
||||
{
|
||||
$key = $requestedAction->getActionType();
|
||||
if ($this->containesRequestedAction($key)) {
|
||||
throw new AllreadySetException("The key is allready set <<$key>>!");
|
||||
}
|
||||
$this->requestedActions->set($key, $requestedAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\ReInfinito\Management\RequestedActionStackInterface::getAllRequestedActions()
|
||||
*/
|
||||
public function getAllRequestedActions(): Collection
|
||||
{
|
||||
return $this->requestedActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\ReInfinito\Management\RequestedActionStackInterface::getRequestedAction()
|
||||
*/
|
||||
public function getRequestedAction(string $actionType): RequestedActionInterface
|
||||
{
|
||||
if ($this->requestedActions->containsKey($actionType)) {
|
||||
return $this->requestedActions->get($actionType);
|
||||
}
|
||||
throw new NotSetException(RequestedActionInterface::class." object for action type <<$actionType>> was not set!");
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\RequestManagement\Action;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RequestedActionStackInterface
|
||||
{
|
||||
/**
|
||||
* @param RequestedActionInterface $requestedAction
|
||||
*/
|
||||
public function addRequestedAction(RequestedActionInterface $requestedAction): void;
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @return RequestedActionInterface
|
||||
*/
|
||||
public function getRequestedAction(string $actionType): RequestedActionInterface;
|
||||
|
||||
/**
|
||||
* @return Collection|RequestedActionInterface[] All requested actions
|
||||
*/
|
||||
public function getAllRequestedActions(): Collection;
|
||||
|
||||
/**
|
||||
* @param string $actionType
|
||||
*
|
||||
* @return bool True if the stack containes an RequestedAction to this action type
|
||||
*/
|
||||
public function containesRequestedAction(string $actionType): bool;
|
||||
}
|
@ -54,7 +54,7 @@ class RequestedRight implements RequestedRightInterface
|
||||
*/
|
||||
private function validateRequestedEntity(): void
|
||||
{
|
||||
if ($this->requestedEntity->hasSlug() || $this->requestedEntity->hasId()) {
|
||||
if ($this->requestedEntity->hasIdentity()) {
|
||||
return;
|
||||
}
|
||||
throw new PreconditionFailedException(get_class($this->requestedEntity).' needs to have a defined attribut id or slug!');
|
||||
|
@ -2,6 +2,11 @@
|
||||
|
||||
namespace Infinito\Exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
* @deprecated
|
||||
*/
|
||||
final class NotProcessedException extends \Exception
|
||||
{
|
||||
public function __construct($message = null)
|
@ -7,6 +7,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class EntityNotFoundHttpException extends NotFoundHttpException
|
||||
final class EntityNotFoundException extends NotFoundHttpException
|
||||
{
|
||||
}
|
@ -5,6 +5,6 @@ namespace Infinito\Exception;
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class UnvalidParameterException extends \Exception
|
||||
final class NoIdentityException extends \Exception
|
||||
{
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Exception;
|
||||
|
||||
final class NotSortableException extends \Exception
|
||||
{
|
||||
}
|
@ -4,6 +4,6 @@ namespace Infinito\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
final class SourceAccessDenied extends AccessDeniedHttpException
|
||||
final class SourceAccessDeniedException extends AccessDeniedHttpException
|
||||
{
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Exception;
|
||||
|
||||
final class RecursiveException extends \Exception
|
||||
{
|
||||
}
|
@ -2,6 +2,11 @@
|
||||
|
||||
namespace Infinito\Exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
final class NoValidChoiceException extends \Exception
|
||||
{
|
||||
}
|
@ -5,6 +5,6 @@ namespace Infinito\Exception;
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class NotValidByFormException extends \Exception
|
||||
class InvalidByFormException extends \Exception
|
||||
{
|
||||
}
|
@ -7,6 +7,6 @@ namespace Infinito\Exception;
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class UnvalidGetParameterException extends UnvalidParameterException
|
||||
class InvalidGetParameterException extends InvalidParameterException
|
||||
{
|
||||
}
|
@ -5,6 +5,6 @@ namespace Infinito\Exception;
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class PreconditionFailedException extends \Exception
|
||||
class InvalidParameterException extends \Exception
|
||||
{
|
||||
}
|
@ -5,6 +5,6 @@ namespace Infinito\Exception;
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class UnvalidValueException extends \Exception
|
||||
class InvalidValueException extends \Exception
|
||||
{
|
||||
}
|
Loading…
Reference in New Issue
Block a user