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
$redirect = $this->container->get('core.redirect');
try {
$this->container->get('core.application.front_controller')->dispatch();
} catch (Exceptions\ResultNotExists $e) {
$this->container->get('core.application.controller_resolver')->dispatch();
} catch (\ACP3\Core\Controller\Exception\ResultNotExistsException $e) {
$redirect->temporary('errors/index/not_found')->send();
} catch (Exceptions\UnauthorizedAccess $e) {
} catch (\ACP3\Core\Authentication\Exception\UnauthorizedAccessException $e) {
$redirectUri = base64_encode($request->getOriginalQuery());
$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');
} catch (Exceptions\ControllerActionNotFound $e) {
} catch (\ACP3\Core\Controller\Exception\ControllerActionNotFoundException $e) {
$this->handleException($e, $redirect, 'errors/index/not_found');
} catch (\Exception $e) {
$this->handleException($e, $redirect, 'errors/index/server_error');
......
......@@ -8,17 +8,17 @@ namespace ACP3\Core\Application;
use ACP3\Core\Application\Event\FrontControllerDispatchEvent;
use ACP3\Core\Controller\ActionInterface;
use ACP3\Core\Controller\Exception\ResultNotExistsException;
use ACP3\Core\Exceptions;
use ACP3\Core\Exceptions\ResultNotExists;
use ACP3\Core\Http\RequestInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Class FrontController
* Class ControllerResolver
* @package ACP3\Core\Application
*/
class FrontController
class ControllerResolver
{
/**
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
......@@ -52,8 +52,8 @@ class FrontController
* @param string $serviceId
* @param array $arguments
*
* @throws \ACP3\Core\Exceptions\ControllerActionNotFound
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ControllerActionNotFoundException
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function dispatch($serviceId = '', array $arguments = [])
{
......@@ -63,7 +63,7 @@ class FrontController
if ($this->container->has($serviceId)) {
$this->eventDispatcher->dispatch(
'core.application.front_controller.before_dispatch',
'core.application.controller_resolver.before_dispatch',
new FrontControllerDispatchEvent($serviceId)
);
......@@ -73,14 +73,14 @@ class FrontController
$controller->display($this->executeControllerAction($controller, $arguments));
$this->eventDispatcher->dispatch(
'core.application.front_controller.after_dispatch',
'core.application.controller_resolver.after_dispatch',
new FrontControllerDispatchEvent($serviceId)
);
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
* @param array $arguments
*
* @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
private function executeControllerAction(ActionInterface $controller, array $arguments)
{
......@@ -99,7 +99,7 @@ class FrontController
$arguments = $this->fetchControllerActionArguments($reflection);
if ($reflection->getNumberOfRequiredParameters() > count($arguments)) {
throw new ResultNotExists();
throw new ResultNotExistsException();
}
}
......
......@@ -6,7 +6,7 @@
namespace ACP3\Core\Authentication;
use ACP3\Core\Exceptions\InvalidAuthenticationMethod;
use ACP3\Core\Authentication\Exception\InvalidAuthenticationMethodException;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -32,7 +32,7 @@ class AuthenticationFactory
* @param string $authenticationMethod
*
* @return \ACP3\Core\Authentication\AuthenticationInterface
* @throws \ACP3\Core\Exceptions\InvalidAuthenticationMethod
* @throws \ACP3\Core\Authentication\Exception\InvalidAuthenticationMethodException
*/
public function get($authenticationMethod)
{
......@@ -41,6 +41,6 @@ class AuthenticationFactory
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
/**
* @return $this
* @throws \ACP3\Core\Exceptions\UnauthorizedAccess
* @throws \ACP3\Core\Authentication\Exception\UnauthorizedAccessException
*/
public function preDispatch()
{
if ($this->user->isAuthenticated() === false) {
throw new Core\Exceptions\UnauthorizedAccess();
throw new Core\Authentication\Exception\UnauthorizedAccessException();
}
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
* Helper function for initializing models, etc.
*
* @return $this
* @throws \ACP3\Core\Exceptions\AccessForbidden
* @throws \ACP3\Core\ACL\Exception\AccessForbiddenException
*/
public function preDispatch()
{
$path = $this->request->getArea() . '/' . $this->request->getFullPathWithoutArea();
if ($this->acl->hasPermission($path) === false) {
throw new Core\Exceptions\AccessForbidden();
throw new Core\ACL\Exception\AccessForbiddenException();
}
// 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
* @param string|null $moduleIndexUrl
*
* @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(
FrontendAction $context,
......@@ -142,7 +142,7 @@ class Action
* @param string|null $moduleIndexUrl
*
* @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(
FrontendAction $context,
......@@ -160,7 +160,7 @@ class Action
} elseif ($action === 'confirmed' && is_array($result)) {
return $callback($result);
} else {
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
}
......
......@@ -2,7 +2,7 @@
namespace ACP3\Core\View\Renderer\Smarty\Functions;
use ACP3\Core\ACL;
use ACP3\Core\Application\FrontController;
use ACP3\Core\Application\ControllerResolver;
/**
* Class LoadModule
......@@ -15,7 +15,7 @@ class LoadModule extends AbstractFunction
*/
protected $acl;
/**
* @var \ACP3\Core\Application\FrontController
* @var \ACP3\Core\Application\ControllerResolver
*/
protected $frontController;
......@@ -23,9 +23,9 @@ class LoadModule extends AbstractFunction
* LoadModule constructor.
*
* @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->frontController = $frontController;
......
......@@ -55,7 +55,7 @@ services:
smarty.plugin.load_module:
class: ACP3\Core\View\Renderer\Smarty\Functions\LoadModule
arguments: ['@core.acl', '@core.application.front_controller']
arguments: ['@core.acl', '@core.application.controller_resolver']
tags:
- { name: core.view.extension }
......
......@@ -31,8 +31,8 @@ services:
- '@permissions.model.privilegerepository'
- '@permissions.cache'
core.application.front_controller:
class: ACP3\Core\Application\FrontController
core.application.controller_resolver:
class: ACP3\Core\Application\ControllerResolver
arguments:
- '@core.eventDispatcher'
- '@core.request'
......
......@@ -45,7 +45,7 @@ class Delete extends AbstractFormAction
* @param string $action
*
* @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($action = '')
{
......
......@@ -118,7 +118,7 @@ class Edit extends AbstractFormAction
* @param int $id
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
......@@ -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
* @param int $id
*
* @return array
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
......@@ -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
* @param string $action
*
* @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($action = '')
{
......
......@@ -58,7 +58,7 @@ class Edit extends Core\Controller\AdminAction
* @param int $id
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
......@@ -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
* @param string $action
*
* @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id, $action = '')
{
......
......@@ -78,7 +78,7 @@ class Edit extends Core\Controller\AdminAction
* @param int $id
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
......@@ -115,7 +115,7 @@ class Edit extends Core\Controller\AdminAction
];
}
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
/**
* @param array $formData
......
......@@ -48,7 +48,7 @@ class Index extends Core\Controller\AdminAction
* @param int $id
*
* @return array
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
......@@ -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
* @param string $action
*
* @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($action = '')
{
......
......@@ -46,7 +46,7 @@ class Delete extends Core\Controller\AdminAction
* @param string $action
*
* @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 = '')
{
......
......@@ -60,7 +60,7 @@ class Edit extends Core\Controller\AdminAction
* @param int $id
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
......@@ -77,7 +77,7 @@ class Edit extends Core\Controller\AdminAction
];
}
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
/**
......
......@@ -37,7 +37,7 @@ class Index extends Core\Controller\FrontendAction
* @param string $feed
*
* @return \Symfony\Component\HttpFoundation\Response
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($feed)
{
......@@ -56,6 +56,6 @@ class Index extends Core\Controller\FrontendAction
return $this->response->setContent($this->feedGenerator->generateFeed());
}
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
}
......@@ -77,7 +77,7 @@ class Delete extends Core\Controller\AdminAction
* @param string $action
*
* @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($action = '')
{
......
......@@ -83,7 +83,7 @@ class Edit extends AbstractFormAction
* @param int $id
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
......@@ -122,7 +122,7 @@ class Edit extends AbstractFormAction
];
}
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
/**
......
......@@ -61,7 +61,7 @@ class Details extends Core\Controller\FrontendAction
* @param string $action
*
* @return array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id, $action = '')
{
......@@ -87,14 +87,14 @@ class Details extends Core\Controller\FrontendAction
];
}
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
/**
* @param array $file
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
protected function downloadFile(array $file)
{
......@@ -116,6 +116,6 @@ class Details extends Core\Controller\FrontendAction
return $this->redirect()->toNewPage($file['file']);
}
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
}
......@@ -54,7 +54,7 @@ class Files extends Core\Controller\FrontendAction
* @param int $cat
*
* @return array
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($cat)
{
......@@ -73,6 +73,6 @@ class Files extends Core\Controller\FrontendAction
];
}
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
}
......@@ -93,7 +93,7 @@ class Edit extends AbstractFormAction
* @param int $id
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
......@@ -118,7 +118,7 @@ class Edit extends AbstractFormAction
$this->executeListPictures($id)
);
}
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
/**
......
......@@ -115,7 +115,7 @@ class Create extends AbstractFormAction
* @param int $id
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
......@@ -143,7 +143,7 @@ class Create extends AbstractFormAction
];
}
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
/**
......
......@@ -67,7 +67,7 @@ class Delete extends Core\Controller\AdminAction
* @param string $action
*
* @return mixed
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id, $action = '')
{
......
......@@ -69,7 +69,7 @@ class Edit extends AbstractFormAction
* @param int $id
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* @throws \ACP3\Core\Exceptions\ResultNotExists
* @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
......@@ -104,7 +104,7 @@ class Edit extends AbstractFormAction
];
}
throw new Core\Exceptions\ResultNotExists();
throw new Core\Controller\Exception\ResultNotExistsException();
}
/**
......
......@@ -55,7 +55,7 @@ Order extends Core\Controller\AdminAction
* @param string $action
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse