86 public function getDriverObject($driverIdentificationString, array $driverConfiguration) {
89 $driverClass = $driverRegistry->getDriverClass($driverIdentificationString);
105 public function getDefaultStorage() {
109 $allStorages = $storageRepository->findAll();
110 foreach ($allStorages as $storage) {
111 if ($storage->isDefault()) {
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);
133 if (
$uid === 0 && $fileIdentifier !== NULL) {
136 if (!$this->storageInstances[
$uid]) {
137 $storageConfiguration = NULL;
138 $storageObject = NULL;
144 'name' =>
'Fallback Storage',
145 'description' =>
'Internal storage, mounting the main TYPO3_site directory.',
147 'processingfolder' =>
'typo3temp/_processed_/',
149 'configuration' =>
'',
151 'is_browsable' => TRUE,
153 'is_writable' => TRUE,
154 'is_default' => FALSE,
156 $storageConfiguration = array(
158 'pathType' =>
'relative' 160 } elseif (count($recordData) === 0 || (
int)$recordData[
'uid'] !== $uid) {
164 $storageObject = $storageRepository->findByUid($uid);
170 $this->storageInstances[
$uid] = $storageObject;
172 return $this->storageInstances[
$uid];
181 $this->signalSlotDispatcher->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceFactory', self::SIGNAL_PostProcessStorage, array($this, $storageObject));
195 if ($this->localDriverStorageCache === NULL) {
196 $this->initializeLocalStorageCache();
199 $bestMatchStorageUid = 0;
200 $bestMatchLength = 0;
201 foreach ($this->localDriverStorageCache as $storageUid => $basePath) {
203 $basePathLength = strlen($basePath);
205 if ($matchLength >= $basePathLength && $matchLength > $bestMatchLength) {
206 $bestMatchStorageUid = (int)$storageUid;
207 $bestMatchLength = $matchLength;
210 if ($bestMatchStorageUid !== 0) {
211 $localPath = substr($localPath, $bestMatchLength);
213 return $bestMatchStorageUid;
221 protected function initializeLocalStorageCache() {
225 $storageObjects = $storageRepository->findByStorageType(
'Local');
227 $storageCache = array();
228 foreach ($storageObjects as $localStorage) {
229 $configuration = $localStorage->getConfiguration();
230 $storageCache[$localStorage->getUid()] = $configuration[
'basePath'];
232 $this->localDriverStorageCache = $storageCache;
242 $configuration = array();
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'];
253 return $configuration;
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);
269 if (!$this->collectionInstances[
$uid]) {
271 if (count($recordData) === 0 || $recordData[
'uid'] !== $uid) {
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);
278 $collectionObject = $this->createCollectionObject($recordData);
279 $this->collectionInstances[
$uid] = $collectionObject;
281 return $this->collectionInstances[
$uid];
290 public function createCollectionObject(array $collectionData) {
293 $class =
$registry->getFileCollectionClass($collectionData[
'type']);
295 return $class::create($collectionData);
306 $className =
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage';
307 if (!$storageConfiguration) {
310 $driverType = $storageRecord[
'driver'];
311 $driverObject = $this->getDriverObject($driverType, $storageConfiguration);
339 if (!is_numeric(
$uid)) {
340 throw new \InvalidArgumentException(
'uid of file has to be numeric.', 1300096564);
342 if (!$this->fileInstances[
$uid]) {
344 if (empty($fileData)) {
346 if ($fileData === FALSE) {
347 throw new \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException(
'No file found for given UID.', 1317178604);
350 $this->fileInstances[
$uid] = $this->createFileObject($fileData);
352 return $this->fileInstances[
$uid];
363 if (!isset($identifier) || !is_string($identifier) || $identifier ===
'') {
364 throw new \InvalidArgumentException(
'Invalid file identifier given. It must be of type string and not empty. "' . gettype($identifier) .
'" given.', 1401732564);
367 if (count($parts) === 2) {
368 $storageUid = $parts[0];
369 $fileIdentifier = $parts[1];
374 $fileIdentifier = $parts[0];
392 $storage = $this->getStorageObject($storageUid, array(), $fileIdentifier);
393 if (!$storage->isWithinProcessingFolder($fileIdentifier)) {
394 $fileData = $this->
getFileIndexRepository()->findOneByStorageUidAndIdentifier($storage->getUid(), $fileIdentifier);
395 if ($fileData === FALSE) {
396 $fileObject = $this->
getIndexer($storage)->createIndexEntry($fileIdentifier);
398 $fileObject = $this->
getFileObject($fileData[
'uid'], $fileData);
430 $input = str_replace(PATH_site,
'', $input);
433 $input = substr($input, 5);
437 } elseif (strpos($input,
':') > 0) {
438 list($prefix, $folderIdentifier) = explode(
':', $input);
442 } elseif ($prefix ==
'EXT') {
456 if (@is_file(PATH_site . $input)) {
475 if (count($parts) === 2) {
476 $storageUid = $parts[0];
477 $folderIdentifier = $parts[1];
485 $folderIdentifier = $parts[0];
491 return $this->getStorageObject($storageUid, array(), $folderIdentifier)->getFolder($folderIdentifier);
502 $storageUid = count($parts) === 2 ? $parts[0] : NULL;
503 return $this->getStorageObject($storageUid);
516 $storage = $this->getStorageObject($storageId);
517 if ($storage->hasFile($objectIdentifier)) {
518 return $storage->getFile($objectIdentifier);
519 } elseif ($storage->hasFolder($objectIdentifier)) {
520 return $storage->getFolder($objectIdentifier);
522 throw new \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException(
'Object with identifier "' . $identifier .
'" does not exist in storage', 1329647780);
534 public function createFileObject(array $fileData,
ResourceStorage $storage = NULL) {
537 $storageObject = $this->getStorageObject((
int)$fileData[
'storage']);
538 } elseif ($storage !== NULL) {
539 $storageObject = $storage;
540 $fileData[
'storage'] = $storage->getUid();
542 throw new \RuntimeException(
'A file needs to reside in a Storage', 1381570997);
560 if (!is_numeric(
$uid)) {
561 throw new \InvalidArgumentException(
'uid of file usage (sys_file_reference) has to be numeric.', 1300086584);
563 if (!$this->fileReferenceInstances[
$uid]) {
565 if (empty($fileReferenceData)) {
566 $fileReferenceData = $this->getFileReferenceData($uid, $raw);
567 if (!is_array($fileReferenceData)) {
568 throw new \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException(
'No file usage (sys_file_reference) found for given UID.', 1317178794);
571 $this->fileReferenceInstances[
$uid] = $this->createFileReferenceObject($fileReferenceData);
573 return $this->fileReferenceInstances[
$uid];
584 public function createFileReferenceObject(array $fileReferenceData) {
587 return $fileReferenceObject;
597 protected function getFileReferenceData(
$uid, $raw = FALSE) {
600 } elseif (!$raw && is_object(
$GLOBALS[
'TSFE'])) {
601 $fileReferenceData =
$GLOBALS[
'TSFE']->sys_page->checkRecord(
'sys_file_reference',
$uid);
604 $fileReferenceData =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetSingleRow(
'*',
'sys_file_reference',
'uid=' . (
int)
$uid .
' AND deleted=0');
606 return $fileReferenceData;
getStorageObjectFromCombinedIdentifier($identifier)
findBestMatchingStorageByLocalPath(&$localPath)
getProcessedFileRepository()
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=TRUE, $unsetMovePointers=FALSE)
getFileObject($uid, array $fileData=array())
static getCanonicalPath($path)
static getCommonPrefix(array $paths)
createFolderObject(ResourceStorage $storage, $identifier, $name)
static isFirstPartOfStr($str, $partStr)
static canBeInterpretedAsInteger($var)
createStorageObject(array $storageRecord, array $storageConfiguration=NULL)
static makeInstance($className)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
convertFlexFormDataToConfigurationArray($flexFormData)
getObjectFromCombinedIdentifier($identifier)
__construct(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher=NULL)
getIndexer(ResourceStorage $storage)
getFolderObjectFromCombinedIdentifier($identifier)
getFileReferenceObject($uid, array $fileReferenceData=array(), $raw=FALSE)
static getRelativePath($sourcePath, $targetPath)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
emitPostProcessStorageSignal(ResourceStorage $storageObject)
getFileObjectByStorageAndIdentifier($storageUid, &$fileIdentifier)
static xml2array($string, $NSprefix='', $reportDocTag=FALSE)
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)
static stripPathSitePrefix($path)
retrieveFileOrFolderObject($input)
getFileObjectFromCombinedIdentifier($identifier)