58 lines
1.3 KiB
PHP
Raw Normal View History

2019-01-27 15:28:25 +01:00
<?php
namespace Infinito\Domain\ActionManagement;
2019-01-27 15:28:25 +01:00
use Infinito\Entity\EntityInterface;
use Infinito\Exception\NotSecureException;
use Infinito\Exception\NotValidByFormException;
2019-01-27 15:28:25 +01:00
/**
* @author kevinfrantz
*/
abstract class AbstractAction extends AbstractActionConstructor implements ActionInterface
{
/**
* @return bool
*/
abstract protected function isSecure(): bool;
/**
* @return bool
*/
2019-02-12 16:47:37 +01:00
abstract protected function isValid(): bool;
2019-01-27 15:28:25 +01:00
/**
* 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;
}
2019-01-27 15:28:25 +01:00
/**
* @throws \Exception
*
* {@inheritdoc}
2019-01-27 15:28:25 +01:00
*
* @see \Infinito\Domain\ActionManagement\ActionInterface::execute()
2019-01-27 15:28:25 +01:00
*/
final public function execute()
2019-01-27 15:28:25 +01:00
{
$this->prepare();
2019-01-27 15:28:25 +01:00
if ($this->isSecure()) {
2019-02-12 16:47:37 +01:00
if ($this->isValid()) {
2019-01-27 15:28:25 +01:00
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!");
}
}