‪TYPO3CMS  10.4
TYPO3\CMS\Core\Utility\PathUtility Class Reference

Static Public Member Functions

static string null getRelativePathTo ($targetPath)
 
static string getAbsoluteWebPath ($targetPath)
 
static string null getRelativePath ($sourcePath, $targetPath)
 
static string null getCommonPrefix (array $paths)
 
static string sanitizeTrailingSeparator ($path, $separator='/')
 
static string basename ($path)
 
static string dirname ($path)
 
static string string[] pathinfo ($path, $options=null)
 
static bool isAbsolutePath ($path)
 
static string getAbsolutePathOfRelativeReferencedFileOrPath ($baseFilenameOrPath, $includeFileName)
 
static string dirnameDuringBootstrap ($path)
 
static string basenameDuringBootstrap ($path)
 
static string getCanonicalPath ($path)
 
static string stripPathSitePrefix ($path)
 

Detailed Description

Class with helper functions for file paths.

Definition at line 23 of file PathUtility.php.

Member Function Documentation

◆ basename()

static string TYPO3\CMS\Core\Utility\PathUtility::basename (   $path)
static

Returns trailing name component of path Since basename() is locale dependent we need to access the filesystem with the same locale of the system, not the rendering context.

See also
http://www.php.net/manual/en/function.basename.php
Parameters
string$path
Returns
‪string

