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

Static Public Member Functions

static getRelativePathTo (string $absolutePath)
 
static string getAbsoluteWebPath (string $targetPath, bool $prefixWithSitePath=true)
 
static getPublicResourceWebPath (string $resourcePath, bool $prefixWithSitePath=true)
 
static isExtensionPath (string $path)
 
static getRelativePath (string $sourcePath, string $targetPath)
 
static getCommonPrefix (array $paths)
 
static sanitizeTrailingSeparator (string $path, string $separator='/')
 
static basename (string $path)
 
static dirname (string $path)
 
static string string[] pathinfo (string $path, int $options=PATHINFO_ALL)
 
static isAbsolutePath (string $path)
 
static string getAbsolutePathOfRelativeReferencedFileOrPath (string $baseFilenameOrPath, string $includeFileName)
 
static string dirnameDuringBootstrap (string $path)
 
static basenameDuringBootstrap (string $path)
 
static string getCanonicalPath (string $path)
 
static stripPathSitePrefix (string $path)
 
static hasProtocolAndScheme (string $path)
 
static isAllowedAdditionalPath (string $path)
 

Detailed Description

Class with helper functions for file paths.

Definition at line 26 of file PathUtility.php.

Member Function Documentation

◆ basename()

static TYPO3\CMS\Core\Utility\PathUtility::basename ( string  $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

Definition at line 219 of file PathUtility.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Resource\Folder\addFile(), TYPO3\CMS\Core\Resource\ResourceStorage\addFile(), TYPO3\CMS\Frontend\Imaging\GifBuilder\checkTextObj(), TYPO3\CMS\Backend\Clipboard\Clipboard\confirmMsgText(), TYPO3\CMS\Extensionmanager\Controller\ActionController\downloadExtensionZipAction(), TYPO3\CMS\Impexp\Command\ExportCommand\execute(), TYPO3\CMS\Impexp\Export\exportAddFile(), TYPO3\CMS\Impexp\Export\exportAddFilesFromRelations(), TYPO3\CMS\Core\Resource\TextExtraction\PlainTextExtractor\extractText(), TYPO3\CMS\Core\Cache\Backend\FileBackend\get(), TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend\get(), TYPO3\CMS\Impexp\Controller\ExportController\getDownload(), TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile\getListEntry(), TYPO3\CMS\Core\Localization\Parser\AbstractXmlParser\getLocalizedFileName(), TYPO3\CMS\Core\Cache\Backend\FileBackend\has(), TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend\has(), TYPO3\CMS\Impexp\Import\processSoftReferencesSaveFile(), TYPO3\CMS\Impexp\Import\processSoftReferencesSaveFileCreateRelFile(), TYPO3\CMS\IndexedSearch\FileContentParser\readFileContent(), TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend\remove(), TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend\requireOnce(), TYPO3\CMS\Core\Cache\Backend\FileBackend\requireOnce(), TYPO3\CMS\Core\Resource\ResourceFactory\retrieveFileOrFolderObject(), TYPO3\CMS\Core\Cache\Backend\FileBackend\set(), TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend\set(), TYPO3\CMS\Frontend\Imaging\GifBuilder\start(), and TYPO3\CMS\Belog\ViewHelpers\FormatDetailsViewHelper\stripPathFromFilenames().

◆ basenameDuringBootstrap()

static TYPO3\CMS\Core\Utility\PathUtility::basenameDuringBootstrap ( string  $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.

Definition at line 348 of file PathUtility.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\basenameDuringBootstrapCorrectlyFetchesBasename().

◆ dirname()

◆ dirnameDuringBootstrap()

static string TYPO3\CMS\Core\Utility\PathUtility::dirnameDuringBootstrap ( string  $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.

Returns
‪string Path without trailing slash

Definition at line 337 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 ( string  $baseFilenameOrPath,
string  $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 on 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 319 of file PathUtility.php.

Referenced by 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 ( string  $targetPath,
bool  $prefixWithSitePath = true 
)
static

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

TODO: And this exactly is a big issue as it mixes file system paths with (relative) URLs TODO: Additionally it depends on the current request and can not do its job on CLI TODO: deprecate entirely and replace with stricter API

Until we have a replacement for this API, the safest way to call this method is by providing absolute filesystem paths and use \TYPO3\CMS\Core\Utility\PathUtility::getPublicResourceWebPath whenever possible.

Parameters
string$targetPath‪can be "../typo3conf/ext/myext/myfile.js" or "/myfile.js"
bool$prefixWithSitePath‪Don't use this argument. It is only used by TYPO3 in one place, which are subject to removal.
Returns
‪string something like "/mysite/typo3conf/ext/myext/myfile.js"

Definition at line 52 of file PathUtility.php.

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

Referenced by TYPO3\CMS\Install\SystemEnvironment\ServerResponse\FileLocation\__construct(), TYPO3\CMS\Backend\Controller\Wizard\EditController\__construct(), TYPO3\CMS\Backend\Controller\BackendController\assignTopbarDetailsToView(), TYPO3\CMS\Fluid\ViewHelpers\Link\FileViewHelper\createFileDumpUrl(), TYPO3\CMS\Core\Page\AssetRenderer\getAbsoluteWebPath(), TYPO3\CMS\Core\Page\PageRenderer\getAbsoluteWebPath(), TYPO3\CMS\Extensionmanager\Utility\ListUtility\getAvailableExtensions(), TYPO3\CMS\Install\Service\LanguagePackService\getExtensionLanguagePackDetails(), TYPO3\CMS\Core\Resource\ResourceCompressor\getFilenameFromMainDir(), TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getIconHtml(), TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\getPublicPath(), TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\getPublicPath(), TYPO3\CMS\Core\Utility\PathUtility\getPublicResourceWebPath(), TYPO3\CMS\Core\Resource\ResourceStorage\getPublicUrl(), TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController\getRelativePathToStylesheetFile(), TYPO3\CMS\Form\Slot\ResourcePublicationSlot\getStreamUrl(), TYPO3\CMS\Backend\View\AuthenticationStyleInformation\getUriForFileName(), TYPO3\CMS\Seo\XmlSitemap\XmlSitemapRenderer\getXslFilePath(), TYPO3\CMS\Frontend\Http\RequestHandler\processHtmlBasedRenderingSettings(), TYPO3\CMS\Lowlevel\Controller\DatabaseIntegrityController\referenceIndexAction(), TYPO3\CMS\Backend\Controller\NewRecordController\renderNewRecordControls(), TYPO3\CMS\Frontend\ContentObject\ScalableVectorGraphicsContentObject\renderObject(), and TYPO3\CMS\Core\Page\ImportMap\resolveRecursiveImportMap().

◆ getCanonicalPath()

◆ getCommonPrefix()

static 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<string>‪$paths Paths to be processed

Definition at line 165 of file PathUtility.php.

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

Referenced by TYPO3\CMS\Filelist\Controller\FileDownloadController\collectFiles(), TYPO3\CMS\Core\Log\Writer\FileWriter\createLogFile(), TYPO3\CMS\Core\Utility\PathUtility\getRelativePath(), and TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\isCommonPrefixResolvedCorrectly().

◆ getPublicResourceWebPath()

static TYPO3\CMS\Core\Utility\PathUtility::getPublicResourceWebPath ( string  $resourcePath,
bool  $prefixWithSitePath = true 
)
static

Dedicated method to resolve the path of public extension resources

This method should not be used for now except for TYPO3 core. It may be removed or be changed any time

Parameters
bool$prefixWithSitePath‪Don't use this argument. It is only used by TYPO3 in one place, which is subject to removal.

Definition at line 97 of file PathUtility.php.

References TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath(), and TYPO3\CMS\Core\Core\Environment\getPublicPath().

Referenced by TYPO3\CMS\IndexedSearch\Controller\SearchController\compileSingleResultRow(), TYPO3\CMS\Dashboard\DashboardInitializationService\defineCssFiles(), TYPO3\CMS\Dashboard\DashboardInitializationService\defineJsFiles(), TYPO3\CMS\Backend\Template\PageRendererBackendSetupTrait\getBackendFavicon(), TYPO3\CMS\Backend\Controller\EditDocumentController\getCloseUrl(), TYPO3\CMS\Core\Resource\ResourceCompressor\getFilenameFromMainDir(), TYPO3\CMS\Backend\Backend\Avatar\Avatar\getImage(), TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\getPublicPath(), TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\getPublicPath(), TYPO3\CMS\Core\Tests\UnitDeprecated\Utility\PathUtilityPublicPathsTest\getPublicResourceWebPathResolvesUrlsCorrectly(), TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityPublicPathsTest\getPublicResourceWebPathResolvesUrlsCorrectly(), TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController\getRelativePathToStylesheetFile(), TYPO3\CMS\Core\Page\PageRenderer\getStreamlinedFileName(), TYPO3\CMS\Backend\Template\PageRendererBackendSetupTrait\getUriForFileName(), TYPO3\CMS\Frontend\Resource\FilePathSanitizer\makeRelative(), TYPO3\CMS\Core\ViewHelpers\NormalizedUrlViewHelper\renderStatic(), TYPO3\CMS\Fluid\ViewHelpers\Uri\ResourceViewHelper\renderStatic(), TYPO3\CMS\Core\Http\Security\ReferrerEnforcer\resolveAbsoluteWebPath(), TYPO3\CMS\Core\Page\ImportMap\resolvePaths(), TYPO3\CMS\RteCKEditor\Form\Element\RichTextElement\resolveUrlPath(), TYPO3\CMS\Core\Resource\ResourceFactory\retrieveFileOrFolderObject(), TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityPublicPathsTest\tryingToResolveNonExtensionResourcesThrowsException(), and TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityPublicPathsTest\tryingToResolvePrivateResourcesFromComposerPackagesThrowsException().

◆ getRelativePath()

static TYPO3\CMS\Core\Utility\PathUtility::getRelativePath ( string  $sourcePath,
string  $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

Definition at line 129 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 TYPO3\CMS\Core\Utility\PathUtility::getRelativePathTo ( string  $absolutePath)
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.

Definition at line 33 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\Backend\Controller\AbstractFormEngineAjaxController\getRelativePathToStylesheetFile(), and TYPO3\CMS\Core\Page\PageRenderer\getStreamlinedFileName().

◆ hasProtocolAndScheme()

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

◆ isAbsolutePath()

◆ isAllowedAdditionalPath()

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

Evaluates a given path against the optional settings in ‘$GLOBALS['TYPO3_CONF_VARS’]['BE']['lockRootPath']. Albeit the nameBE/lockRootPath` is misleading, this setting was and is used in general and is not limited to the backend-scope. The setting actually allows defining additional paths, besides the project root path.

Parameters
string$path‪Absolute path to a file or directory

Definition at line 457 of file PathUtility.php.

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

Referenced by TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\allowedAdditionalPathsAreEvaluated().

◆ isExtensionPath()

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

Checks whether the given path is an extension resource

Definition at line 117 of file PathUtility.php.

Referenced by TYPO3\CMS\Form\Mvc\Property\PropertyMappingConfiguration\checkSaveFileMountAccess(), TYPO3\CMS\Impexp\Controller\ImportController\configureImportFromFormDataAndImportIfRequested(), TYPO3\CMS\Dashboard\DashboardInitializationService\defineCssFiles(), TYPO3\CMS\Dashboard\DashboardInitializationService\defineJsFiles(), TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider\generateInlineMarkup(), TYPO3\CMS\Core\Imaging\IconProvider\SvgSpriteIconProvider\generateInlineMarkup(), TYPO3\CMS\Core\Resource\ResourceCompressor\getFilenameFromMainDir(), TYPO3\CMS\Core\Imaging\IconProvider\AbstractSvgIconProvider\getPublicPath(), TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider\getPublicPath(), TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController\getRelativePathToStylesheetFile(), TYPO3\CMS\Core\TypoScript\IncludeTree\TsConfigTreeBuilder\getRootlinePageTsConfigTree(), TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader\getStreamlinedFileName(), TYPO3\CMS\Core\Page\PageRenderer\getStreamlinedFileName(), TYPO3\CMS\Backend\Template\PageRendererBackendSetupTrait\getUriForFileName(), TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder\handleSingleIncludeStaticFile(), TYPO3\CMS\Form\Controller\FormEditorController\indexAction(), TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager\load(), TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager\loadMetaData(), TYPO3\CMS\Core\Localization\LocalizationFactory\localizationOverride(), TYPO3\CMS\Form\SoftReference\FormPersistenceIdentifierSoftReferenceParser\parse(), TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager\pathIsIntendedAsExtensionPath(), TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\renderPageModulePreviewContent(), TYPO3\CMS\RteCKEditor\Form\Element\RichTextElement\replaceAbsolutePathsToRelativeResourcesPath(), TYPO3\CMS\Fluid\ViewHelpers\Uri\ResourceViewHelper\resolveExtensionPath(), TYPO3\CMS\Frontend\Resource\FilePathSanitizer\sanitize(), TYPO3\CMS\Backend\Module\ModuleFactory\sanitizeConfiguration(), TYPO3\CMS\Core\Localization\LanguageStore\setConfiguration(), TYPO3\CMS\Core\Localization\LanguageService\sL(), and TYPO3\CMS\Form\Service\TranslationService\translate().

◆ pathinfo()

◆ sanitizeTrailingSeparator()

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

◆ stripPathSitePrefix()

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

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

Definition at line 428 of file PathUtility.php.

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

Referenced by TYPO3\CMS\Frontend\Resource\FilePathSanitizer\__construct(), TYPO3\CMS\Core\Package\Initialization\ImportExtensionDataOnPackageInitialization\__invoke(), TYPO3\CMS\Core\Package\Initialization\ImportStaticSqlDataOnPackageInitialization\__invoke(), TYPO3\CMS\Impexp\Initialization\ImportContentOnPackageInitialization\__invoke(), TYPO3\CMS\Impexp\ImportExport\addFiles(), TYPO3\CMS\Core\Resource\ResourceCompressor\compressCssFile(), TYPO3\CMS\Core\Resource\ResourceCompressor\createMergedFile(), TYPO3\CMS\Core\Utility\DebugUtility\debugTrail(), TYPO3\CMS\Lowlevel\Command\CleanUpLocalProcessedFilesCommand\deleteFile(), TYPO3\CMS\Install\Service\CoreUpdateService\downloadVersion(), TYPO3\CMS\Lowlevel\Command\CleanUpLocalProcessedFilesCommand\execute(), TYPO3\CMS\Impexp\Export\exportAddFile(), TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath(), TYPO3\CMS\Lowlevel\Service\CleanUpLocalProcessedFilesService\getFilesToClean(), TYPO3\CMS\Core\Resource\ResourceFactory\getFolderObjectFromCombinedIdentifier(), TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility\getRelativePath(), TYPO3\CMS\Frontend\Resource\FilePathSanitizer\makeRelative(), TYPO3\CMS\Impexp\Import\processSoftReferencesSaveFileCreateRelFile(), TYPO3\CMS\Core\Package\PackageActivationService\reloadExtensionData(), TYPO3\CMS\Extensionmanager\ViewHelpers\ReloadSqlDataViewHelper\render(), TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController\setAbsRefPrefix(), and TYPO3\CMS\Install\Service\CoreUpdateService\unpackVersion().