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