9979f2a4fda86dfb3a958aff75d2c21953ae6995
[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\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Database\DatabaseConnection;
20 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
21 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\CMS\Core\Utility\MathUtility;
24 use TYPO3\CMS\Core\Utility\PathUtility;
25 use TYPO3\CMS\Extbase\Service\FlexFormService;
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 = null;
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 null|ResourceStorage
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 (!$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(ResourceFactory::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 PATH_site.
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 * @return void
246 */
247 protected function initializeLocalStorageCache()
248 {
249 /** @var $storageRepository StorageRepository */
250 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
251 /** @var $storageObjects ResourceStorage[] */
252 $storageObjects = $storageRepository->findByStorageType('Local');
253
254 $storageCache = [];
255 foreach ($storageObjects as $localStorage) {
256 $configuration = $localStorage->getConfiguration();
257 $storageCache[$localStorage->getUid()] = $configuration['basePath'];
258 }
259 $this->localDriverStorageCache = $storageCache;
260 }
261
262 /**
263 * Converts a flexform data string to a flat array with key value pairs
264 *
265 * @param string $flexFormData
266 * @return array Array with key => value pairs of the field data in the FlexForm
267 */
268 public function convertFlexFormDataToConfigurationArray($flexFormData)
269 {
270 $configuration = [];
271 if ($flexFormData) {
272 $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
273 $configuration = $flexFormService->convertFlexFormContentToArray($flexFormData);
274 }
275 return $configuration;
276 }
277
278 /**
279 * Creates an instance of the collection from given UID. The $recordData can be supplied to increase performance.
280 *
281 * @param int $uid The uid of the collection to instantiate.
282 * @param array $recordData The record row from database.
283 *
284 * @throws \InvalidArgumentException
285 * @return Collection\AbstractFileCollection
286 */
287 public function getCollectionObject($uid, array $recordData = [])
288 {
289 if (!is_numeric($uid)) {
290 throw new \InvalidArgumentException('The UID of collection has to be numeric. UID given: "' . $uid . '"', 1314085999);
291 }
292 if (!$this->collectionInstances[$uid]) {
293 // Get mount data if not already supplied as argument to this function
294 if (empty($recordData) || $recordData['uid'] !== $uid) {
295 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_collection');
296 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
297 $recordData = $queryBuilder->select('*')
298 ->from('sys_file_collection')
299 ->where($queryBuilder->expr()->eq('uid', (int)$uid))
300 ->execute()
301 ->fetch();
302 if (empty($recordData)) {
303 throw new \InvalidArgumentException('No collection found for given UID: "' . $uid . '"', 1314085992);
304 }
305 }
306 $collectionObject = $this->createCollectionObject($recordData);
307 $this->collectionInstances[$uid] = $collectionObject;
308 }
309 return $this->collectionInstances[$uid];
310 }
311
312 /**
313 * Creates a collection object.
314 *
315 * @param array $collectionData The database row of the sys_file_collection record.
316 * @return Collection\AbstractFileCollection
317 */
318 public function createCollectionObject(array $collectionData)
319 {
320 /** @var $registry Collection\FileCollectionRegistry */
321 $registry = GeneralUtility::makeInstance(Collection\FileCollectionRegistry::class);
322
323 /** @var \TYPO3\CMS\Core\Collection\AbstractRecordCollection $class */
324 $class = $registry->getFileCollectionClass($collectionData['type']);
325
326 return $class::create($collectionData);
327 }
328
329 /**
330 * Creates a storage object from a storage database row.
331 *
332 * @param array $storageRecord
333 * @param array $storageConfiguration Storage configuration (if given, this won't be extracted from the FlexForm value but the supplied array used instead)
334 * @return ResourceStorage
335 */
336 public function createStorageObject(array $storageRecord, array $storageConfiguration = null)
337 {
338 if (!$storageConfiguration) {
339 $storageConfiguration = $this->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
340 }
341 $driverType = $storageRecord['driver'];
342 $driverObject = $this->getDriverObject($driverType, $storageConfiguration);
343 return GeneralUtility::makeInstance(ResourceStorage::class, $driverObject, $storageRecord);
344 }
345
346 /**
347 * Creates a folder to directly access (a part of) a storage.
348 *
349 * @param ResourceStorage $storage The storage the folder belongs to
350 * @param string $identifier The path to the folder. Might also be a simple unique string, depending on the storage driver.
351 * @param string $name The name of the folder (e.g. the folder name)
352 * @return Folder
353 */
354 public function createFolderObject(ResourceStorage $storage, $identifier, $name)
355 {
356 return GeneralUtility::makeInstance(Folder::class, $storage, $identifier, $name);
357 }
358
359 /**
360 * Creates an instance of the file given UID. The $fileData can be supplied
361 * to increase performance.
362 *
363 * @param int $uid The uid of the file to instantiate.
364 * @param array $fileData The record row from database.
365 *
366 * @throws \InvalidArgumentException
367 * @throws Exception\FileDoesNotExistException
368 * @return File
369 */
370 public function getFileObject($uid, array $fileData = [])
371 {
372 if (!is_numeric($uid)) {
373 throw new \InvalidArgumentException('The UID of file has to be numeric. UID given: "' . $uid . '"', 1300096564);
374 }
375 if (!$this->fileInstances[$uid]) {
376 // Fetches data in case $fileData is empty
377 if (empty($fileData)) {
378 $fileData = $this->getFileIndexRepository()->findOneByUid($uid);
379 if ($fileData === false) {
380 throw new Exception\FileDoesNotExistException('No file found for given UID: ' . $uid, 1317178604);
381 }
382 }
383 $this->fileInstances[$uid] = $this->createFileObject($fileData);
384 }
385 return $this->fileInstances[$uid];
386 }
387
388 /**
389 * Gets an file object from an identifier [storage]:[fileId]
390 *
391 * @param string $identifier
392 * @return File
393 * @throws \InvalidArgumentException
394 */
395 public function getFileObjectFromCombinedIdentifier($identifier)
396 {
397 if (!isset($identifier) || !is_string($identifier) || $identifier === '') {
398 throw new \InvalidArgumentException('Invalid file identifier given. It must be of type string and not empty. "' . gettype($identifier) . '" given.', 1401732564);
399 }
400 $parts = GeneralUtility::trimExplode(':', $identifier);
401 if (count($parts) === 2) {
402 $storageUid = $parts[0];
403 $fileIdentifier = $parts[1];
404 } else {
405 // We only got a path: Go into backwards compatibility mode and
406 // use virtual Storage (uid=0)
407 $storageUid = 0;
408 $fileIdentifier = $parts[0];
409 }
410
411 // please note that getStorageObject() might modify $fileIdentifier when
412 // auto-detecting the best-matching storage to use
413 return $this->getFileObjectByStorageAndIdentifier($storageUid, $fileIdentifier);
414 }
415
416 /**
417 * Gets an file object from storage by file identifier
418 * If the file is outside of the process folder it gets indexed and returned as file object afterwards
419 * If the file is within processing folder the file object will be directly returned
420 *
421 * @param int $storageUid
422 * @param string $fileIdentifier
423 * @return NULL|File|ProcessedFile
424 */
425 public function getFileObjectByStorageAndIdentifier($storageUid, &$fileIdentifier)
426 {
427 $storage = $this->getStorageObject($storageUid, [], $fileIdentifier);
428 if (!$storage->isWithinProcessingFolder($fileIdentifier)) {
429 $fileData = $this->getFileIndexRepository()->findOneByStorageUidAndIdentifier($storage->getUid(), $fileIdentifier);
430 if ($fileData === false) {
431 $fileObject = $this->getIndexer($storage)->createIndexEntry($fileIdentifier);
432 } else {
433 $fileObject = $this->getFileObject($fileData['uid'], $fileData);
434 }
435 } else {
436 $fileObject = $this->getProcessedFileRepository()->findByStorageAndIdentifier($storage, $fileIdentifier);
437 }
438
439 return $fileObject;
440 }
441
442 /**
443 * Bulk function, can be used for anything to get a file or folder
444 *
445 * 1. It's a UID
446 * 2. It's a combined identifier
447 * 3. It's just a path/filename (coming from the oldstyle/backwards compatibility)
448 *
449 * Files, previously laid on fileadmin/ or something, will be "mapped" to the storage the file is
450 * in now. Files like typo3temp/ or typo3conf/ will be moved to the first writable storage
451 * in its processing folder
452 *
453 * $input could be
454 * - "2:myfolder/myfile.jpg" (combined identifier)
455 * - "23" (file UID)
456 * - "uploads/myfile.png" (backwards-compatibility, storage "0")
457 * - "file:23"
458 *
459 * @param string $input
460 * @return File|Folder
461 */
462 public function retrieveFileOrFolderObject($input)
463 {
464 // Remove PATH_site because absolute paths under Windows systems contain ':'
465 // This is done in all considered sub functions anyway
466 $input = str_replace(PATH_site, '', $input);
467
468 if (GeneralUtility::isFirstPartOfStr($input, 'file:')) {
469 $input = substr($input, 5);
470 return $this->retrieveFileOrFolderObject($input);
471 } elseif (MathUtility::canBeInterpretedAsInteger($input)) {
472 return $this->getFileObject($input);
473 } elseif (strpos($input, ':') > 0) {
474 list($prefix) = explode(':', $input);
475 if (MathUtility::canBeInterpretedAsInteger($prefix)) {
476 // path or folder in a valid storageUID
477 return $this->getObjectFromCombinedIdentifier($input);
478 } elseif ($prefix == 'EXT') {
479 $input = GeneralUtility::getFileAbsFileName($input);
480 if (empty($input)) {
481 return null;
482 }
483
484 $input = PathUtility::getRelativePath(PATH_site, PathUtility::dirname($input)) . PathUtility::basename($input);
485 return $this->getFileObjectFromCombinedIdentifier($input);
486 } else {
487 return null;
488 }
489 } else {
490 // this is a backwards-compatible way to access "0-storage" files or folders
491 // eliminate double slashes, /./ and /../
492 $input = PathUtility::getCanonicalPath(ltrim($input, '/'));
493 if (@is_file(PATH_site . $input)) {
494 // only the local file
495 return $this->getFileObjectFromCombinedIdentifier($input);
496 } else {
497 // only the local path
498 return $this->getFolderObjectFromCombinedIdentifier($input);
499 }
500 }
501 }
502
503 /**
504 * Gets a folder object from an identifier [storage]:[fileId]
505 *
506 * @TODO check naming, inserted by SteffenR while working on filelist
507 * @param string $identifier
508 * @return Folder
509 */
510 public function getFolderObjectFromCombinedIdentifier($identifier)
511 {
512 $parts = GeneralUtility::trimExplode(':', $identifier);
513 if (count($parts) === 2) {
514 $storageUid = $parts[0];
515 $folderIdentifier = $parts[1];
516 } else {
517 // We only got a path: Go into backwards compatibility mode and
518 // use virtual Storage (uid=0)
519 $storageUid = 0;
520
521 // please note that getStorageObject() might modify $folderIdentifier when
522 // auto-detecting the best-matching storage to use
523 $folderIdentifier = $parts[0];
524 // make sure to not use an absolute path, and remove PATH_site if it is prepended
525 if (GeneralUtility::isFirstPartOfStr($folderIdentifier, PATH_site)) {
526 $folderIdentifier = PathUtility::stripPathSitePrefix($parts[0]);
527 }
528 }
529 return $this->getStorageObject($storageUid, [], $folderIdentifier)->getFolder($folderIdentifier);
530 }
531
532 /**
533 * Gets a storage object from a combined identifier
534 *
535 * @param string $identifier An identifier of the form [storage uid]:[object identifier]
536 * @return ResourceStorage
537 */
538 public function getStorageObjectFromCombinedIdentifier($identifier)
539 {
540 $parts = GeneralUtility::trimExplode(':', $identifier);
541 $storageUid = count($parts) === 2 ? $parts[0] : null;
542 return $this->getStorageObject($storageUid);
543 }
544
545 /**
546 * Gets a file or folder object.
547 *
548 * @param string $identifier
549 *
550 * @throws Exception\ResourceDoesNotExistException
551 * @return FileInterface|Folder
552 */
553 public function getObjectFromCombinedIdentifier($identifier)
554 {
555 list($storageId, $objectIdentifier) = GeneralUtility::trimExplode(':', $identifier);
556 $storage = $this->getStorageObject($storageId);
557 if ($storage->hasFile($objectIdentifier)) {
558 return $storage->getFile($objectIdentifier);
559 } elseif ($storage->hasFolder($objectIdentifier)) {
560 return $storage->getFolder($objectIdentifier);
561 } else {
562 throw new Exception\ResourceDoesNotExistException('Object with identifier "' . $identifier . '" does not exist in storage', 1329647780);
563 }
564 }
565
566 /**
567 * Creates a file object from an array of file data. Requires a database
568 * row to be fetched.
569 *
570 * @param array $fileData
571 * @param ResourceStorage $storage
572 * @return File
573 */
574 public function createFileObject(array $fileData, ResourceStorage $storage = null)
575 {
576 /** @var File $fileObject */
577 if (array_key_exists('storage', $fileData) && MathUtility::canBeInterpretedAsInteger($fileData['storage'])) {
578 $storageObject = $this->getStorageObject((int)$fileData['storage']);
579 } elseif ($storage !== null) {
580 $storageObject = $storage;
581 $fileData['storage'] = $storage->getUid();
582 } else {
583 throw new \RuntimeException('A file needs to reside in a Storage', 1381570997);
584 }
585 $fileObject = GeneralUtility::makeInstance(File::class, $fileData, $storageObject);
586 return $fileObject;
587 }
588
589 /**
590 * Creates an instance of a FileReference object. The $fileReferenceData can
591 * be supplied to increase performance.
592 *
593 * @param int $uid The uid of the file usage (sys_file_reference) to instantiate.
594 * @param array $fileReferenceData The record row from database.
595 * @param bool $raw Whether to get raw results without performing overlays
596 * @return FileReference
597 * @throws \InvalidArgumentException
598 * @throws Exception\ResourceDoesNotExistException
599 */
600 public function getFileReferenceObject($uid, array $fileReferenceData = [], $raw = false)
601 {
602 if (!is_numeric($uid)) {
603 throw new \InvalidArgumentException(
604 'The reference UID for the file (sys_file_reference) has to be numeric. UID given: "' . $uid . '"',
605 1300086584
606 );
607 }
608 if (!$this->fileReferenceInstances[$uid]) {
609 // Fetches data in case $fileData is empty
610 if (empty($fileReferenceData)) {
611 $fileReferenceData = $this->getFileReferenceData($uid, $raw);
612 if (!is_array($fileReferenceData)) {
613 throw new Exception\ResourceDoesNotExistException(
614 'No file reference (sys_file_reference) was found for given UID: "' . $uid . '"',
615 1317178794
616 );
617 }
618 }
619 $this->fileReferenceInstances[$uid] = $this->createFileReferenceObject($fileReferenceData);
620 }
621 return $this->fileReferenceInstances[$uid];
622 }
623
624 /**
625 * Creates a file usage object from an array of fileReference data
626 * from sys_file_reference table.
627 * Requires a database row to be already fetched and present.
628 *
629 * @param array $fileReferenceData
630 * @return FileReference
631 */
632 public function createFileReferenceObject(array $fileReferenceData)
633 {
634 /** @var FileReference $fileReferenceObject */
635 $fileReferenceObject = GeneralUtility::makeInstance(FileReference::class, $fileReferenceData);
636 return $fileReferenceObject;
637 }
638
639 /**
640 * Gets data for the given uid of the file reference record.
641 *
642 * @param int $uid The uid of the file usage (sys_file_reference) to be fetched
643 * @param bool $raw Whether to get raw results without performing overlays
644 * @return NULL|array
645 */
646 protected function getFileReferenceData($uid, $raw = false)
647 {
648 if (!$raw && TYPO3_MODE === 'BE') {
649 $fileReferenceData = BackendUtility::getRecordWSOL('sys_file_reference', $uid);
650 } elseif (!$raw && is_object($GLOBALS['TSFE'])) {
651 $fileReferenceData = $GLOBALS['TSFE']->sys_page->checkRecord('sys_file_reference', $uid);
652 } else {
653 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
654 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
655 $fileReferenceData = $queryBuilder->select('*')
656 ->from('sys_file_reference')
657 ->where($queryBuilder->expr()->eq('uid', (int)$uid))
658 ->execute()
659 ->fetch();
660 }
661 return $fileReferenceData;
662 }
663
664 /**
665 * Returns an instance of the FileIndexRepository
666 *
667 * @return FileIndexRepository
668 */
669 protected function getFileIndexRepository()
670 {
671 return FileIndexRepository::getInstance();
672 }
673
674 /**
675 * Returns an instance of the ProcessedFileRepository
676 *
677 * @return ProcessedFileRepository
678 */
679 protected function getProcessedFileRepository()
680 {
681 return GeneralUtility::makeInstance(ProcessedFileRepository::class);
682 }
683
684 /**
685 * Returns an instance of the Indexer
686 *
687 * @param ResourceStorage $storage
688 * @return Index\Indexer
689 */
690 protected function getIndexer(ResourceStorage $storage)
691 {
692 return GeneralUtility::makeInstance(Index\Indexer::class, $storage);
693 }
694
695 /**
696 * @return DatabaseConnection
697 */
698 protected function getDatabaseConnection()
699 {
700 return $GLOBALS['TYPO3_DB'];
701 }
702 }