[TASK] Deprecate methods in PageRepository
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Page / ExternalPageUrlHandler.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Frontend\Page;
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
18 use Psr\Http\Message\ResponseInterface;
19 use TYPO3\CMS\Core\Http\RedirectResponse;
20 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
21
22 /**
23 * Handles the redirection for external URL pages.
24 * @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10.0. The functionality has been moved into a PSR-15 middleware.
25 */
26 class ExternalPageUrlHandler implements \TYPO3\CMS\Frontend\Http\UrlHandlerInterface
27 {
28 /**
29 * @var string
30 */
31 protected $externalUrl = '';
32
33 public function __construct()
34 {
35 trigger_error('ExternalPageUrlHandler has been moved into a PSR-15 middleware and will be removed in TYPO3 v10.0. In order to modify the external page redirection, use a PSR-15 middleware as well', E_USER_DEPRECATED);
36 }
37
38 /**
39 * Checks if external URLs are enabled and if the current page points to an external URL.
40 *
41 * @return bool
42 */
43 public function canHandleCurrentUrl(): bool
44 {
45 $tsfe = $this->getTypoScriptFrontendController();
46
47 if (!empty($tsfe->config['config']['disablePageExternalUrl'])) {
48 return false;
49 }
50
51 $this->externalUrl = $tsfe->sys_page->getExtURL($tsfe->page);
52 if (empty($this->externalUrl)) {
53 return false;
54 }
55 return true;
56 }
57
58 /**
59 * Redirects the user to the detected external URL.
60 */
61 public function handle(): ResponseInterface
62 {
63 return new RedirectResponse($this->externalUrl, 303);
64 }
65
66 /**
67 * @return TypoScriptFrontendController
68 */
69 protected function getTypoScriptFrontendController(): TypoScriptFrontendController
70 {
71 return $GLOBALS['TSFE'];
72 }
73 }