. */ namespace SP\Modules\Web\Controllers; use SP\Core\Application; use SP\Core\Events\EventDispatcher; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\Acl\AclInterface; use SP\Domain\Core\Acl\UnauthorizedPageException; use SP\Domain\Core\Bootstrap\UriContextInterface; use SP\Domain\Core\Context\SessionContext; use SP\Domain\Core\Exceptions\SessionTimeout; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Core\PhpExtensionCheckerService; use SP\Domain\Core\UI\ThemeInterface; use SP\Domain\Http\Ports\RequestService; use SP\Modules\Web\Controllers\Traits\WebControllerTrait; use SP\Mvc\Controller\SimpleControllerHelper; /** * Class SimpleControllerBase */ abstract class SimpleControllerBase { use WebControllerTrait; protected readonly EventDispatcher $eventDispatcher; protected readonly ConfigFileService $config; protected readonly SessionContext $session; protected readonly ThemeInterface $theme; protected readonly AclInterface $acl; protected readonly RequestService $request; protected readonly PhpExtensionCheckerService $extensionChecker; protected readonly ConfigDataInterface $configData; protected readonly UriContextInterface $uriContext; /** * @throws SessionTimeout */ public function __construct( Application $application, SimpleControllerHelper $simpleControllerHelper ) { $this->theme = $simpleControllerHelper->getTheme(); $this->router = $simpleControllerHelper->getRouter(); $this->acl = $simpleControllerHelper->getAcl(); $this->request = $simpleControllerHelper->getRequest(); $this->extensionChecker = $simpleControllerHelper->getExtensionChecker(); $this->uriContext = $simpleControllerHelper->getUriContext(); $this->config = $application->getConfig(); $this->configData = $this->config->getConfigData(); $this->eventDispatcher = $application->getEventDispatcher(); $this->session = $application->getContext(); $this->setup = true; if (method_exists($this, 'initialize')) { $this->initialize(); } } /** * Comprobaciones * * @throws SPException * @throws SessionTimeout */ protected function checks(): void { if ($this->session->isLoggedIn() === false || $this->session->getAuthCompleted() !== true) { $this->handleSessionTimeout(); throw new SessionTimeout(); } // $this->checkSecurityToken($this->session, $this->request); } /** * Comprobar si está permitido el acceso al módulo/página. * * @throws UnauthorizedPageException */ protected function checkAccess(int $action): void { if (!$this->acl->checkUserAccess($action) && !$this->session->getUserData()->isAdminApp) { throw new UnauthorizedPageException(SPException::INFO); } } }