TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
LinkService.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\LinkHandling;
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 
20 
28 {
29  const TYPE_PAGE = 'page';
30  const TYPE_URL = 'url';
31  const TYPE_EMAIL = 'email';
32  const TYPE_FILE = 'file';
33  const TYPE_FOLDER = 'folder';
34  const TYPE_UNKNOWN = 'unknown';
35 
41  protected $handlers;
42 
46  public function __construct()
47  {
48  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['linkHandler'])) {
49  foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['linkHandler'] as $type => $handler) {
50  if (!is_object($this->handlers[$type])) {
51  $this->handlers[$type] = GeneralUtility::makeInstance($handler);
52  }
53  }
54  }
55  }
56 
73  public function resolve(string $linkParameter): array
74  {
75  try {
76  // Check if the new syntax with "t3://" is used
77  return $this->resolveByStringRepresentation($linkParameter);
78  } catch (\InvalidArgumentException $e) {
79  $legacyLinkNotationConverter = GeneralUtility::makeInstance(LegacyLinkNotationConverter::class);
80  return $legacyLinkNotationConverter->resolve($linkParameter);
81  }
82  }
83 
90  public function resolveByStringRepresentation(string $urn): array
91  {
92  // linking to any t3:// syntax
93  if (stripos($urn, 't3://') === 0) {
94  // lets parse the urn
95  $urnParsed = parse_url($urn);
96  $type = $urnParsed['host'];
97  if (isset($urnParsed['query'])) {
98  parse_str($urnParsed['query'], $data);
99  } else {
100  $data = [];
101  }
102  $fragment = $urnParsed['fragment'] ?? null;
103 
104  if (is_object($this->handlers[$type])) {
105  $result = $this->handlers[$type]->resolveHandlerData($data);
106  $result['type'] = $type;
107  } else {
108  throw new \InvalidArgumentException('LinkHandler for ' . $type . ' was not registered', 1460581769);
109  }
110  // this was historically named "section"
111  if ($fragment) {
112  $result['fragment'] = $fragment;
113  }
114  } elseif (stripos($urn, '://') && $this->handlers[self::TYPE_URL]) {
115  $result = $this->handlers[self::TYPE_URL]->resolveHandlerData(['url' => $urn]);
116  $result['type'] = self::TYPE_URL;
117  } elseif (stripos($urn, 'mailto:') === 0 && $this->handlers[self::TYPE_EMAIL]) {
118  $result = $this->handlers[self::TYPE_EMAIL]->resolveHandlerData(['email' => $urn]);
119  $result['type'] = self::TYPE_EMAIL;
120  } else {
121  throw new \InvalidArgumentException('No valid URN to resolve found', 1457177667);
122  }
123 
124  return $result;
125  }
126 
140  public function asString(array $parameters): string
141  {
142  if (is_object($this->handlers[$parameters['type']])) {
143  return $this->handlers[$parameters['type']]->asString($parameters);
144  }
145  throw new \InvalidArgumentException('No valid handlers found for type: ' . $parameters['type'], 1460629247);
146  }
147 }
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)