Definition at line 165 of file PathUtility.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Resource\Folder\addFile(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\addFile(), TYPO3\CMS\Core\Resource\ResourceStorage\addFile(), TYPO3\CMS\Backend\Utility\BackendUtility\buildScriptUrl(), TYPO3\CMS\Frontend\Imaging\GifBuilder\checkTextObj(), TYPO3\CMS\Backend\Clipboard\Clipboard\confirmMsgText(), TYPO3\CMS\Lowlevel\Command\FilesWithMultipleReferencesCommand\copyMultipleReferencedFiles(), TYPO3\CMS\Impexp\Export\export_addFile(), TYPO3\CMS\Impexp\Export\export_addFilesFromRelations(), TYPO3\CMS\Impexp\Controller\ExportController\exportData(), TYPO3\CMS\Core\Resource\TextExtraction\PlainTextExtractor\extractText(), TYPO3\CMS\Core\Cache\Backend\FileBackend\get(), TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend\get(), TYPO3\CMS\Core\Utility\CommandUtility\getConfiguredApps(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\getFolderInfoByIdentifier(), TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile\getListEntry(), TYPO3\CMS\Core\Localization\Parser\AbstractXmlParser\getLocalizedFileName(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\getRole(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\getSpecificFileInformation(), TYPO3\CMS\Core\Cache\Backend\FileBackend\has(), TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend\has(), TYPO3\CMS\Core\Imaging\GraphicalFunctions\imageMagickConvert(), TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\importExternalTypoScriptFile(), TYPO3\CMS\IndexedSearch\Indexer\indexRegularDocument(), TYPO3\CMS\Impexp\Import\processSoftReferences_saveFile(), TYPO3\CMS\Impexp\Import\processSoftReferences_saveFile_createRelFile(), TYPO3\CMS\IndexedSearch\FileContentParser\readFileContent(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\recycleFileOrFolder(), TYPO3\CMS\Core\Cache\Backend\FileBackend\remove(), TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend\remove(), TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend\requireOnce(), TYPO3\CMS\Core\Cache\Backend\FileBackend\requireOnce(), TYPO3\CMS\Workspaces\Service\AdditionalResourceService\resolvePath(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\retrieveFileAndFoldersInPath(), TYPO3\CMS\Core\Resource\ResourceFactory\retrieveFileOrFolderObject(), TYPO3\CMS\Extensionmanager\Controller\ActionController\sendZipFileToBrowserAndDelete(), TYPO3\CMS\Core\Cache\Backend\FileBackend\set(), TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend\set(), TYPO3\CMS\Frontend\Imaging\GifBuilder\start(), TYPO3\CMS\Belog\ViewHelpers\FormatDetailsViewHelper\stripPathFromFilenames(), and TYPO3\CMS\IndexedSearch\Indexer\submitFilePage().

◆ basenameDuringBootstrap()

static string TYPO3\CMS\Core\Utility\PathUtility::basenameDuringBootstrap (   $path)
static

Returns filename part of a path Early during bootstrap there is no TYPO3_CONF_VARS yet so the setting for the system locale is also unavailable. The filename part is determined with a regular expression to avoid issues with locales.

Parameters
string$path
Returns
‪string

Definition at line 291 of file PathUtility.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\basenameDuringBootstrapCorrectlyFetchesBasename(), and TYPO3\CMS\Install\Updates\BackendLayoutIconUpdateWizard\migrateField().

◆ dirname()

static string TYPO3\CMS\Core\Utility\PathUtility::dirname (   $path)
static

Returns parent directory's path Since dirname() is locale dependent we need to access the filesystem with the same locale of the system, not the rendering context.

See also
http://www.php.net/manual/en/function.dirname.php
Parameters
string$path
Returns
‪string

Definition at line 186 of file PathUtility.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Utility\CommandUtility\checkCommand(), TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorTest\compressCssFileContent(), TYPO3\CMS\Lowlevel\Command\FilesWithMultipleReferencesCommand\copyMultipleReferencedFiles(), TYPO3\CMS\Core\Page\PageRenderer\createInlineCssTagFromFile(), TYPO3\CMS\Core\Log\Writer\FileWriter\createLogFile(), TYPO3\CMS\Core\Resource\ResourceCompressor\cssFixRelativeUrlPaths(), TYPO3\CMS\Impexp\Export\export_addFile(), TYPO3\CMS\Core\Utility\CommandUtility\getConfiguredApps(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\getFileInfoByIdentifier(), TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile\getListEntry(), TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver\getParentFolderIdentifierOfIdentifier(), TYPO3\CMS\Core\Resource\ResourceStorage\getPublicUrl(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\getRecycleDirectory(), TYPO3\CMS\Core\Imaging\GraphicalFunctions\gifCompress(), TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\importExternalTypoScriptFile(), TYPO3\CMS\Backend\Clipboard\Clipboard\linkItemText(), TYPO3\CMS\Frontend\Plugin\AbstractPlugin\pi_loadLL(), TYPO3\CMS\Impexp\Import\processSoftReferences_saveFile(), TYPO3\CMS\Impexp\Import\processSoftReferences_saveFile_createRelFile(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\renameFile(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\renameFolder(), TYPO3\CMS\Workspaces\Service\AdditionalResourceService\resolvePath(), TYPO3\CMS\Core\Resource\ResourceFactory\retrieveFileOrFolderObject(), TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController\set_no_cache(), TYPO3\CMS\Impexp\Import\writeFileVerify(), and TYPO3\CMS\Impexp\Import\writeSysFileRecords().

◆ dirnameDuringBootstrap()

static string TYPO3\CMS\Core\Utility\PathUtility::dirnameDuringBootstrap (   $path)
static

Returns parent directory's path Early during bootstrap there is no TYPO3_CONF_VARS yet so the setting for the system locale is also unavailable. The path of the parent directory is determined with a regular expression to avoid issues with locales.

Parameters
string$path
Returns
‪string Path without trailing slash

Definition at line 276 of file PathUtility.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\dirnameDuringBootstrapCorrectlyFetchesParent(), and TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\getRootPathFromScriptPath().

◆ getAbsolutePathOfRelativeReferencedFileOrPath()

static string TYPO3\CMS\Core\Utility\PathUtility::getAbsolutePathOfRelativeReferencedFileOrPath (   $baseFilenameOrPath,
  $includeFileName 
)
static

Gets the (absolute) path of an include file based on the (absolute) path of a base file

Does NOT do any sanity checks. This is a task for the calling function, e.g. call GeneralUtility::getFileAbsFileName() on the result.

See also
‪\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName()

Resolves all dots and slashes between that paths of both files. Whether the result is absolute or not, depends of the base file name.

If the include file goes higher than a relative base file, then the result will contain dots as a relative part.

  base:    abc/one.txt
  include: ../../two.txt
  result:  ../two.txt

The exact behavior, refer to getCanonicalPath().

Parameters
string$baseFilenameOrPath‪The name of the file or a path that serves as a base; a path will need to have a '/' at the end
string$includeFileName‪The name of the file that is included in the file
Returns
‪string The (absolute) path of the include file

Definition at line 256 of file PathUtility.php.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\addImportsFromExternalFiles(), TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\checkIncludeLines(), TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\getAbsolutePathOfRelativeReferencedFileOrPathResolvesFileCorrectly(), and TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader\getStreamlinedFileName().

◆ getAbsoluteWebPath()

static string TYPO3\CMS\Core\Utility\PathUtility::getAbsoluteWebPath (   $targetPath)
static

Creates an absolute URL out of really any input path, removes '../' parts for the targetPath

Parameters
string$targetPath‪can be "../typo3conf/ext/myext/myfile.js" or "/myfile.js"
Returns
‪string something like "/mysite/typo3conf/ext/myext/myfile.js"

Definition at line 43 of file PathUtility.php.

References TYPO3\CMS\Core\Core\Environment\getCurrentScript(), TYPO3\CMS\Core\Core\Environment\getPublicPath(), TYPO3\CMS\Core\Core\Environment\isCli(), and TYPO3\CMS\Core\Utility\PathUtility\stripPathSitePrefix().

Referenced by TYPO3\CMS\Install\SystemEnvironment\ServerResponse\FileLocation\__construct(), TYPO3\CMS\Backend\Routing\UriBuilder\buildUri(), TYPO3\CMS\IndexedSearch\Controller\SearchController\compileSingleResultRow(), TYPO3\CMS\Core\Page\PageRenderer\computeRequireJsConfig(), TYPO3\CMS\Dashboard\DashboardInitializationService\defineCssFiles(), TYPO3\CMS\Dashboard\DashboardInitializationService\defineJsFiles(), TYPO3\CMS\Core\Controller\ErrorPageController\errorAction(), TYPO3\CMS\Lowlevel\Controller\DatabaseIntegrityController\func_refindex(), TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\generateInlineMarkup(), TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider\generateMarkup(), TYPO3\CMS\Core\Imaging\IconProvider\SvgSpriteIconProvider\generateMarkup(), TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\generateMarkup(), TYPO3\CMS\Backend\Controller\File\ThumbnailController\generateThumbnail(), TYPO3\CMS\Core\Page\AssetRenderer\getAbsoluteWebPath(), TYPO3\CMS\Core\Page\PageRenderer\getAbsoluteWebPath(), TYPO3\CMS\Extensionmanager\Utility\ListUtility\getAvailableExtensions(), TYPO3\CMS\Backend\Template\ModuleTemplate\getBackendFavicon(), TYPO3\CMS\Backend\Template\DocumentTemplate\getBackendFavicon(), TYPO3\CMS\Backend\Controller\EditDocumentController\getCloseUrl(), TYPO3\CMS\Adminpanel\Utility\ResourceUtility\getCssTag(), TYPO3\CMS\Extensionmanager\Controller\ExtensionComposerStatusController\getExtensionIcon(), TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getIconHtml(), TYPO3\CMS\Adminpanel\Utility\ResourceUtility\getJsTag(), TYPO3\CMS\Core\Resource\ResourceStorage\getPublicUrl(), TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController\getRelativePathToStylesheetFile(), TYPO3\CMS\Form\Slot\ResourcePublicationSlot\getStreamUrl(), TYPO3\CMS\Backend\Template\ModuleTemplate\getUriForFileName(), TYPO3\CMS\Backend\Controller\LoginController\getUriForFileName(), TYPO3\CMS\Backend\Template\DocumentTemplate\getUriForFileName(), TYPO3\CMS\Backend\Backend\Avatar\Image\getUrl(), TYPO3\CMS\Seo\XmlSitemap\XmlSitemapRenderer\getXslFilePath(), TYPO3\CMS\Dashboard\Controller\DashboardController\preparePageRenderer(), TYPO3\CMS\Frontend\Http\RequestHandler\processHtmlBasedRenderingSettings(), TYPO3\CMS\Backend\Controller\NewRecordController\renderNewRecordControls(), TYPO3\CMS\Frontend\ContentObject\ScalableVectorGraphicsContentObject\renderObject(), TYPO3\CMS\Reports\ViewHelpers\IconViewHelper\renderStatic(), TYPO3\CMS\Fluid\ViewHelpers\Uri\ResourceViewHelper\renderStatic(), TYPO3\CMS\Backend\Controller\BackendController\renderTopbar(), TYPO3\CMS\Core\Http\Security\ReferrerEnforcer\resolveAbsoluteWebPath(), TYPO3\CMS\Form\Controller\AbstractBackendController\resolveResourcePaths(), and TYPO3\CMS\RteCKEditor\Form\Element\RichTextElement\resolveUrlPath().

◆ getCanonicalPath()

◆ getCommonPrefix()

static string null TYPO3\CMS\Core\Utility\PathUtility::getCommonPrefix ( array  $paths)
static

Gets the common path prefix out of many paths.

  • ‪/var/www/domain.com/typo3/sysext/frontend/
  • ‪/var/www/domain.com/typo3/sysext/em/
  • ‪/var/www/domain.com/typo3/sysext/file/ = /var/www/domain.com/typo3/sysext/
Parameters
array$paths‪Paths to be processed
Returns
‪string|null

Definition at line 110 of file PathUtility.php.

References TYPO3\CMS\Core\Utility\PathUtility\sanitizeTrailingSeparator().

Referenced by TYPO3\CMS\Core\Log\Writer\FileWriter\createLogFile(), TYPO3\CMS\Core\Resource\ResourceFactory\findBestMatchingStorageByLocalPath(), TYPO3\CMS\Core\Utility\PathUtility\getRelativePath(), and TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\isCommonPrefixResolvedCorrectly().

◆ getRelativePath()

static string null TYPO3\CMS\Core\Utility\PathUtility::getRelativePath (   $sourcePath,
  $targetPath 
)
static

Gets the relative path from a source directory to a target directory. The allowed TYPO3 path is checked as well, thus it's not possible to go to upper levels.

Parameters
string$sourcePath‪Absolute source path
string$targetPath‪Absolute target path
Returns
‪string|null

Definition at line 73 of file PathUtility.php.

References TYPO3\CMS\Core\Utility\PathUtility\getCommonPrefix(), and TYPO3\CMS\Core\Utility\PathUtility\sanitizeTrailingSeparator().

Referenced by TYPO3\CMS\Core\Utility\PathUtility\getRelativePathTo(), TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\isRelativePathResolvedCorrectly(), TYPO3\CMS\Core\Resource\ResourceFactory\retrieveFileOrFolderObject(), and TYPO3\CMS\Core\Resource\ResourceCompressor\returnFileReference().

◆ getRelativePathTo()

static string null TYPO3\CMS\Core\Utility\PathUtility::getRelativePathTo (   $targetPath)
static

Gets the relative path from the current used script to a given directory. The allowed TYPO3 path is checked as well, thus it's not possible to go to upper levels.

Parameters
string$targetPath‪Absolute target path
Returns
‪string|null

Definition at line 32 of file PathUtility.php.

References TYPO3\CMS\Core\Core\Environment\getCurrentScript(), and TYPO3\CMS\Core\Utility\PathUtility\getRelativePath().

Referenced by TYPO3\CMS\Core\Resource\ResourceCompressor\getFilenameFromMainDir(), TYPO3\CMS\Core\Resource\ResourceStorage\getPublicUrl(), TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController\getRelativePathToStylesheetFile(), TYPO3\CMS\Core\Page\PageRenderer\getStreamlinedFileName(), and TYPO3\CMS\Workspaces\Service\AdditionalResourceService\resolvePath().

◆ isAbsolutePath()

static bool TYPO3\CMS\Core\Utility\PathUtility::isAbsolutePath (   $path)
static

◆ pathinfo()

◆ sanitizeTrailingSeparator()

static string TYPO3\CMS\Core\Utility\PathUtility::sanitizeTrailingSeparator (   $path,
  $separator = '/' 
)
static

Sanitizes a trailing separator. (e.g. 'some/path' -> 'some/path/')

Parameters
string$path‪The path to be sanitized
string$separator‪The separator to be used
Returns
‪string

Definition at line 148 of file PathUtility.php.

Referenced by TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility\createZipFileFromExtension(), TYPO3\CMS\Core\Utility\PathUtility\getCommonPrefix(), TYPO3\CMS\Core\Utility\PathUtility\getRelativePath(), and TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\isTrailingSeparatorSanitizedCorrectly().

◆ stripPathSitePrefix()

static string TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix (   $path)
static

Strip first part of a path, equal to the length of public web path including trailing slash

Parameters
string$path
Returns
‪string

Definition at line 372 of file PathUtility.php.

References TYPO3\CMS\Core\Core\Environment\getPublicPath().

Referenced by TYPO3\CMS\Frontend\Resource\FilePathSanitizer\__construct(), TYPO3\CMS\Core\Resource\ResourceCompressor\compressCssFile(), TYPO3\CMS\Lowlevel\Command\FilesWithMultipleReferencesCommand\copyMultipleReferencedFiles(), TYPO3\CMS\IndexedSearch\Hook\CrawlerHook\crawler_execute_type2(), TYPO3\CMS\Core\Resource\ResourceCompressor\createMergedFile(), TYPO3\CMS\Core\Utility\DebugUtility\debugTrail(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\determineBaseUrl(), TYPO3\CMS\Core\Localization\Parser\LocallangXmlParser\doParsingFromRootForElement(), TYPO3\CMS\Install\Service\CoreUpdateService\downloadVersion(), TYPO3\CMS\Impexp\Export\export_addFile(), TYPO3\CMS\Impexp\Export\fixFileIDsInRelations(), TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath(), TYPO3\CMS\Install\Service\LanguagePackService\getExtensionLanguagePackDetails(), TYPO3\CMS\Core\Resource\ResourceFactory\getFolderObjectFromCombinedIdentifier(), TYPO3\CMS\Backend\Domain\Repository\TableManualRepository\getImages(), TYPO3\CMS\Extensionmanager\ViewHelpers\DistributionImageViewHelper\getImageUri(), TYPO3\CMS\Backend\Backend\Avatar\Avatar\getImgTag(), TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility\getRelativePath(), TYPO3\CMS\Backend\Domain\Repository\TableManualRepository\getSeeAlsoLinks(), TYPO3\CMS\IndexedSearch\Controller\SearchController\makeItemTypeIcon(), TYPO3\CMS\Impexp\Import\processSoftReferences_saveFile_createRelFile(), TYPO3\CMS\Backend\Utility\BackendUtility\referenceCount(), TYPO3\CMS\Fluid\ViewHelpers\Debug\RenderViewHelper\render(), TYPO3\CMS\Fluid\ViewHelpers\Uri\ResourceViewHelper\renderStatic(), TYPO3\CMS\Frontend\Resource\FilePathSanitizer\sanitize(), TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController\setAbsRefPrefix(), TYPO3\CMS\Install\Service\CoreUpdateService\unpackVersion(), and TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility\writeEmConfToFile().