2019-01-27 15:28:25 +01:00
|
|
|
<?php
|
|
|
|
|
2019-02-17 14:33:19 +01:00
|
|
|
namespace Infinito\Domain\ActionManagement;
|
2019-01-27 15:28:25 +01:00
|
|
|
|
2019-02-17 14:33:19 +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();
|
|
|
|
|
2019-02-13 16:26:32 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2019-02-03 15:21:45 +01:00
|
|
|
*
|
|
|
|
* {@inheritdoc}
|
2019-01-27 15:28:25 +01:00
|
|
|
*
|
2019-02-17 14:33:19 +01:00
|
|
|
* @see \Infinito\Domain\ActionManagement\ActionInterface::execute()
|
2019-01-27 15:28:25 +01:00
|
|
|
*/
|
2019-02-03 15:21:45 +01:00
|
|
|
final public function execute()
|
2019-01-27 15:28:25 +01:00
|
|
|
{
|
2019-02-13 16:26:32 +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!");
|
|
|
|
}
|
|
|
|
}
|