41 return GeneralUtility::makeInstance(__CLASS__);
69 protected $localDriverStorageCache;
94 public function getDriverObject($driverIdentificationString, array $driverConfiguration)
97 $driverRegistry = GeneralUtility::makeInstance(Driver\DriverRegistry::class);
98 $driverClass = $driverRegistry->getDriverClass($driverIdentificationString);
99 $driverObject = GeneralUtility::makeInstance($driverClass, $driverConfiguration);
100 return $driverObject;
116 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
118 $allStorages = $storageRepository->findAll();
119 foreach ($allStorages as $storage) {
120 if ($storage->isDefault()) {
137 public function getStorageObject($uid, array $recordData = [], &$fileIdentifier =
null)
139 if (!is_numeric($uid)) {
140 throw new \InvalidArgumentException(
'The UID of storage has to be numeric. UID given: "' . $uid .
'"', 1314085991);
143 if ($uid === 0 && $fileIdentifier !==
null) {
146 if (empty($this->storageInstances[$uid])) {
147 $storageConfiguration =
null;
154 'name' =>
'Fallback Storage',
155 'description' =>
'Internal storage, mounting the main TYPO3_site directory.',
157 'processingfolder' =>
'typo3temp/assets/_processed_/',
159 'configuration' =>
'',
161 'is_browsable' =>
true,
163 'is_writable' =>
true,
164 'is_default' =>
false,
166 $storageConfiguration = [
168 'pathType' =>
'relative'
170 } elseif ($recordData === [] || (
int)$recordData[
'uid'] !== $uid) {
172 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
173 $recordData = $storageRepository->fetchRowByUid($uid);
177 $this->storageInstances[$uid] = $storageObject;
179 return $this->storageInstances[$uid];
192 return $this->
signalSlotDispatcher->dispatch(\
TYPO3\CMS\Core\Resource\ResourceFactory::class, self::SIGNAL_PreProcessStorage, [$this, $uid, $recordData, $fileIdentifier]);
202 $this->
signalSlotDispatcher->dispatch(self::class, self::SIGNAL_PostProcessStorage, [$this, $storageObject]);
217 if ($this->localDriverStorageCache ===
null) {
223 if ($localPath[0] !==
'/') {
224 $localPath =
'/' . $localPath;
226 $bestMatchStorageUid = 0;
227 $bestMatchLength = 0;
228 foreach ($this->localDriverStorageCache as $storageUid => $basePath) {
230 if ($basePath->getRelative() !==
null
233 $matchLength = strlen($commonPrefix);
234 $basePathLength = strlen($basePath->getRelative());
235 if ($matchLength >= $basePathLength && $matchLength > $bestMatchLength) {
236 $bestMatchStorageUid = $storageUid;
237 $bestMatchLength = $matchLength;
242 $matchLength = strlen($commonPrefix);
243 $basePathLength = strlen($basePath->getAbsolute());
244 if ($matchLength >= $basePathLength && $matchLength > $bestMatchLength) {
245 $bestMatchStorageUid = $storageUid;
246 $bestMatchLength = $matchLength;
250 if ($bestMatchLength > 0) {
253 $localPath = substr($localPath, $bestMatchLength - 1);
255 return $bestMatchStorageUid;
264 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
266 $storageObjects = $storageRepository->findByStorageType(
'Local');
268 $this->localDriverStorageCache = [
272 foreach ($storageObjects as $localStorage) {
273 $configuration = $localStorage->getConfiguration();
274 if (!isset($configuration[
'basePath']) || !isset($configuration[
'pathType'])) {
277 if ($configuration[
'pathType'] ===
'relative') {
279 } elseif ($configuration[
'pathType'] ===
'absolute') {
284 $this->localDriverStorageCache[$localStorage->getUid()] = GeneralUtility::makeInstance(
286 $configuration[
'basePath'],
302 $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
303 $configuration = $flexFormService->convertFlexFormContentToArray($flexFormData);
305 return $configuration;
319 if (!is_numeric($uid)) {
320 throw new \InvalidArgumentException(
'The UID of collection has to be numeric. UID given: "' . $uid .
'"', 1314085999);
322 if (!$this->collectionInstances[$uid]) {
324 if (empty($recordData) || $recordData[
'uid'] !== $uid) {
325 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'sys_file_collection');
326 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
327 $recordData = $queryBuilder->select(
'*')
328 ->from(
'sys_file_collection')
330 $queryBuilder->expr()->eq(
332 $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
337 if (empty($recordData)) {
338 throw new \InvalidArgumentException(
'No collection found for given UID: "' . $uid .
'"', 1314085992);
342 $this->collectionInstances[$uid] = $collectionObject;
344 return $this->collectionInstances[$uid];
356 $registry = GeneralUtility::makeInstance(Collection\FileCollectionRegistry::class);
359 $class = $registry->getFileCollectionClass($collectionData[
'type']);
361 return $class::create($collectionData);
373 if (!$storageConfiguration) {
376 $driverType = $storageRecord[
'driver'];
377 $driverObject = $this->
getDriverObject($driverType, $storageConfiguration);
378 return GeneralUtility::makeInstance(ResourceStorage::class, $driverObject, $storageRecord);
391 return GeneralUtility::makeInstance(Folder::class, $storage, $identifier, $name);
407 if (!is_numeric($uid)) {
408 throw new \InvalidArgumentException(
'The UID of file has to be numeric. UID given: "' . $uid .
'"', 1300096564);
410 if (empty($this->fileInstances[$uid])) {
412 if (empty($fileData)) {
414 if ($fileData ===
false) {
415 throw new Exception\FileDoesNotExistException(
'No file found for given UID: ' . $uid, 1317178604);
420 return $this->fileInstances[$uid];
432 if (!isset($identifier) || !is_string($identifier) || $identifier ===
'') {
433 throw new \InvalidArgumentException(
'Invalid file identifier given. It must be of type string and not empty. "' . gettype($identifier) .
'" given.', 1401732564);
435 $parts = GeneralUtility::trimExplode(
':', $identifier);
436 if (count($parts) === 2) {
437 $storageUid = $parts[0];
438 $fileIdentifier = $parts[1];
443 $fileIdentifier = $parts[0];
463 if (!$storage->isWithinProcessingFolder($fileIdentifier)) {
465 if ($fileData ===
false) {
466 $fileObject = $this->
getIndexer($storage)->createIndexEntry($fileIdentifier);
503 if (GeneralUtility::isFirstPartOfStr($input,
'file:')) {
504 $input = substr($input, 5);
510 if (strpos($input,
':') > 0) {
511 list($prefix) = explode(
':', $input);
516 if ($prefix ===
'EXT') {
517 $input = GeneralUtility::getFileAbsFileName($input);
547 $parts = GeneralUtility::trimExplode(
':', $identifier);
548 if (count($parts) === 2) {
549 $storageUid = $parts[0];
550 $folderIdentifier = $parts[1];
558 $folderIdentifier = $parts[0];
575 $parts = GeneralUtility::trimExplode(
':', $identifier);
576 $storageUid = count($parts) === 2 ? $parts[0] :
null;
590 list($storageId, $objectIdentifier) = GeneralUtility::trimExplode(
':', $identifier);
592 if ($storage->hasFile($objectIdentifier)) {
593 return $storage->getFile($objectIdentifier);
595 if ($storage->hasFolder($objectIdentifier)) {
596 return $storage->getFolder($objectIdentifier);
598 throw new Exception\ResourceDoesNotExistException(
'Object with identifier "' . $identifier .
'" does not exist in storage', 1329647780);
609 public function createFileObject(array $fileData, ResourceStorage $storage =
null)
614 } elseif ($storage !==
null) {
615 $storageObject = $storage;
616 $fileData[
'storage'] = $storage->getUid();
618 throw new \RuntimeException(
'A file needs to reside in a Storage', 1381570997);
620 $fileObject = GeneralUtility::makeInstance(File::class, $fileData, $storageObject);
637 if (!is_numeric($uid)) {
638 throw new \InvalidArgumentException(
639 'The reference UID for the file (sys_file_reference) has to be numeric. UID given: "' . $uid .
'"',
643 if (!$this->fileReferenceInstances[$uid]) {
645 if (empty($fileReferenceData)) {
647 if (!is_array($fileReferenceData)) {
648 throw new Exception\ResourceDoesNotExistException(
649 'No file reference (sys_file_reference) was found for given UID: "' . $uid .
'"',
656 return $this->fileReferenceInstances[$uid];
670 $fileReferenceObject = GeneralUtility::makeInstance(FileReference::class, $fileReferenceData);
671 return $fileReferenceObject;
683 if (!$raw && TYPO3_MODE ===
'BE') {
685 } elseif (!$raw && is_object(
$GLOBALS[
'TSFE'])) {
686 $fileReferenceData =
$GLOBALS[
'TSFE']->sys_page->checkRecord(
'sys_file_reference', $uid);
688 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'sys_file_reference');
689 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
690 $fileReferenceData = $queryBuilder->select(
'*')
691 ->from(
'sys_file_reference')
693 $queryBuilder->expr()->eq(
695 $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
701 return $fileReferenceData;
721 return GeneralUtility::makeInstance(ProcessedFileRepository::class);
732 return GeneralUtility::makeInstance(Index\Indexer::class, $storage);