Commit 2fc2844c authored by Tino Goratsch's avatar Tino Goratsch

allow to modify the current request URI

parent 37b28bbc
......@@ -87,8 +87,7 @@ class Bootstrap extends AbstractBootstrap
*/
public function outputPage()
{
/** @var \ACP3\Core\Http\RedirectResponse $redirect */
$redirect = $this->container->get('core.http.redirect_response');
$controllerActionDispatcher = $this->container->get('core.application.controller_action_dispatcher');
try {
/** @var \ACP3\Core\Authentication\AuthenticationInterface $authentication */
......@@ -100,16 +99,18 @@ class Bootstrap extends AbstractBootstrap
$response = $controllerActionDispatcher->dispatch();
} catch (\ACP3\Core\Controller\Exception\ResultNotExistsException $e) {
$response = $redirect->temporary('errors/index/not_found');
$response = $controllerActionDispatcher->dispatch('errors.controller.frontend.index.not_found');
} catch (\ACP3\Core\Authentication\Exception\UnauthorizedAccessException $e) {
/** @var \ACP3\Core\Http\RedirectResponse $redirect */
$redirect = $this->container->get('core.http.redirect_response');
/** @var \ACP3\Core\Http\Request $request */
$request = $this->container->get('core.http.request');
$redirectUri = \base64_encode($request->getPathInfo());
$response = $redirect->temporary('users/index/login/redirect_' . $redirectUri);
} catch (\ACP3\Core\ACL\Exception\AccessForbiddenException $e) {
$response = $redirect->temporary('errors/index/access_forbidden');
$response = $controllerActionDispatcher->dispatch('errors.controller.frontend.index.access_forbidden');
} catch (\ACP3\Core\Controller\Exception\ControllerActionNotFoundException $e) {
$response = $redirect->temporary('errors/index/not_found');
$response = $controllerActionDispatcher->dispatch('errors.controller.frontend.index.not_found');
} catch (MaintenanceModeActiveException $e) {
$response = new Response($e->getMessage(), $e->getCode());
} catch (\Exception $e) {
......
......@@ -47,7 +47,8 @@ class ControllerActionDispatcher
RequestInterface $request,
ContainerInterface $container,
ArgumentResolverInterface $argumentResolver
) {
)
{
$this->eventDispatcher = $eventDispatcher;
$this->request = $request;
$this->container = $container;
......@@ -68,6 +69,8 @@ class ControllerActionDispatcher
{
if (empty($serviceId)) {
$serviceId = $this->buildControllerServiceId();
} else {
$this->modifyRequest($serviceId);
}
if ($this->container->has($serviceId)) {
......@@ -106,6 +109,14 @@ class ControllerActionDispatcher
. '.' . $this->request->getAction();
}
protected function modifyRequest(string $serviceId)
{
list($module, , , $controller, $action) = explode('.', $serviceId);
$this->request->setPathInfo($module . '/' . $controller . '/' . $action);
$this->request->processQuery();
}
/**
* @param \ACP3\Core\Controller\ActionInterface $controller
* @param array $arguments
......
......@@ -121,8 +121,6 @@ class Request extends AbstractRequest
*/
public function processQuery()
{
$this->setPathInfo();
$this->query = $this->pathInfo;
// It's an request for the admin panel page
......@@ -204,9 +202,17 @@ class Request extends AbstractRequest
return \preg_replace('/\/page_(\d+)\//', '/', $this->query);
}
protected function setPathInfo()
/**
* @inheritdoc
*/
public function setPathInfo(?string $pathInfo = null): void
{
$this->pathInfo = \substr($this->symfonyRequest->getPathInfo(), 1);
if ($pathInfo !== null) {
$this->pathInfo = $pathInfo;
} else {
$this->pathInfo = \substr($this->symfonyRequest->getPathInfo(), 1);
}
$this->pathInfo .= !\preg_match('/\/$/', $this->pathInfo) ? '/' : '';
}
......
......@@ -41,6 +41,7 @@ class RequestFactory
{
$request = $this->getRequest();
$request->setHomepage($this->config->getSettings(Schema::MODULE_NAME)['homepage']);
$request->setPathInfo();
$request->processQuery();
return $request;
......
......@@ -167,4 +167,9 @@ interface RequestInterface
* @return $this
*/
public function setHomepage($homepage);
/**
* @param null|string $pathInfo
*/
public function setPathInfo(?string $pathInfo = null): void;
}
......@@ -35,6 +35,7 @@ class RequestFactory
{
$request = new Request($this->symfonyRequest);
$request->setHomepage($homepage);
$request->setPathInfo();
$request->processQuery();
return $request;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment