mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-03-14 02:45:19 +01:00
58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Infinito\Domain\ActionManagement;
|
|
|
|
use Infinito\Entity\EntityInterface;
|
|
use Infinito\Exception\NotSecureException;
|
|
use Infinito\Exception\NotValidByFormException;
|
|
|
|
/**
|
|
* @author kevinfrantz
|
|
*/
|
|
abstract class AbstractAction extends AbstractActionConstructor implements ActionInterface
|
|
{
|
|
/**
|
|
* @return bool
|
|
*/
|
|
abstract protected function isSecure(): bool;
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
abstract protected function isValid(): bool;
|
|
|
|
/**
|
|
* Process the routine.
|
|
*
|
|
* @return EntityInterface|EntityInterface[]|null
|
|
*/
|
|
abstract protected function proccess();
|
|
|
|
/**
|
|
* This function can be implemented in the child classes for preparation.
|
|
*/
|
|
protected function prepare(): void
|
|
{
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* @throws \Exception
|
|
*
|
|
* {@inheritdoc}
|
|
*
|
|
* @see \Infinito\Domain\ActionManagement\ActionInterface::execute()
|
|
*/
|
|
final public function execute(): ?EntityInterface
|
|
{
|
|
$this->prepare();
|
|
if ($this->isSecure()) {
|
|
if ($this->isValid()) {
|
|
return $this->proccess();
|
|
}
|
|
throw new NotValidByFormException('The requested Entity is not valid!');
|
|
}
|
|
throw new NotSecureException("You don't have the permission to execute this action!");
|
|
}
|
|
}
|