2 namespace TYPO3\CMS\Core\Resource;
86 public function getDriverObject($driverIdentificationString, array $driverConfiguration)
90 $driverClass = $driverRegistry->getDriverClass($driverIdentificationString);
106 public function getDefaultStorage()
111 $allStorages = $storageRepository->findAll();
112 foreach ($allStorages as $storage) {
113 if ($storage->isDefault()) {
130 public function getStorageObject($uid, array $recordData = array(), &$fileIdentifier = null)
132 if (!is_numeric($uid)) {
133 throw new \InvalidArgumentException(
'The UID of storage has to be numeric. UID given: "' . $uid .
'"', 1314085991);
136 if ($uid === 0 && $fileIdentifier !== null) {
139 if (!$this->storageInstances[$uid]) {
140 $storageConfiguration = null;
141 $storageObject = null;
147 'name' =>
'Fallback Storage',
148 'description' =>
'Internal storage, mounting the main TYPO3_site directory.',
150 'processingfolder' =>
'typo3temp/_processed_/',
152 'configuration' =>
'',
154 'is_browsable' =>
true,
156 'is_writable' =>
true,
157 'is_default' =>
false,
159 $storageConfiguration = array(
161 'pathType' =>
'relative'
163 }
elseif (count($recordData) === 0 || (
int)$recordData[
'uid'] !== $uid) {
167 $storageObject = $storageRepository->findByUid($uid);
169 if (!$storageObject instanceof ResourceStorage) {
173 $this->storageInstances[$uid] = $storageObject;
175 return $this->storageInstances[$uid];
185 $this->signalSlotDispatcher->dispatch(\TYPO3\CMS\Core\Resource\ResourceFactory::class, self::SIGNAL_PostProcessStorage, array($this, $storageObject));
200 if ($this->localDriverStorageCache === null) {
201 $this->initializeLocalStorageCache();
204 $bestMatchStorageUid = 0;
205 $bestMatchLength = 0;
206 foreach ($this->localDriverStorageCache as $storageUid => $basePath) {
208 $basePathLength = strlen($basePath);
210 if ($matchLength >= $basePathLength && $matchLength > $bestMatchLength) {
211 $bestMatchStorageUid = (int)$storageUid;
212 $bestMatchLength = $matchLength;
215 if ($bestMatchStorageUid !== 0) {
216 $localPath = substr($localPath, $bestMatchLength);
218 return $bestMatchStorageUid;
226 protected function initializeLocalStorageCache()
231 $storageObjects = $storageRepository->findByStorageType(
'Local');
233 $storageCache = array();
234 foreach ($storageObjects as $localStorage) {
235 $configuration = $localStorage->getConfiguration();
236 $storageCache[$localStorage->getUid()] = $configuration[
'basePath'];
238 $this->localDriverStorageCache = $storageCache;
249 $configuration = array();
252 if (!empty($flexFormContents[
'data'][
'sDEF'][
'lDEF']) && is_array($flexFormContents[
'data'][
'sDEF'][
'lDEF'])) {
253 foreach ($flexFormContents[
'data'][
'sDEF'][
'lDEF'] as $key => $value) {
254 if (isset($value[
'vDEF'])) {
255 $configuration[$key] = $value[
'vDEF'];
260 return $configuration;
272 public function getCollectionObject($uid, array $recordData = array())
274 if (!is_numeric($uid)) {
275 throw new \InvalidArgumentException(
'The UID of collection has to be numeric. UID given: "' . $uid .
'"', 1314085999);
277 if (!$this->collectionInstances[$uid]) {
279 if (empty($recordData) || $recordData[
'uid'] !== $uid) {
281 $recordData =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetSingleRow(
'*',
'sys_file_collection',
'uid=' . (
int)$uid .
' AND deleted=0');
282 if (!is_array($recordData)) {
283 throw new \InvalidArgumentException(
'No collection found for given UID: "' . $uid .
'"', 1314085992);
286 $collectionObject = $this->createCollectionObject($recordData);
287 $this->collectionInstances[$uid] = $collectionObject;
289 return $this->collectionInstances[$uid];
298 public function createCollectionObject(array $collectionData)
301 $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Collection\FileCollectionRegistry::class);
302 $class =
$registry->getFileCollectionClass($collectionData[
'type']);
304 return $class::create($collectionData);
316 $className = \TYPO3\CMS\Core\Resource\ResourceStorage::class;
317 if (!$storageConfiguration) {
320 $driverType = $storageRecord[
'driver'];
321 $driverObject = $this->getDriverObject($driverType, $storageConfiguration);
351 if (!is_numeric($uid)) {
352 throw new \InvalidArgumentException(
'The UID of file has to be numeric. UID given: "' . $uid .
'"', 1300096564);
354 if (!$this->fileInstances[$uid]) {
356 if (empty($fileData)) {
358 if ($fileData ===
false) {
359 throw new \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException(
'No file found for given UID:' . $uid, 1317178604);
362 $this->fileInstances[$uid] = $this->createFileObject($fileData);
364 return $this->fileInstances[$uid];
376 if (!isset($identifier) || !is_string($identifier) || $identifier ===
'') {
377 throw new \InvalidArgumentException(
'Invalid file identifier given. It must be of type string and not empty. "' . gettype($identifier) .
'" given.', 1401732564);
380 if (count($parts) === 2) {
381 $storageUid = $parts[0];
382 $fileIdentifier = $parts[1];
387 $fileIdentifier = $parts[0];
406 $storage = $this->getStorageObject($storageUid, array(), $fileIdentifier);
407 if (!$storage->isWithinProcessingFolder($fileIdentifier)) {
408 $fileData = $this->
getFileIndexRepository()->findOneByStorageUidAndIdentifier($storage->getUid(), $fileIdentifier);
409 if ($fileData ===
false) {
410 $fileObject = $this->
getIndexer($storage)->createIndexEntry($fileIdentifier);
412 $fileObject = $this->
getFileObject($fileData[
'uid'], $fileData);
445 $input = str_replace(PATH_site,
'', $input);
448 $input = substr($input, 5);
452 }
elseif (strpos($input,
':') > 0) {
453 list($prefix, $folderIdentifier) = explode(
':', $input);
457 }
elseif ($prefix ==
'EXT') {
471 $input = \TYPO3\CMS\Core\Utility\PathUtility::getCanonicalPath(ltrim($input,
'/'));
472 if (@is_file(PATH_site . $input)) {
492 if (count($parts) === 2) {
493 $storageUid = $parts[0];
494 $folderIdentifier = $parts[1];
502 $folderIdentifier = $parts[0];
505 $folderIdentifier = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($parts[0]);
508 return $this->getStorageObject($storageUid, array(), $folderIdentifier)->getFolder($folderIdentifier);
520 $storageUid = count($parts) === 2 ? $parts[0] : null;
521 return $this->getStorageObject($storageUid);
535 $storage = $this->getStorageObject($storageId);
536 if ($storage->hasFile($objectIdentifier)) {
537 return $storage->getFile($objectIdentifier);
538 }
elseif ($storage->hasFolder($objectIdentifier)) {
539 return $storage->getFolder($objectIdentifier);
541 throw new \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException(
'Object with identifier "' . $identifier .
'" does not exist in storage', 1329647780);
553 public function createFileObject(array $fileData,
ResourceStorage $storage = null)
557 $storageObject = $this->getStorageObject((
int)$fileData[
'storage']);
558 }
elseif ($storage !== null) {
559 $storageObject = $storage;
560 $fileData[
'storage'] = $storage->getUid();
562 throw new \RuntimeException(
'A file needs to reside in a Storage', 1381570997);
581 if (!is_numeric($uid)) {
582 throw new \InvalidArgumentException(
583 'The reference UID for the file (sys_file_reference) has to be numeric. UID given: "' . $uid .
'"',
587 if (!$this->fileReferenceInstances[$uid]) {
589 if (empty($fileReferenceData)) {
590 $fileReferenceData = $this->getFileReferenceData($uid, $raw);
591 if (!is_array($fileReferenceData)) {
592 throw new \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException(
593 'No file reference (sys_file_reference) was found for given UID: "' . $uid .
'"',
598 $this->fileReferenceInstances[$uid] = $this->createFileReferenceObject($fileReferenceData);
600 return $this->fileReferenceInstances[$uid];
611 public function createFileReferenceObject(array $fileReferenceData)
615 return $fileReferenceObject;
625 protected function getFileReferenceData($uid, $raw =
false)
627 if (!$raw && TYPO3_MODE ===
'BE') {
628 $fileReferenceData = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL(
'sys_file_reference', $uid);
630 $fileReferenceData =
$GLOBALS[
'TSFE']->sys_page->checkRecord(
'sys_file_reference', $uid);
633 $fileReferenceData =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetSingleRow(
'*',
'sys_file_reference',
'uid=' . (
int)$uid .
' AND deleted=0');
635 return $fileReferenceData;