2019-01-27 15:28:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Domain\ActionManagement;
|
|
|
|
|
|
|
|
use App\Entity\EntityInterface;
|
|
|
|
use App\Exception\NotSecureException;
|
|
|
|
use App\Exception\NotValidByFormException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
|
|
|
*/
|
|
|
|
abstract class AbstractAction extends AbstractActionConstructor implements ActionInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
abstract protected function isSecure(): bool;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
abstract protected function isValidByForm(): bool;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the routine.
|
|
|
|
*
|
|
|
|
* @return EntityInterface|EntityInterface[]|null
|
|
|
|
*/
|
|
|
|
abstract protected function proccess();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \Exception
|
2019-02-03 15:21:45 +01:00
|
|
|
*
|
|
|
|
* {@inheritdoc}
|
2019-01-27 15:28:25 +01:00
|
|
|
*
|
|
|
|
* @see \App\Domain\ActionManagement\ActionInterface::execute()
|
|
|
|
*/
|
2019-02-03 15:21:45 +01:00
|
|
|
final public function execute()
|
2019-01-27 15:28:25 +01:00
|
|
|
{
|
|
|
|
if ($this->isSecure()) {
|
|
|
|
if ($this->isValidByForm()) {
|
|
|
|
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!");
|
|
|
|
}
|
|
|
|
}
|