‪TYPO3CMS  9.5
RedirectFinisher.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
23 
30 {
31 
35  protected ‪$defaultOptions = [
36  'pageUid' => 1,
37  'additionalParameters' => '',
38  'delay' => 0,
39  'statusCode' => 303,
40  ];
41 
45  protected ‪$request;
46 
50  protected ‪$response;
51 
55  protected ‪$uriBuilder;
56 
61  protected function ‪executeInternal()
62  {
63  $formRuntime = $this->finisherContext->getFormRuntime();
64  $this->request = $formRuntime->getRequest();
65  $this->response = $formRuntime->getResponse();
66  $this->uriBuilder = $this->objectManager->get(UriBuilder::class);
67  $this->uriBuilder->setRequest($this->request);
68 
69  $pageUid = (int)str_replace('pages_', '', $this->‪parseOption('pageUid'));
70  $additionalParameters = $this->‪parseOption('additionalParameters');
71  $additionalParameters = '&' . ltrim($additionalParameters, '&');
72  $delay = (int)$this->‪parseOption('delay');
73  $statusCode = (int)$this->‪parseOption('statusCode');
74 
75  $this->finisherContext->cancel();
76  $this->‪redirect($pageUid, $additionalParameters, $delay, $statusCode);
77  }
78 
94  protected function ‪redirect(int $pageUid = 1, string $additionalParameters = '', int $delay = 0, int $statusCode = 303)
95  {
96  if (!$this->request instanceof ‪Request) {
97  throw new ‪UnsupportedRequestTypeException('redirect() only supports web requests.', 1471776457);
98  }
99 
100  $typolinkConfiguration = [
101  'parameter' => $pageUid,
102  'additionalParams' => $additionalParameters,
103  ];
104  $redirectUri = $this->‪getTypoScriptFrontendController()->cObj->typoLink_URL($typolinkConfiguration);
105  $this->‪redirectToUri($redirectUri, $delay, $statusCode);
106  }
107 
119  protected function ‪redirectToUri(string $uri, int $delay = 0, int $statusCode = 303)
120  {
121  if (!$this->request instanceof Request) {
122  throw new UnsupportedRequestTypeException('redirect() only supports web requests.', 1471776458);
123  }
124 
125  $uri = $this->‪addBaseUriIfNecessary($uri);
126  $escapedUri = htmlentities($uri, ENT_QUOTES, 'utf-8');
127 
128  $this->response->setContent('<html><head><meta http-equiv="refresh" content="' . (int)$delay . ';url=' . $escapedUri . '"/></head></html>');
129  if ($this->response instanceof \‪TYPO3\CMS\‪Extbase\Mvc\Web\Response) {
130  $this->response->setStatus($statusCode);
131  $this->response->setHeader('Location', (string)$uri);
132  }
133  throw new StopActionException('redirectToUri', 1477070964);
134  }
135 
142  protected function ‪addBaseUriIfNecessary(string $uri): string
143  {
144  return GeneralUtility::locationHeaderUrl((string)$uri);
145  }
146 }
‪TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
Definition: StopActionException.php:26
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\redirect
‪redirect(int $pageUid=1, string $additionalParameters='', int $delay=0, int $statusCode=303)
Definition: RedirectFinisher.php:90
‪TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
Definition: UnsupportedRequestTypeException.php:21
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$response
‪TYPO3 CMS Extbase Mvc Web Response $response
Definition: RedirectFinisher.php:47
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:29
‪TYPO3
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:3
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$uriBuilder
‪TYPO3 CMS Extbase Mvc Web Routing UriBuilder $uriBuilder
Definition: RedirectFinisher.php:51
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
Definition: AbstractFinisher.php:35
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\executeInternal
‪executeInternal()
Definition: RedirectFinisher.php:57
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$request
‪TYPO3 CMS Extbase Mvc Web Request $request
Definition: RedirectFinisher.php:43
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\addBaseUriIfNecessary
‪string addBaseUriIfNecessary(string $uri)
Definition: RedirectFinisher.php:138
‪TYPO3\CMS\Extbase\Mvc\Web\Request
Definition: Request.php:21
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\$defaultOptions
‪array $defaultOptions
Definition: RedirectFinisher.php:34
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\parseOption
‪string array null parseOption(string $optionName)
Definition: AbstractFinisher.php:155
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher\redirectToUri
‪redirectToUri(string $uri, int $delay=0, int $statusCode=303)
Definition: RedirectFinisher.php:115
‪TYPO3\CMS\Form\Domain\Finishers\RedirectFinisher
Definition: RedirectFinisher.php:30
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\getTypoScriptFrontendController
‪TypoScriptFrontendController getTypoScriptFrontendController()
Definition: AbstractFinisher.php:367