[TASK] Move FlexFormService from EXT:extbase to EXT:core
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / ResourceFactory.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Core\Environment;
19 use TYPO3\CMS\Core\Database\ConnectionPool;
20 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
21 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
22 use TYPO3\CMS\Core\Service\FlexFormService;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Core\Utility\MathUtility;
25 use TYPO3\CMS\Core\Utility\PathUtility;
26 use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
27
28 // @todo implement constructor-level caching
29 /**
30 * Factory class for FAL objects
31 */
32 class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\SingletonInterface
33 {
34 /**
35 * Gets a singleton instance of this class.
36 *
37 * @return ResourceFactory
38 */
39 public static function getInstance()
40 {
41 return GeneralUtility::makeInstance(__CLASS__);
42 }
43
44 /**
45 * @var ResourceStorage[]
46 */
47 protected $storageInstances = [];
48
49 /**
50 * @var Collection\AbstractFileCollection[]
51 */
52 protected $collectionInstances = [];
53
54 /**
55 * @var File[]
56 */
57 protected $fileInstances = [];
58
59 /**
60 * @var FileReference[]
61 */
62 protected $fileReferenceInstances = [];
63
64 /**
65 * A list of the base paths of "local" driver storages. Used to make the detection of base paths easier.
66 *
67 * @var array
68 */
69 protected $localDriverStorageCache;
70
71 /**
72 * @var Dispatcher
73 */
74 protected $signalSlotDispatcher;
75
76 /**
77 * Inject signal slot dispatcher
78 *
79 * @param Dispatcher $signalSlotDispatcher an instance of the signal slot dispatcher
80 */
81 public function __construct(Dispatcher $signalSlotDispatcher = null)
82 {
83 $this->signalSlotDispatcher = $signalSlotDispatcher ?: GeneralUtility::makeInstance(Dispatcher::class);
84 }
85
86 /**
87 * Creates a driver object for a specified storage object.
88 *
89 * @param string $driverIdentificationString The driver class (or identifier) to use.
90 * @param array $driverConfiguration The configuration of the storage
91 * @return Driver\DriverInterface
92 * @throws \InvalidArgumentException
93 */
94 public function getDriverObject($driverIdentificationString, array $driverConfiguration)
95 {
96 /** @var $driverRegistry Driver\DriverRegistry */
97 $driverRegistry = GeneralUtility::makeInstance(Driver\DriverRegistry::class);
98 $driverClass = $driverRegistry->getDriverClass($driverIdentificationString);
99 $driverObject = GeneralUtility::makeInstance($driverClass, $driverConfiguration);
100 return $driverObject;
101 }
102
103 /**
104 * Returns the Default Storage
105 *
106 * The Default Storage is considered to be the replacement for the fileadmin/ construct.
107 * It is automatically created with the setting fileadminDir from install tool.
108 * getDefaultStorage->getDefaultFolder() will get you fileadmin/user_upload/ in a standard
109 * TYPO3 installation.
110 *
111 * @return ResourceStorage|null
112 */
113 public function getDefaultStorage()
114 {
115 /** @var $storageRepository StorageRepository */
116 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
117
118 $allStorages = $storageRepository->findAll();
119 foreach ($allStorages as $storage) {
120 if ($storage->isDefault()) {
121 return $storage;
122 }
123 }
124 return null;
125 }
126 /**
127 * Creates an instance of the storage from given UID. The $recordData can
128 * be supplied to increase performance.
129 *
130 * @param int $uid The uid of the storage to instantiate.
131 * @param array $recordData The record row from database.
132 * @param string $fileIdentifier Identifier for a file. Used for auto-detection of a storage, but only if $uid === 0 (Local default storage) is used
133 *
134 * @throws \InvalidArgumentException
135 * @return ResourceStorage
136 */
137 public function getStorageObject($uid, array $recordData = [], &$fileIdentifier = null)
138 {
139 if (!is_numeric($uid)) {
140 throw new \InvalidArgumentException('The UID of storage has to be numeric. UID given: "' . $uid . '"', 1314085991);
141 }
142 $uid = (int)$uid;
143 if ($uid === 0 && $fileIdentifier !== null) {
144 $uid = $this->findBestMatchingStorageByLocalPath($fileIdentifier);
145 }
146 if (empty($this->storageInstances[$uid])) {
147 $storageConfiguration = null;
148 $storageObject = null;
149 list($_, $uid, $recordData, $fileIdentifier) = $this->emitPreProcessStorageSignal($uid, $recordData, $fileIdentifier);
150 // If the built-in storage with UID=0 is requested:
151 if ($uid === 0) {
152 $recordData = [
153 'uid' => 0,
154 'pid' => 0,
155 'name' => 'Fallback Storage',
156 'description' => 'Internal storage, mounting the main TYPO3_site directory.',
157 'driver' => 'Local',
158 'processingfolder' => 'typo3temp/assets/_processed_/',
159 // legacy code
160 'configuration' => '',
161 'is_online' => true,
162 'is_browsable' => true,
163 'is_public' => true,
164 'is_writable' => true,
165 'is_default' => false,
166 ];
167 $storageConfiguration = [
168 'basePath' => '/',
169 'pathType' => 'relative'
170 ];
171 } elseif (count($recordData) === 0 || (int)$recordData['uid'] !== $uid) {
172 /** @var $storageRepository StorageRepository */
173 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
174 /** @var $storage ResourceStorage */
175 $storageObject = $storageRepository->findByUid($uid);
176 }
177 if (!$storageObject instanceof ResourceStorage) {
178 $storageObject = $this->createStorageObject($recordData, $storageConfiguration);
179 }
180 $this->emitPostProcessStorageSignal($storageObject);
181 $this->storageInstances[$uid] = $storageObject;
182 }
183 return $this->storageInstances[$uid];
184 }
185
186 /**
187 * Emits a signal before a resource storage was initialized
188 *
189 * @param int $uid
190 * @param array $recordData
191 * @param string $fileIdentifier
192 * @return mixed
193 */
194 protected function emitPreProcessStorageSignal($uid, $recordData, $fileIdentifier)
195 {
196 return $this->signalSlotDispatcher->dispatch(\TYPO3\CMS\Core\Resource\ResourceFactory::class, self::SIGNAL_PreProcessStorage, [$this, $uid, $recordData, $fileIdentifier]);
197 }
198
199 /**
200 * Emits a signal after a resource storage was initialized
201 *
202 * @param ResourceStorage $storageObject
203 */
204 protected function emitPostProcessStorageSignal(ResourceStorage $storageObject)
205 {
206 $this->signalSlotDispatcher->dispatch(self::class, self::SIGNAL_PostProcessStorage, [$this, $storageObject]);
207 }
208
209 /**
210 * Checks whether a file resides within a real storage in local file system.
211 * If no match is found, uid 0 is returned which is a fallback storage pointing to fileadmin in public web path.
212 *
213 * The file identifier is adapted accordingly to match the new storage's base path.
214 *
215 * @param string $localPath
216 *
217 * @return int
218 */
219 protected function findBestMatchingStorageByLocalPath(&$localPath)
220 {
221 if ($this->localDriverStorageCache === null) {
222 $this->initializeLocalStorageCache();
223 }
224
225 $bestMatchStorageUid = 0;
226 $bestMatchLength = 0;
227 foreach ($this->localDriverStorageCache as $storageUid => $basePath) {
228 $matchLength = strlen(PathUtility::getCommonPrefix([$basePath, $localPath]));
229 $basePathLength = strlen($basePath);
230
231 if ($matchLength >= $basePathLength && $matchLength > $bestMatchLength) {
232 $bestMatchStorageUid = (int)$storageUid;
233 $bestMatchLength = $matchLength;
234 }
235 }
236 if ($bestMatchStorageUid !== 0) {
237 $localPath = substr($localPath, $bestMatchLength);
238 }
239 return $bestMatchStorageUid;
240 }
241
242 /**
243 * Creates an array mapping all uids to the basePath of storages using the "local" driver.
244 */
245 protected function initializeLocalStorageCache()
246 {
247 /** @var $storageRepository StorageRepository */
248 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
249 /** @var $storageObjects ResourceStorage[] */
250 $storageObjects = $storageRepository->findByStorageType('Local');
251
252 $storageCache = [];
253 foreach ($storageObjects as $localStorage) {
254 $configuration = $localStorage->getConfiguration();
255 $storageCache[$localStorage->getUid()] = $configuration['basePath'];
256 }
257 $this->localDriverStorageCache = $storageCache;
258 }
259
260 /**
261 * Converts a flexform data string to a flat array with key value pairs
262 *
263 * @param string $flexFormData
264 * @return array Array with key => value pairs of the field data in the FlexForm
265 */
266 public function convertFlexFormDataToConfigurationArray($flexFormData)
267 {
268 $configuration = [];
269 if ($flexFormData) {
270 $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
271 $configuration = $flexFormService->convertFlexFormContentToArray($flexFormData);
272 }
273 return $configuration;
274 }
275
276 /**
277 * Creates an instance of the collection from given UID. The $recordData can be supplied to increase performance.
278 *
279 * @param int $uid The uid of the collection to instantiate.
280 * @param array $recordData The record row from database.
281 *
282 * @throws \InvalidArgumentException
283 * @return Collection\AbstractFileCollection
284 */
285 public function getCollectionObject($uid, array $recordData = [])
286 {
287 if (!is_numeric($uid)) {
288 throw new \InvalidArgumentException('The UID of collection has to be numeric. UID given: "' . $uid . '"', 1314085999);
289 }
290 if (!$this->collectionInstances[$uid]) {
291 // Get mount data if not already supplied as argument to this function
292 if (empty($recordData) || $recordData['uid'] !== $uid) {
293 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_collection');
294 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
295 $recordData = $queryBuilder->select('*')
296 ->from('sys_file_collection')
297 ->where(
298 $queryBuilder->expr()->eq(
299 'uid',
300 $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
301 )
302 )
303 ->execute()
304 ->fetch();
305 if (empty($recordData)) {
306 throw new \InvalidArgumentException('No collection found for given UID: "' . $uid . '"', 1314085992);
307 }
308 }
309 $collectionObject = $this->createCollectionObject($recordData);
310 $this->collectionInstances[$uid] = $collectionObject;
311 }
312 return $this->collectionInstances[$uid];
313 }
314
315 /**
316 * Creates a collection object.
317 *
318 * @param array $collectionData The database row of the sys_file_collection record.
319 * @return Collection\AbstractFileCollection
320 */
321 public function createCollectionObject(array $collectionData)
322 {
323 /** @var $registry Collection\FileCollectionRegistry */
324 $registry = GeneralUtility::makeInstance(Collection\FileCollectionRegistry::class);
325
326 /** @var \TYPO3\CMS\Core\Collection\AbstractRecordCollection $class */
327 $class = $registry->getFileCollectionClass($collectionData['type']);
328
329 return $class::create($collectionData);
330 }
331
332 /**
333 * Creates a storage object from a storage database row.
334 *
335 * @param array $storageRecord
336 * @param array $storageConfiguration Storage configuration (if given, this won't be extracted from the FlexForm value but the supplied array used instead)
337 * @return ResourceStorage
338 */
339 public function createStorageObject(array $storageRecord, array $storageConfiguration = null)
340 {
341 if (!$storageConfiguration) {
342 $storageConfiguration = $this->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
343 }
344 $driverType = $storageRecord['driver'];
345 $driverObject = $this->getDriverObject($driverType, $storageConfiguration);
346 return GeneralUtility::makeInstance(ResourceStorage::class, $driverObject, $storageRecord);
347 }
348
349 /**
350 * Creates a folder to directly access (a part of) a storage.
351 *
352 * @param ResourceStorage $storage The storage the folder belongs to
353 * @param string $identifier The path to the folder. Might also be a simple unique string, depending on the storage driver.
354 * @param string $name The name of the folder (e.g. the folder name)
355 * @return Folder
356 */
357 public function createFolderObject(ResourceStorage $storage, $identifier, $name)
358 {
359 return GeneralUtility::makeInstance(Folder::class, $storage, $identifier, $name);
360 }
361
362 /**
363 * Creates an instance of the file given UID. The $fileData can be supplied
364 * to increase performance.
365 *
366 * @param int $uid The uid of the file to instantiate.
367 * @param array $fileData The record row from database.
368 *
369 * @throws \InvalidArgumentException
370 * @throws Exception\FileDoesNotExistException
371 * @return File
372 */
373 public function getFileObject($uid, array $fileData = [])
374 {
375 if (!is_numeric($uid)) {
376 throw new \InvalidArgumentException('The UID of file has to be numeric. UID given: "' . $uid . '"', 1300096564);
377 }
378 if (empty($this->fileInstances[$uid])) {
379 // Fetches data in case $fileData is empty
380 if (empty($fileData)) {
381 $fileData = $this->getFileIndexRepository()->findOneByUid($uid);
382 if ($fileData === false) {
383 throw new Exception\FileDoesNotExistException('No file found for given UID: ' . $uid, 1317178604);
384 }
385 }
386 $this->fileInstances[$uid] = $this->createFileObject($fileData);
387 }
388 return $this->fileInstances[$uid];
389 }
390
391 /**
392 * Gets an file object from an identifier [storage]:[fileId]
393 *
394 * @param string $identifier
395 * @return File
396 * @throws \InvalidArgumentException
397 */
398 public function getFileObjectFromCombinedIdentifier($identifier)
399 {
400 if (!isset($identifier) || !is_string($identifier) || $identifier === '') {
401 throw new \InvalidArgumentException('Invalid file identifier given. It must be of type string and not empty. "' . gettype($identifier) . '" given.', 1401732564);
402 }
403 $parts = GeneralUtility::trimExplode(':', $identifier);
404 if (count($parts) === 2) {
405 $storageUid = $parts[0];
406 $fileIdentifier = $parts[1];
407 } else {
408 // We only got a path: Go into backwards compatibility mode and
409 // use virtual Storage (uid=0)
410 $storageUid = 0;
411 $fileIdentifier = $parts[0];
412 }
413
414 // please note that getStorageObject() might modify $fileIdentifier when
415 // auto-detecting the best-matching storage to use
416 return $this->getFileObjectByStorageAndIdentifier($storageUid, $fileIdentifier);
417 }
418
419 /**
420 * Gets an file object from storage by file identifier
421 * If the file is outside of the process folder it gets indexed and returned as file object afterwards
422 * If the file is within processing folder the file object will be directly returned
423 *
424 * @param int $storageUid
425 * @param string $fileIdentifier
426 * @return File|ProcessedFile|null
427 */
428 public function getFileObjectByStorageAndIdentifier($storageUid, &$fileIdentifier)
429 {
430 $storage = $this->getStorageObject($storageUid, [], $fileIdentifier);
431 if (!$storage->isWithinProcessingFolder($fileIdentifier)) {
432 $fileData = $this->getFileIndexRepository()->findOneByStorageUidAndIdentifier($storage->getUid(), $fileIdentifier);
433 if ($fileData === false) {
434 $fileObject = $this->getIndexer($storage)->createIndexEntry($fileIdentifier);
435 } else {
436 $fileObject = $this->getFileObject($fileData['uid'], $fileData);
437 }
438 } else {
439 $fileObject = $this->getProcessedFileRepository()->findByStorageAndIdentifier($storage, $fileIdentifier);
440 }
441
442 return $fileObject;
443 }
444
445 /**
446 * Bulk function, can be used for anything to get a file or folder
447 *
448 * 1. It's a UID
449 * 2. It's a combined identifier
450 * 3. It's just a path/filename (coming from the oldstyle/backwards compatibility)
451 *
452 * Files, previously laid on fileadmin/ or something, will be "mapped" to the storage the file is
453 * in now. Files like typo3temp/ or typo3conf/ will be moved to the first writable storage
454 * in its processing folder
455 *
456 * $input could be
457 * - "2:myfolder/myfile.jpg" (combined identifier)
458 * - "23" (file UID)
459 * - "uploads/myfile.png" (backwards-compatibility, storage "0")
460 * - "file:23"
461 *
462 * @param string $input
463 * @return File|Folder
464 */
465 public function retrieveFileOrFolderObject($input)
466 {
467 // Remove Environment::getPublicPath() because absolute paths under Windows systems contain ':'
468 // This is done in all considered sub functions anyway
469 $input = str_replace(Environment::getPublicPath() . '/', '', $input);
470
471 if (GeneralUtility::isFirstPartOfStr($input, 'file:')) {
472 $input = substr($input, 5);
473 return $this->retrieveFileOrFolderObject($input);
474 }
475 if (MathUtility::canBeInterpretedAsInteger($input)) {
476 return $this->getFileObject($input);
477 }
478 if (strpos($input, ':') > 0) {
479 list($prefix) = explode(':', $input);
480 if (MathUtility::canBeInterpretedAsInteger($prefix)) {
481 // path or folder in a valid storageUID
482 return $this->getObjectFromCombinedIdentifier($input);
483 }
484 if ($prefix === 'EXT') {
485 $input = GeneralUtility::getFileAbsFileName($input);
486 if (empty($input)) {
487 return null;
488 }
489
490 $input = PathUtility::getRelativePath(Environment::getPublicPath() . '/', PathUtility::dirname($input)) . PathUtility::basename($input);
491 return $this->getFileObjectFromCombinedIdentifier($input);
492 }
493 return null;
494 }
495 // this is a backwards-compatible way to access "0-storage" files or folders
496 // eliminate double slashes, /./ and /../
497 $input = PathUtility::getCanonicalPath(ltrim($input, '/'));
498 if (@is_file(Environment::getPublicPath() . '/' . $input)) {
499 // only the local file
500 return $this->getFileObjectFromCombinedIdentifier($input);
501 }
502 // only the local path
503 return $this->getFolderObjectFromCombinedIdentifier($input);
504 }
505
506 /**
507 * Gets a folder object from an identifier [storage]:[fileId]
508 *
509 * @TODO check naming, inserted by SteffenR while working on filelist
510 * @param string $identifier
511 * @return Folder
512 */
513 public function getFolderObjectFromCombinedIdentifier($identifier)
514 {
515 $parts = GeneralUtility::trimExplode(':', $identifier);
516 if (count($parts) === 2) {
517 $storageUid = $parts[0];
518 $folderIdentifier = $parts[1];
519 } else {
520 // We only got a path: Go into backwards compatibility mode and
521 // use virtual Storage (uid=0)
522 $storageUid = 0;
523
524 // please note that getStorageObject() might modify $folderIdentifier when
525 // auto-detecting the best-matching storage to use
526 $folderIdentifier = $parts[0];
527 // make sure to not use an absolute path, and remove Environment::getPublicPath if it is prepended
528 if (GeneralUtility::isFirstPartOfStr($folderIdentifier, Environment::getPublicPath() . '/')) {
529 $folderIdentifier = PathUtility::stripPathSitePrefix($parts[0]);
530 }
531 }
532 return $this->getStorageObject($storageUid, [], $folderIdentifier)->getFolder($folderIdentifier);
533 }
534
535 /**
536 * Gets a storage object from a combined identifier
537 *
538 * @param string $identifier An identifier of the form [storage uid]:[object identifier]
539 * @return ResourceStorage
540 */
541 public function getStorageObjectFromCombinedIdentifier($identifier)
542 {
543 $parts = GeneralUtility::trimExplode(':', $identifier);
544 $storageUid = count($parts) === 2 ? $parts[0] : null;
545 return $this->getStorageObject($storageUid);
546 }
547
548 /**
549 * Gets a file or folder object.
550 *
551 * @param string $identifier
552 *
553 * @throws Exception\ResourceDoesNotExistException
554 * @return FileInterface|Folder
555 */
556 public function getObjectFromCombinedIdentifier($identifier)
557 {
558 list($storageId, $objectIdentifier) = GeneralUtility::trimExplode(':', $identifier);
559 $storage = $this->getStorageObject($storageId);
560 if ($storage->hasFile($objectIdentifier)) {
561 return $storage->getFile($objectIdentifier);
562 }
563 if ($storage->hasFolder($objectIdentifier)) {
564 return $storage->getFolder($objectIdentifier);
565 }
566 throw new Exception\ResourceDoesNotExistException('Object with identifier "' . $identifier . '" does not exist in storage', 1329647780);
567 }
568
569 /**
570 * Creates a file object from an array of file data. Requires a database
571 * row to be fetched.
572 *
573 * @param array $fileData
574 * @param ResourceStorage $storage
575 * @return File
576 */
577 public function createFileObject(array $fileData, ResourceStorage $storage = null)
578 {
579 /** @var File $fileObject */
580 if (array_key_exists('storage', $fileData) && MathUtility::canBeInterpretedAsInteger($fileData['storage'])) {
581 $storageObject = $this->getStorageObject((int)$fileData['storage']);
582 } elseif ($storage !== null) {
583 $storageObject = $storage;
584 $fileData['storage'] = $storage->getUid();
585 } else {
586 throw new \RuntimeException('A file needs to reside in a Storage', 1381570997);
587 }
588 $fileObject = GeneralUtility::makeInstance(File::class, $fileData, $storageObject);
589 return $fileObject;
590 }
591
592 /**
593 * Creates an instance of a FileReference object. The $fileReferenceData can
594 * be supplied to increase performance.
595 *
596 * @param int $uid The uid of the file usage (sys_file_reference) to instantiate.
597 * @param array $fileReferenceData The record row from database.
598 * @param bool $raw Whether to get raw results without performing overlays
599 * @return FileReference
600 * @throws \InvalidArgumentException
601 * @throws Exception\ResourceDoesNotExistException
602 */
603 public function getFileReferenceObject($uid, array $fileReferenceData = [], $raw = false)
604 {
605 if (!is_numeric($uid)) {
606 throw new \InvalidArgumentException(
607 'The reference UID for the file (sys_file_reference) has to be numeric. UID given: "' . $uid . '"',
608 1300086584
609 );
610 }
611 if (!$this->fileReferenceInstances[$uid]) {
612 // Fetches data in case $fileData is empty
613 if (empty($fileReferenceData)) {
614 $fileReferenceData = $this->getFileReferenceData($uid, $raw);
615 if (!is_array($fileReferenceData)) {
616 throw new Exception\ResourceDoesNotExistException(
617 'No file reference (sys_file_reference) was found for given UID: "' . $uid . '"',
618 1317178794
619 );
620 }
621 }
622 $this->fileReferenceInstances[$uid] = $this->createFileReferenceObject($fileReferenceData);
623 }
624 return $this->fileReferenceInstances[$uid];
625 }
626
627 /**
628 * Creates a file usage object from an array of fileReference data
629 * from sys_file_reference table.
630 * Requires a database row to be already fetched and present.
631 *
632 * @param array $fileReferenceData
633 * @return FileReference
634 */
635 public function createFileReferenceObject(array $fileReferenceData)
636 {
637 /** @var FileReference $fileReferenceObject */
638 $fileReferenceObject = GeneralUtility::makeInstance(FileReference::class, $fileReferenceData);
639 return $fileReferenceObject;
640 }
641
642 /**
643 * Gets data for the given uid of the file reference record.
644 *
645 * @param int $uid The uid of the file usage (sys_file_reference) to be fetched
646 * @param bool $raw Whether to get raw results without performing overlays
647 * @return array|null
648 */
649 protected function getFileReferenceData($uid, $raw = false)
650 {
651 if (!$raw && TYPO3_MODE === 'BE') {
652 $fileReferenceData = BackendUtility::getRecordWSOL('sys_file_reference', $uid);
653 } elseif (!$raw && is_object($GLOBALS['TSFE'])) {
654 $fileReferenceData = $GLOBALS['TSFE']->sys_page->checkRecord('sys_file_reference', $uid);
655 } else {
656 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
657 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
658 $fileReferenceData = $queryBuilder->select('*')
659 ->from('sys_file_reference')
660 ->where(
661 $queryBuilder->expr()->eq(
662 'uid',
663 $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
664 )
665 )
666 ->execute()
667 ->fetch();
668 }
669 return $fileReferenceData;
670 }
671
672 /**
673 * Returns an instance of the FileIndexRepository
674 *
675 * @return FileIndexRepository
676 */
677 protected function getFileIndexRepository()
678 {
679 return FileIndexRepository::getInstance();
680 }
681
682 /**
683 * Returns an instance of the ProcessedFileRepository
684 *
685 * @return ProcessedFileRepository
686 */
687 protected function getProcessedFileRepository()
688 {
689 return GeneralUtility::makeInstance(ProcessedFileRepository::class);
690 }
691
692 /**
693 * Returns an instance of the Indexer
694 *
695 * @param ResourceStorage $storage
696 * @return Index\Indexer
697 */
698 protected function getIndexer(ResourceStorage $storage)
699 {
700 return GeneralUtility::makeInstance(Index\Indexer::class, $storage);
701 }
702 }