‪TYPO3CMS  ‪main
PageLinkHandler.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
21 
26 {
31  protected ‪$baseUrn = 't3://page';
32 
36  public function ‪asString(array $parameters): string
37  {
38  $urn = $this->baseUrn . '?uid=' . $parameters['pageuid'];
39  $urn = rtrim($urn, ':');
40  // Page type is set and not empty (= "0" in this case means it is not empty)
41  if (isset($parameters['pagetype']) && strlen((string)$parameters['pagetype']) > 0) {
42  $urn .= '&type=' . $parameters['pagetype'];
43  }
44  if (!empty($parameters['parameters'])) {
45  $urn .= '&' . ltrim($parameters['parameters'], '?&');
46  }
47  if (!empty($parameters['fragment'])) {
48  $urn .= '#' . $parameters['fragment'];
49  }
50 
51  return $urn;
52  }
53 
57  public function ‪resolveHandlerData(array $data): array
58  {
59  $result = [];
60  if (isset($data['uid'])) {
61  $result['pageuid'] = ‪MathUtility::canBeInterpretedAsInteger($data['uid']) ? (int)$data['uid'] : $data['uid'];
62  unset($data['uid']);
63  }
64  if (isset($data['type'])) {
65  $result['pagetype'] = $data['type'];
66  unset($data['type']);
67  }
68  if (!empty($data)) {
69  $result['parameters'] = http_build_query($data, '', '&', PHP_QUERY_RFC3986);
70  }
71  if (empty($result)) {
72  $result['pageuid'] = 'current';
73  }
74 
75  return $result;
76  }
77 }
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger(mixed $var)
Definition: MathUtility.php:69
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24