Commit eec11f58 authored by Tino Goratsch's avatar Tino Goratsch

- renamed the FrontController class to ControllerResolver so that it describes...

- renamed the FrontController class to ControllerResolver so that it describes its meaning much better
- moved some exceptions around
parent f6553dbc
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\ACL\Exception;
/**
* Class AccessForbiddenException
* @package ACP3\Core\ACL\Exception
*/
class AccessForbiddenException extends \Exception
{
}
...@@ -128,15 +128,15 @@ class Bootstrap extends AbstractBootstrap ...@@ -128,15 +128,15 @@ class Bootstrap extends AbstractBootstrap
$redirect = $this->container->get('core.redirect'); $redirect = $this->container->get('core.redirect');
try { try {
$this->container->get('core.application.front_controller')->dispatch(); $this->container->get('core.application.controller_resolver')->dispatch();
} catch (Exceptions\ResultNotExists $e) { } catch (\ACP3\Core\Controller\Exception\ResultNotExistsException $e) {
$redirect->temporary('errors/index/not_found')->send(); $redirect->temporary('errors/index/not_found')->send();
} catch (Exceptions\UnauthorizedAccess $e) { } catch (\ACP3\Core\Authentication\Exception\UnauthorizedAccessException $e) {
$redirectUri = base64_encode($request->getOriginalQuery()); $redirectUri = base64_encode($request->getOriginalQuery());
$redirect->temporary('users/index/login/redirect_' . $redirectUri)->send(); $redirect->temporary('users/index/login/redirect_' . $redirectUri)->send();
} catch (Exceptions\AccessForbidden $e) { } catch (\ACP3\Core\ACL\Exception\AccessForbiddenException $e) {
$redirect->temporary('errors/index/access_forbidden'); $redirect->temporary('errors/index/access_forbidden');
} catch (Exceptions\ControllerActionNotFound $e) { } catch (\ACP3\Core\Controller\Exception\ControllerActionNotFoundException $e) {
$this->handleException($e, $redirect, 'errors/index/not_found'); $this->handleException($e, $redirect, 'errors/index/not_found');
} catch (\Exception $e) { } catch (\Exception $e) {
$this->handleException($e, $redirect, 'errors/index/server_error'); $this->handleException($e, $redirect, 'errors/index/server_error');
......
...@@ -8,17 +8,17 @@ namespace ACP3\Core\Application; ...@@ -8,17 +8,17 @@ namespace ACP3\Core\Application;
use ACP3\Core\Application\Event\FrontControllerDispatchEvent; use ACP3\Core\Application\Event\FrontControllerDispatchEvent;
use ACP3\Core\Controller\ActionInterface; use ACP3\Core\Controller\ActionInterface;
use ACP3\Core\Controller\Exception\ResultNotExistsException;
use ACP3\Core\Exceptions; use ACP3\Core\Exceptions;
use ACP3\Core\Exceptions\ResultNotExists;
use ACP3\Core\Http\RequestInterface; use ACP3\Core\Http\RequestInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/** /**
* Class FrontController * Class ControllerResolver
* @package ACP3\Core\Application * @package ACP3\Core\Application
*/ */
class FrontController class ControllerResolver
{ {
/** /**
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
...@@ -52,8 +52,8 @@ class FrontController ...@@ -52,8 +52,8 @@ class FrontController
* @param string $serviceId * @param string $serviceId
* @param array $arguments * @param array $arguments
* *
* @throws \ACP3\Core\Exceptions\ControllerActionNotFound * @throws \ACP3\Core\Controller\Exception\ControllerActionNotFoundException
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function dispatch($serviceId = '', array $arguments = []) public function dispatch($serviceId = '', array $arguments = [])
{ {
...@@ -63,7 +63,7 @@ class FrontController ...@@ -63,7 +63,7 @@ class FrontController
if ($this->container->has($serviceId)) { if ($this->container->has($serviceId)) {
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
'core.application.front_controller.before_dispatch', 'core.application.controller_resolver.before_dispatch',
new FrontControllerDispatchEvent($serviceId) new FrontControllerDispatchEvent($serviceId)
); );
...@@ -73,14 +73,14 @@ class FrontController ...@@ -73,14 +73,14 @@ class FrontController
$controller->display($this->executeControllerAction($controller, $arguments)); $controller->display($this->executeControllerAction($controller, $arguments));
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
'core.application.front_controller.after_dispatch', 'core.application.controller_resolver.after_dispatch',
new FrontControllerDispatchEvent($serviceId) new FrontControllerDispatchEvent($serviceId)
); );
return; return;
} }
throw new Exceptions\ControllerActionNotFound('Service-Id ' . $serviceId . ' was not found!'); throw new \ACP3\Core\Controller\Exception\ControllerActionNotFoundException('Service-Id ' . $serviceId . ' was not found!');
} }
/** /**
...@@ -88,7 +88,7 @@ class FrontController ...@@ -88,7 +88,7 @@ class FrontController
* @param array $arguments * @param array $arguments
* *
* @return mixed * @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
private function executeControllerAction(ActionInterface $controller, array $arguments) private function executeControllerAction(ActionInterface $controller, array $arguments)
{ {
...@@ -99,7 +99,7 @@ class FrontController ...@@ -99,7 +99,7 @@ class FrontController
$arguments = $this->fetchControllerActionArguments($reflection); $arguments = $this->fetchControllerActionArguments($reflection);
if ($reflection->getNumberOfRequiredParameters() > count($arguments)) { if ($reflection->getNumberOfRequiredParameters() > count($arguments)) {
throw new ResultNotExists(); throw new ResultNotExistsException();
} }
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
namespace ACP3\Core\Authentication; namespace ACP3\Core\Authentication;
use ACP3\Core\Exceptions\InvalidAuthenticationMethod; use ACP3\Core\Authentication\Exception\InvalidAuthenticationMethodException;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
...@@ -32,7 +32,7 @@ class AuthenticationFactory ...@@ -32,7 +32,7 @@ class AuthenticationFactory
* @param string $authenticationMethod * @param string $authenticationMethod
* *
* @return \ACP3\Core\Authentication\AuthenticationInterface * @return \ACP3\Core\Authentication\AuthenticationInterface
* @throws \ACP3\Core\Exceptions\InvalidAuthenticationMethod * @throws \ACP3\Core\Authentication\Exception\InvalidAuthenticationMethodException
*/ */
public function get($authenticationMethod) public function get($authenticationMethod)
{ {
...@@ -41,6 +41,6 @@ class AuthenticationFactory ...@@ -41,6 +41,6 @@ class AuthenticationFactory
return $this->container->get($serviceId); return $this->container->get($serviceId);
} }
throw new InvalidAuthenticationMethod(); throw new InvalidAuthenticationMethodException();
} }
} }
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Authentication\Exception;
/**
* Class InvalidAuthenticationMethodException
* @package ACP3\Core\Authentication\Exception
*/
class InvalidAuthenticationMethodException extends \Exception
{
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Authentication\Exception;
/**
* Class UnauthorizedAccessException
* @package ACP3\Core\Authentication\Exception
*/
class UnauthorizedAccessException extends \Exception
{
}
...@@ -31,12 +31,12 @@ abstract class AdminAction extends Core\Controller\FrontendAction ...@@ -31,12 +31,12 @@ abstract class AdminAction extends Core\Controller\FrontendAction
/** /**
* @return $this * @return $this
* @throws \ACP3\Core\Exceptions\UnauthorizedAccess * @throws \ACP3\Core\Authentication\Exception\UnauthorizedAccessException
*/ */
public function preDispatch() public function preDispatch()
{ {
if ($this->user->isAuthenticated() === false) { if ($this->user->isAuthenticated() === false) {
throw new Core\Exceptions\UnauthorizedAccess(); throw new Core\Authentication\Exception\UnauthorizedAccessException();
} }
return parent::preDispatch(); return parent::preDispatch();
......
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Controller\Exception;
/**
* Class ControllerActionNotFoundException
* @package ACP3\Core\Controller\Exception
*/
class ControllerActionNotFoundException extends \Exception
{
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Controller\Exception;
/**
* Class ResultNotExistsException
* @package ACP3\Core\Controller\Exception
*/
class ResultNotExistsException extends \Exception
{
}
...@@ -63,14 +63,14 @@ abstract class FrontendAction extends Core\Controller\WidgetAction ...@@ -63,14 +63,14 @@ abstract class FrontendAction extends Core\Controller\WidgetAction
* Helper function for initializing models, etc. * Helper function for initializing models, etc.
* *
* @return $this * @return $this
* @throws \ACP3\Core\Exceptions\AccessForbidden * @throws \ACP3\Core\ACL\Exception\AccessForbiddenException
*/ */
public function preDispatch() public function preDispatch()
{ {
$path = $this->request->getArea() . '/' . $this->request->getFullPathWithoutArea(); $path = $this->request->getArea() . '/' . $this->request->getFullPathWithoutArea();
if ($this->acl->hasPermission($path) === false) { if ($this->acl->hasPermission($path) === false) {
throw new Core\Exceptions\AccessForbidden(); throw new Core\ACL\Exception\AccessForbiddenException();
} }
// Get the current resultset position // Get the current resultset position
......
<?php
namespace ACP3\Core\Exceptions;
/**
* Class AccessForbidden
* @package ACP3\Core\Exceptions
*/
class AccessForbidden extends \Exception
{
}
<?php
namespace ACP3\Core\Exceptions;
/**
* Class ControllerActionNotFound
* @package ACP3\Core\Exceptions
*/
class ControllerActionNotFound extends \Exception
{
}
<?php
namespace ACP3\Core\Exceptions;
/**
* Class InvalidAuthenticationMethod
* @package ACP3\Core\Exceptions
*/
class InvalidAuthenticationMethod extends \Exception
{
}
<?php
namespace ACP3\Core\Exceptions;
/**
* Class ResultNotExists
* @package ACP3\Core\Exceptions
*/
class ResultNotExists extends \Exception
{
}
<?php
namespace ACP3\Core\Exceptions;
/**
* Class UnauthorizedAccess
* @package ACP3\Core\Exceptions
*/
class UnauthorizedAccess extends \Exception
{
}
...@@ -110,7 +110,7 @@ class Action ...@@ -110,7 +110,7 @@ class Action
* @param string|null $moduleIndexUrl * @param string|null $moduleIndexUrl
* *
* @return array|string|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|void * @return array|string|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|void
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function handleDeleteAction( public function handleDeleteAction(
FrontendAction $context, FrontendAction $context,
...@@ -142,7 +142,7 @@ class Action ...@@ -142,7 +142,7 @@ class Action
* @param string|null $moduleIndexUrl * @param string|null $moduleIndexUrl
* *
* @return void|string|array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse * @return void|string|array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function handleCustomDeleteAction( public function handleCustomDeleteAction(
FrontendAction $context, FrontendAction $context,
...@@ -160,7 +160,7 @@ class Action ...@@ -160,7 +160,7 @@ class Action
} elseif ($action === 'confirmed' && is_array($result)) { } elseif ($action === 'confirmed' && is_array($result)) {
return $callback($result); return $callback($result);
} else { } else {
throw new Core\Exceptions\ResultNotExists(); throw new Core\Controller\Exception\ResultNotExistsException();
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace ACP3\Core\View\Renderer\Smarty\Functions; namespace ACP3\Core\View\Renderer\Smarty\Functions;
use ACP3\Core\ACL; use ACP3\Core\ACL;
use ACP3\Core\Application\FrontController; use ACP3\Core\Application\ControllerResolver;
/** /**
* Class LoadModule * Class LoadModule
...@@ -15,7 +15,7 @@ class LoadModule extends AbstractFunction ...@@ -15,7 +15,7 @@ class LoadModule extends AbstractFunction
*/ */
protected $acl; protected $acl;
/** /**
* @var \ACP3\Core\Application\FrontController * @var \ACP3\Core\Application\ControllerResolver
*/ */
protected $frontController; protected $frontController;
...@@ -23,9 +23,9 @@ class LoadModule extends AbstractFunction ...@@ -23,9 +23,9 @@ class LoadModule extends AbstractFunction
* LoadModule constructor. * LoadModule constructor.
* *
* @param \ACP3\Core\ACL $acl * @param \ACP3\Core\ACL $acl
* @param \ACP3\Core\Application\FrontController $frontController * @param \ACP3\Core\Application\ControllerResolver $frontController
*/ */
public function __construct(ACL $acl, FrontController $frontController) public function __construct(ACL $acl, ControllerResolver $frontController)
{ {
$this->acl = $acl; $this->acl = $acl;
$this->frontController = $frontController; $this->frontController = $frontController;
......
...@@ -55,7 +55,7 @@ services: ...@@ -55,7 +55,7 @@ services:
smarty.plugin.load_module: smarty.plugin.load_module:
class: ACP3\Core\View\Renderer\Smarty\Functions\LoadModule class: ACP3\Core\View\Renderer\Smarty\Functions\LoadModule
arguments: ['@core.acl', '@core.application.front_controller'] arguments: ['@core.acl', '@core.application.controller_resolver']
tags: tags:
- { name: core.view.extension } - { name: core.view.extension }
......
...@@ -31,8 +31,8 @@ services: ...@@ -31,8 +31,8 @@ services:
- '@permissions.model.privilegerepository' - '@permissions.model.privilegerepository'
- '@permissions.cache' - '@permissions.cache'
core.application.front_controller: core.application.controller_resolver:
class: ACP3\Core\Application\FrontController class: ACP3\Core\Application\ControllerResolver
arguments: arguments:
- '@core.eventDispatcher' - '@core.eventDispatcher'
- '@core.request' - '@core.request'
......
...@@ -45,7 +45,7 @@ class Delete extends AbstractFormAction ...@@ -45,7 +45,7 @@ class Delete extends AbstractFormAction
* @param string $action * @param string $action
* *
* @return mixed * @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function execute($action = '') public function execute($action = '')
{ {
......
...@@ -118,7 +118,7 @@ class Edit extends AbstractFormAction ...@@ -118,7 +118,7 @@ class Edit extends AbstractFormAction
* @param int $id * @param int $id
* *
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function execute($id) public function execute($id)
{ {
...@@ -164,7 +164,7 @@ class Edit extends AbstractFormAction ...@@ -164,7 +164,7 @@ class Edit extends AbstractFormAction
]; ];
} }
throw new Core\Exceptions\ResultNotExists(); throw new Core\Controller\Exception\ResultNotExistsException();
} }
/** /**
......
...@@ -60,7 +60,7 @@ class Details extends Core\Controller\FrontendAction ...@@ -60,7 +60,7 @@ class Details extends Core\Controller\FrontendAction
* @param int $id * @param int $id
* *
* @return array * @return array
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function execute($id) public function execute($id)
{ {
...@@ -77,6 +77,6 @@ class Details extends Core\Controller\FrontendAction ...@@ -77,6 +77,6 @@ class Details extends Core\Controller\FrontendAction
]; ];
} }
throw new Core\Exceptions\ResultNotExists(); throw new Core\Controller\Exception\ResultNotExistsException();
} }
} }
...@@ -46,7 +46,7 @@ class Delete extends Core\Controller\AdminAction ...@@ -46,7 +46,7 @@ class Delete extends Core\Controller\AdminAction
* @param string $action * @param string $action
* *
* @return mixed * @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function execute($action = '') public function execute($action = '')
{ {
......
...@@ -58,7 +58,7 @@ class Edit extends Core\Controller\AdminAction ...@@ -58,7 +58,7 @@ class Edit extends Core\Controller\AdminAction
* @param int $id * @param int $id
* *
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function execute($id) public function execute($id)
{ {
...@@ -77,7 +77,7 @@ class Edit extends Core\Controller\AdminAction ...@@ -77,7 +77,7 @@ class Edit extends Core\Controller\AdminAction
]; ];
} }
throw new Core\Exceptions\ResultNotExists(); throw new Core\Controller\Exception\ResultNotExistsException();
} }
/** /**
......
...@@ -42,7 +42,7 @@ class Delete extends Core\Controller\AdminAction ...@@ -42,7 +42,7 @@ class Delete extends Core\Controller\AdminAction
* @param string $action * @param string $action
* *
* @return mixed * @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function execute($id, $action = '') public function execute($id, $action = '')
{ {
......
...@@ -78,7 +78,7 @@ class Edit extends Core\Controller\AdminAction ...@@ -78,7 +78,7 @@ class Edit extends Core\Controller\AdminAction
* @param int $id * @param int $id
* *
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function execute($id) public function execute($id)
{ {
...@@ -115,7 +115,7 @@ class Edit extends Core\Controller\AdminAction ...@@ -115,7 +115,7 @@ class Edit extends Core\Controller\AdminAction
]; ];
} }
throw new Core\Exceptions\ResultNotExists(); throw new Core\Controller\Exception\ResultNotExistsException();
} }
/** /**
* @param array $formData * @param array $formData
......
...@@ -48,7 +48,7 @@ class Index extends Core\Controller\AdminAction ...@@ -48,7 +48,7 @@ class Index extends Core\Controller\AdminAction
* @param int $id * @param int $id
* *
* @return array * @return array
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function execute($id) public function execute($id)
{ {
...@@ -103,6 +103,6 @@ class Index extends Core\Controller\AdminAction ...@@ -103,6 +103,6 @@ class Index extends Core\Controller\AdminAction
]; ];
} }
throw new Core\Exceptions\ResultNotExists(); throw new Core\Controller\Exception\ResultNotExistsException();
} }
} }
...@@ -39,7 +39,7 @@ class Delete extends Core\Controller\AdminAction ...@@ -39,7 +39,7 @@ class Delete extends Core\Controller\AdminAction
* @param string $action * @param string $action
* *
* @return mixed * @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function execute($action = '') public function execute($action = '')
{ {
......
...@@ -46,7 +46,7 @@ class Delete extends Core\Controller\AdminAction ...@@ -46,7 +46,7 @@ class Delete extends Core\Controller\AdminAction
* @param string $action * @param string $action
* *
* @return array|string|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|void * @return array|string|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|void
* @throws \ACP3\Core\Exceptions\ResultNotExists * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/ */
public function execute($action = '') public function execute($action = '')
{ {
......