[TASK] Remove ext:dbal from installation steps
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / LinkHandling / FolderLinkHandler.php
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 use TYPO3\CMS\Core\Resource\ResourceFactory;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Interface for classes which are transforming a tag link hrefs for folders, in order to
22 * use FAL to store them in database, which means that folders can be moved in the fileadmin
23 * without breaking folder links in the frontend/backend
24 */
25 class FolderLinkHandler implements LinkHandlingInterface
26 {
27
28 /**
29 * The Base URN
30 * @var string
31 */
32 protected $baseUrn = 't3://folder';
33
34 /**
35 * The resource factory to resolve
36 * @var \TYPO3\CMS\Core\Resource\ResourceFactory
37 */
38 protected $resourceFactory;
39
40 /**
41 * Returns a link notation to a folder
42 *
43 * @param array $parameters
44 *
45 * @return string
46 */
47 public function asString(array $parameters): string
48 {
49 // the magic with prepending slash if it is missing will not work on windows
50 return $this->baseUrn . '?storage=' . $parameters['folder']->getStorage()->getUid() .
51 '&identifier=' . urlencode('/' . ltrim($parameters['folder']->getIdentifier(), '/'));
52 }
53
54 /**
55 * Get a folder object inside the array data from the string
56 *
57 * @param array $data with the "folder" property containing a Folder object
58 *
59 * @return array
60 */
61 public function resolveHandlerData(array $data): array
62 {
63 $combinedIdentifier = ($data['storage'] ?? '0') . ':' . $data['identifier'];
64 return ['folder' => $this->getResourceFactory()->getFolderObjectFromCombinedIdentifier($combinedIdentifier)];
65 }
66
67 /**
68 * Initializes the resource factory (only once)
69 *
70 * @return ResourceFactory
71 */
72 protected function getResourceFactory(): ResourceFactory
73 {
74 if (!$this->resourceFactory) {
75 $this->resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
76 }
77 return $this->resourceFactory;
78 }
79 }