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