本文整理汇总了PHP中TYPO3\CMS\Core\Utility\PathUtility::basename方法的典型用法代码示例。如果您正苦于以下问题:PHP PathUtility::basename方法的具体用法?PHP PathUtility::basename怎么用?PHP PathUtility::basename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Utility\PathUtility
的用法示例。
在下文中一共展示了PathUtility::basename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addData
/**
* Initialize new row with default values from various sources
*
* @param array $result
* @return array
* @todo: Should not implode valid values with | again, container & elements should work
* @todo: with the array as it was done for select items
* @throws \UnexpectedValueException
*/
public function addData(array $result)
{
foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
if (empty($fieldConfig['config']['type']) || $fieldConfig['config']['type'] !== 'group' || empty($fieldConfig['config']['internal_type'])) {
continue;
}
$databaseRowFieldContent = '';
if (!empty($result['databaseRow'][$fieldName])) {
$databaseRowFieldContent = (string) $result['databaseRow'][$fieldName];
}
$internalType = $fieldConfig['config']['internal_type'];
if ($internalType === 'file_reference' || $internalType === 'file') {
$files = array();
// Simple list of files
$fileList = GeneralUtility::trimExplode(',', $databaseRowFieldContent, true);
foreach ($fileList as $file) {
if ($file) {
$files[] = rawurlencode($file) . '|' . rawurlencode(PathUtility::basename($file));
}
}
$result['databaseRow'][$fieldName] = implode(',', $files);
} elseif ($internalType === 'db') {
/** @var $relationHandler RelationHandler */
$relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
$relationHandler->start($databaseRowFieldContent, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $result['databaseRow']['uid'], $result['tableName'], $fieldConfig['config']);
$relationHandler->getFromDB();
$result['databaseRow'][$fieldName] = $relationHandler->readyForInterface();
} else {
// @todo: "folder" is a valid internal_type, too.
throw new \UnexpectedValueException('TCA internal_type of field "' . $fieldName . '" in table ' . $result['tableName'] . ' must be set to either "db", "file" or "file_reference"', 1438780511);
}
}
return $result;
}
示例2: prepareLoader
/**
* Get all the complex data for the loader.
* This return value will be cached and stored in the database
* There is no file monitoring for this cache
*
* @param Loader $autoLoader
* @param int $type
*
* @return array
*/
public function prepareLoader(Loader $autoLoader, $type)
{
$languageOverride = [];
if ($type === LoaderInterface::EXT_TABLES) {
return $languageOverride;
}
$languageOverridePath = ExtensionManagementUtility::extPath($autoLoader->getExtensionKey()) . 'Resources/Private/Language/Overrides/';
if (!is_dir($languageOverridePath)) {
return $languageOverride;
}
$files = GeneralUtility::getAllFilesAndFoldersInPath([], $languageOverridePath, 'xlf,php,xml', false, 99);
foreach ($files as $file) {
$file = str_replace($languageOverridePath, '', $file);
$parts = GeneralUtility::trimExplode('/', $file, true);
$extension = GeneralUtility::camelCaseToLowerCaseUnderscored($parts[0]);
unset($parts[0]);
$parts = array_values($parts);
// language
$language = 'default';
$fileParts = GeneralUtility::trimExplode('.', PathUtility::basename($file), true);
if (strlen($fileParts[0]) === 2) {
$language = $fileParts[0];
unset($fileParts[0]);
$parts[sizeof($parts) - 1] = implode('.', $fileParts);
}
$languageOverride[] = ['language' => $language, 'original' => 'EXT:' . $extension . '/' . implode('/', $parts), 'override' => 'EXT:' . $autoLoader->getExtensionKey() . '/Resources/Private/Language/Overrides/' . $file];
}
return $languageOverride;
}
示例3: getRelativePath
/**
* Return a public path pointing to a resource.
*
* @param string $resource
* @return string
*/
public static function getRelativePath($resource)
{
// If file is not found, resolve the path
if (!is_file(PATH_site . $resource)) {
$resource = substr(self::resolvePath($resource), strlen(PATH_site));
}
return PathUtility::getRelativePathTo(PathUtility::dirname(PATH_site . $resource)) . PathUtility::basename($resource);
}
示例4: extractText
/**
* The actual text extraction.
*
* @param FileInterface $file
* @return string
*/
public function extractText(FileInterface $file)
{
$localTempFile = $file->getForLocalProcessing(false);
// extract text
$content = file_get_contents($localTempFile);
// In case of remote storage, the temporary copy of the
// original file in typo3temp must be removed
// Simply compare the filenames, because the filename is so unique that
// it is nearly impossible to have a file with this name in a storage
if (PathUtility::basename($localTempFile) !== $file->getName()) {
unlink($localTempFile);
}
return $content;
}
示例5: getExistingFiles
/**
* Handles the existing files of a Fine Uploader form.
* The values are stored in the GET/POST var at the index "fieldValue".
*
* @return string
*/
public function getExistingFiles()
{
$files = array();
$fieldValue = GeneralUtility::_GP('fieldValue');
if ($fieldValue != '') {
$imagePath = GeneralUtility::getFileAbsFileName($fieldValue);
$imageName = PathUtility::basename($imagePath);
$imageDirectoryPath = PathUtility::dirname($imagePath);
$imageDirectoryPath = PathUtility::getRelativePath(PATH_site, $imageDirectoryPath);
$imageUrl = GeneralUtility::locationHeaderUrl('/' . $imageDirectoryPath . $imageName);
if (file_exists($imagePath)) {
$files[] = array('name' => $imageName, 'uuid' => $imageUrl, 'thumbnailUrl' => $imageUrl);
}
}
return json_encode($files);
}
示例6: getExistingFiles
/**
* Handles the existing files of a Fine Uploader form.
* The values are stored in the GET/POST var at the index "fieldValue".
*
* @return string
*/
public function getExistingFiles()
{
$files = [];
$fieldValue = GeneralUtility::_GP('fieldValue');
if ($fieldValue != '') {
// $imagePath = GeneralUtility::getFileAbsFileName($fieldValue);
$imagePath = str_replace('new:', '', $fieldValue);
$imageName = PathUtility::basename($imagePath);
$imageDirectoryPath = PathUtility::dirname($imagePath);
$imageDirectoryPath = PathUtility::getRelativePath(PATH_site, $imageDirectoryPath);
$imageUrl = GeneralUtility::locationHeaderUrl('/' . $imageDirectoryPath . $imageName);
if (file_exists($imagePath)) {
$files[] = ['name' => $imageName, 'uuid' => $imageUrl, 'thumbnailUrl' => $imageUrl];
}
}
return $files;
}
示例7: getPublicUrl
/**
* @param ResourceStorage $storage
* @param AbstractDriver $driver
* @param ResourceInterface $resource
* @param boolean $relativeToCurrentScript
* @param array $urlData
*/
public function getPublicUrl(ResourceStorage $storage, AbstractDriver $driver, ResourceInterface $resource, $relativeToCurrentScript, array $urlData)
{
if (!$driver instanceof LocalDriver) {
// We cannot handle other files than local files yet
return;
}
$publicUrl = $this->resourcePublisher->getResourceWebUri($resource);
if ($publicUrl !== FALSE) {
// If requested, make the path relative to the current script in order to make it possible
// to use the relative file
if ($relativeToCurrentScript) {
$publicUrl = PathUtility::getRelativePathTo(PathUtility::dirname(PATH_site . $publicUrl)) . PathUtility::basename($publicUrl);
}
// $urlData['publicUrl'] is passed by reference, so we can change that here and the value will be taken into account
$urlData['publicUrl'] = $publicUrl;
}
}
示例8: renderRecord_groupProc
/**
* Processing of the data value in case the field type is "group"
*
* @param string $data The field value
* @param array $fieldConfig TCA field config
* @param array $TSconfig TCEform TSconfig for the record
* @param string $table Table name
* @param array $row The row
* @param string $field Field name
* @return string The processed input field value ($data)
* @access private
* @see renderRecord()
*/
public function renderRecord_groupProc($data, $fieldConfig, $TSconfig, $table, $row, $field)
{
switch ($fieldConfig['config']['internal_type']) {
case 'file_reference':
case 'file':
// Init array used to accumulate the files:
$dataAcc = array();
// Now, load the files into the $dataAcc array, whether stored by MM or as a list of filenames:
if ($fieldConfig['config']['MM']) {
$loadDB = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\RelationHandler::class);
$loadDB->start('', 'files', $fieldConfig['config']['MM'], $row['uid']);
// Setting dummy startup
foreach ($loadDB->itemArray as $value) {
if ($value['id']) {
$dataAcc[] = rawurlencode($value['id']) . '|' . rawurlencode(PathUtility::basename($value['id']));
}
}
} else {
$fileList = GeneralUtility::trimExplode(',', $data, TRUE);
foreach ($fileList as $value) {
if ($value) {
$dataAcc[] = rawurlencode($value) . '|' . rawurlencode(PathUtility::basename($value));
}
}
}
// Implode the accumulation array to a comma separated string:
$data = implode(',', $dataAcc);
break;
case 'db':
$loadDB = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\RelationHandler::class);
/** @var $loadDB \TYPO3\CMS\Core\Database\RelationHandler */
$loadDB->start($data, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $row['uid'], $table, $fieldConfig['config']);
$loadDB->getFromDB();
$data = $loadDB->readyForInterface();
break;
}
return $data;
}
示例9: getShortInfo
/**
* @param string $identifier
* @param string $type
* @return array
*/
protected function getShortInfo($identifier, $type)
{
return ['identifier' => $identifier, 'name' => PathUtility::basename($identifier), 'type' => $type];
}
示例10: export_addFile
/**
* Adds a files content to the export memory
*
* @param array $fI File information with three keys: "filename" = filename without path, "ID_absFile" = absolute filepath to the file (including the filename), "ID" = md5 hash of "ID_absFile". "relFileName" is optional for files attached to records, but mandatory for soft referenced files (since the relFileName determines where such a file should be stored!)
* @param string $recordRef If the file is related to a record, this is the id on the form [table]:[id]. Information purposes only.
* @param string $fieldname If the file is related to a record, this is the field name it was related to. Information purposes only.
* @return void
*/
public function export_addFile($fI, $recordRef = '', $fieldname = '')
{
if (!@is_file($fI['ID_absFile'])) {
$this->error($fI['ID_absFile'] . ' was not a file! Skipping.');
return;
}
if (filesize($fI['ID_absFile']) >= $this->maxFileSize) {
$this->error($fI['ID_absFile'] . ' was larger (' . GeneralUtility::formatSize(filesize($fI['ID_absFile'])) . ') than the maxFileSize (' . GeneralUtility::formatSize($this->maxFileSize) . ')! Skipping.');
return;
}
$fileInfo = stat($fI['ID_absFile']);
$fileRec = array();
$fileRec['filesize'] = $fileInfo['size'];
$fileRec['filename'] = PathUtility::basename($fI['ID_absFile']);
$fileRec['filemtime'] = $fileInfo['mtime'];
//for internal type file_reference
$fileRec['relFileRef'] = PathUtility::stripPathSitePrefix($fI['ID_absFile']);
if ($recordRef) {
$fileRec['record_ref'] = $recordRef . '/' . $fieldname;
}
if ($fI['relFileName']) {
$fileRec['relFileName'] = $fI['relFileName'];
}
// Setting this data in the header
$this->dat['header']['files'][$fI['ID']] = $fileRec;
// ... and for the recordlisting, why not let us know WHICH relations there was...
if ($recordRef && $recordRef !== '_SOFTREF_') {
$refParts = explode(':', $recordRef, 2);
if (!is_array($this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'])) {
$this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'] = array();
}
$this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'][] = $fI['ID'];
}
$fileMd5 = md5_file($fI['ID_absFile']);
if (!$this->saveFilesOutsideExportFile) {
// ... and finally add the heavy stuff:
$fileRec['content'] = GeneralUtility::getUrl($fI['ID_absFile']);
} else {
GeneralUtility::upload_copy_move($fI['ID_absFile'], $this->getTemporaryFilesPathForExport() . $fileMd5);
}
$fileRec['content_md5'] = $fileMd5;
$this->dat['files'][$fI['ID']] = $fileRec;
// For soft references, do further processing:
if ($recordRef === '_SOFTREF_') {
// RTE files?
if ($RTEoriginal = $this->getRTEoriginalFilename(PathUtility::basename($fI['ID_absFile']))) {
$RTEoriginal_absPath = PathUtility::dirname($fI['ID_absFile']) . '/' . $RTEoriginal;
if (@is_file($RTEoriginal_absPath)) {
$RTEoriginal_ID = md5($RTEoriginal_absPath);
$fileInfo = stat($RTEoriginal_absPath);
$fileRec = array();
$fileRec['filesize'] = $fileInfo['size'];
$fileRec['filename'] = PathUtility::basename($RTEoriginal_absPath);
$fileRec['filemtime'] = $fileInfo['mtime'];
$fileRec['record_ref'] = '_RTE_COPY_ID:' . $fI['ID'];
$this->dat['header']['files'][$fI['ID']]['RTE_ORIG_ID'] = $RTEoriginal_ID;
// Setting this data in the header
$this->dat['header']['files'][$RTEoriginal_ID] = $fileRec;
$fileMd5 = md5_file($RTEoriginal_absPath);
if (!$this->saveFilesOutsideExportFile) {
// ... and finally add the heavy stuff:
$fileRec['content'] = GeneralUtility::getUrl($RTEoriginal_absPath);
} else {
GeneralUtility::upload_copy_move($RTEoriginal_absPath, $this->getTemporaryFilesPathForExport() . $fileMd5);
}
$fileRec['content_md5'] = $fileMd5;
$this->dat['files'][$RTEoriginal_ID] = $fileRec;
} else {
$this->error('RTE original file "' . PathUtility::stripPathSitePrefix($RTEoriginal_absPath) . '" was not found!');
}
}
// Files with external media?
// This is only done with files grabbed by a softreference parser since it is deemed improbable that hard-referenced files should undergo this treatment.
$html_fI = pathinfo(PathUtility::basename($fI['ID_absFile']));
if ($this->includeExtFileResources && GeneralUtility::inList($this->extFileResourceExtensions, strtolower($html_fI['extension']))) {
$uniquePrefix = '###' . md5($GLOBALS['EXEC_TIME']) . '###';
if (strtolower($html_fI['extension']) === 'css') {
$prefixedMedias = explode($uniquePrefix, preg_replace('/(url[[:space:]]*\\([[:space:]]*["\']?)([^"\')]*)(["\']?[[:space:]]*\\))/i', '\\1' . $uniquePrefix . '\\2' . $uniquePrefix . '\\3', $fileRec['content']));
} else {
// html, htm:
$htmlParser = GeneralUtility::makeInstance(HtmlParser::class);
$prefixedMedias = explode($uniquePrefix, $htmlParser->prefixResourcePath($uniquePrefix, $fileRec['content'], array(), $uniquePrefix));
}
$htmlResourceCaptured = false;
foreach ($prefixedMedias as $k => $v) {
if ($k % 2) {
$EXTres_absPath = GeneralUtility::resolveBackPath(PathUtility::dirname($fI['ID_absFile']) . '/' . $v);
$EXTres_absPath = GeneralUtility::getFileAbsFileName($EXTres_absPath);
if ($EXTres_absPath && GeneralUtility::isFirstPartOfStr($EXTres_absPath, PATH_site . $this->fileadminFolderName . '/') && @is_file($EXTres_absPath)) {
$htmlResourceCaptured = true;
$EXTres_ID = md5($EXTres_absPath);
$this->dat['header']['files'][$fI['ID']]['EXT_RES_ID'][] = $EXTres_ID;
//.........这里部分代码省略.........
示例11: getRole
/**
* Returns the role of an item (currently only folders; can later be extended for files as well)
*
* @param string $folderIdentifier
* @return string
*/
public function getRole($folderIdentifier)
{
$name = PathUtility::basename($folderIdentifier);
$role = $this->mappingFolderNameToRole[$name];
if (empty($role)) {
$role = FolderInterface::ROLE_DEFAULT;
}
return $role;
}
示例12: getSpecificFileInformation
/**
* Extracts a specific FileInformation from the FileSystems.
*
* @param string $fileIdentifier
* @param string $containerPath
* @param string $property
*
* @return bool|int|string
* @throws \InvalidArgumentException
*/
public function getSpecificFileInformation($fileIdentifier, $containerPath, $property)
{
$baseName = basename($fileIdentifier);
$parts = explode('/', $fileIdentifier);
$identifier = $this->canonicalizeAndCheckFileIdentifier($containerPath . PathUtility::basename($fileIdentifier));
$file = $this->filesystem->getMetadata($fileIdentifier);
switch ($property) {
case 'size':
return $file['size'];
case 'atime':
return $file['timestamp'];
case 'mtime':
return $file['timestamp'];
case 'ctime':
return $file['timestamp'];
case 'name':
return $baseName;
case 'mimetype':
return 'application/octet-stream';
case 'identifier':
return $identifier;
case 'storage':
return $this->storageUid;
case 'identifier_hash':
return $this->hashIdentifier($identifier);
case 'folder_hash':
if (1 < count($parts)) {
return $this->hashIdentifier($this->getParentFolderIdentifierOfIdentifier($identifier));
} elseif (1 === count($parts)) {
return sha1('/');
} else {
return '';
}
default:
throw new \InvalidArgumentException(sprintf('The information "%s" is not available.', $property));
}
}
示例13: addFile
/**
* Moves a file from the local filesystem to this storage.
*
* @param string $localFilePath The file on the server's hard disk to add.
* @param Folder $targetFolder The target path, without the fileName
* @param string $targetFileName The fileName. If not set, the local file name is used.
* @param string $conflictMode possible value are 'cancel', 'replace', 'changeName'
*
* @throws \InvalidArgumentException
* @throws Exception\ExistingTargetFileNameException
* @return FileInterface
*/
public function addFile($localFilePath, Folder $targetFolder, $targetFileName = '', $conflictMode = 'changeName')
{
$localFilePath = PathUtility::getCanonicalPath($localFilePath);
if (!file_exists($localFilePath)) {
throw new \InvalidArgumentException('File "' . $localFilePath . '" does not exist.', 1319552745);
}
$targetFolder = $targetFolder ?: $this->getDefaultFolder();
$targetFileName = $this->driver->sanitizeFileName($targetFileName ?: PathUtility::basename($localFilePath));
$this->assureFileAddPermissions('', $targetFolder, $targetFileName);
// We do not care whether the file exists yet because $targetFileName may be changed by an
// external slot and only then we should check how to proceed according to $conflictMode
$targetFileName = $this->emitPreFileAddSignal($targetFileName, $targetFolder, $localFilePath);
if ($conflictMode === 'cancel' && $this->driver->fileExistsInFolder($targetFileName, $targetFolder->getIdentifier())) {
throw new Exception\ExistingTargetFileNameException('File "' . $targetFileName . '" already exists in folder ' . $targetFolder->getIdentifier(), 1322121068);
} elseif ($conflictMode === 'changeName') {
$targetFileName = $this->getUniqueName($targetFolder, $targetFileName);
}
$fileIdentifier = $this->driver->addFile($localFilePath, $targetFolder->getIdentifier(), $targetFileName);
$file = ResourceFactory::getInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $fileIdentifier);
$this->emitPostFileAddSignal($file, $targetFolder);
return $file;
}
示例14: getFolderInfoByIdentifier
/**
* Returns information about a file.
*
* @param string $folderIdentifier
* @return array
*/
public function getFolderInfoByIdentifier($folderIdentifier)
{
$folderIdentifier = $this->canonicalizeAndCheckFolderIdentifier($folderIdentifier);
$details = $this->adapter->getDetails($this->rootPath . $folderIdentifier);
return ['identifier' => $folderIdentifier, 'name' => PathUtility::basename($folderIdentifier), 'mtime' => $details['mtime'], 'ctime' => $details['ctime'], 'storage' => $this->storageUid];
}
示例15: postFileReplace
/**
* A file is about to be added as a *replacement* of an existing
* one.
*
* @param File $file
* @param string $uploadedFileName
* @return void
*/
public function postFileReplace(File $file, $uploadedFileName)
{
$folder = $file->getParentFolder();
$storageConfiguration = $folder->getStorage()->getConfiguration();
$storageRecord = $folder->getStorage()->getStorageRecord();
if ($storageRecord['driver'] !== 'Local') {
// Unfortunately unsupported yet
return;
}
$targetDirectory = $storageConfiguration['pathType'] === 'relative' ? PATH_site : '';
$targetDirectory .= rtrim(rtrim($storageConfiguration['basePath'], '/') . $folder->getIdentifier(), '/');
$targetFileName = $targetDirectory . '/' . $file->getName();
$this->processFile($targetFileName, PathUtility::basename($targetFileName), $targetDirectory, $file);
$this->populateMetadata($file, $folder);
}