TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Core\Utility\PathUtility Class Reference
Inheritance diagram for TYPO3\CMS\Core\Utility\PathUtility:
TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\WindowsPathUtilityFixture

Static Public Member Functions

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

Static Protected Member Functions

static isWindows ()
 

Detailed Description

Class with helper functions for file paths.

Definition at line 20 of file PathUtility.php.

Member Function Documentation

◆ basename()

◆ dirname()

◆ getAbsolutePathOfRelativeReferencedFileOrPath()

static 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
::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$baseFilenameOrPathThe name of the file or a path that serves as a base; a path will need to have a '/' at the end
string$includeFileNameThe 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\error(), TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\extractIncludes(), TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\getAbsolutePathOfRelativeReferencedFileOrPathResolvesFileCorrectly(), TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\includeDirectory(), and TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\includeFile().

◆ getAbsoluteWebPath()

◆ 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$pathsPaths to be processed
Returns
NULL|string

Definition at line 107 of file PathUtility.php.

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

◆ getRelativePath()

static 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$sourcePathAbsolute source path
string$targetPathAbsolute target path
Returns
NULL|string

Definition at line 70 of file PathUtility.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\fixWindowsFilePath(), and TYPO3\CMS\Core\Utility\GeneralUtility\isAllowedAbsPath().

Referenced by TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\isRelativePathResolvedCorrectly(), TYPO3\CMS\Core\Page\PageRenderer\loadRequireJs(), and TYPO3\CMS\Core\Resource\ResourceFactory\retrieveFileOrFolderObject().

◆ getRelativePathTo()

static 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$targetPathAbsolute target path
Returns
NULL|string

Definition at line 29 of file PathUtility.php.

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

Referenced by TYPO3\CMS\Backend\Sprite\AbstractSpriteHandler\collectTcaSpriteIcons(), TYPO3\CMS\Core\Resource\ResourceStorage\getPublicUrl(), and TYPO3\CMS\Backend\Backend\Avatar\Image\getUrl().

◆ isAbsolutePath()

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

Checks if the $path is absolute or relative (detecting either '/' or 'x:/' as first part of string) and returns TRUE if so.

Parameters
string$pathFile path to evaluate
Returns
bool

Definition at line 223 of file PathUtility.php.

Referenced by TYPO3\CMS\Install\Service\CoreUpdateService\getMessages(), and TYPO3\CMS\Core\Log\Writer\FileWriter\setLogFile().

◆ isWindows()

static TYPO3\CMS\Core\Utility\PathUtility::isWindows ( )
staticprotected

Wrapper method to be able to test windows path transformation on other systems

Returns
bool

Definition at line 364 of file PathUtility.php.

◆ pathinfo()

◆ sanitizeTrailingSeparator()

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

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

Parameters
string$pathThe path to be sanitized
string$separatorThe separator to be used
Returns
string

Definition at line 145 of file PathUtility.php.

Referenced by TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility\createZipFileFromExtension(), TYPO3\CMS\Core\Tests\Unit\Utility\PathUtilityTest\isTrailingSeparatorSanitizedCorrectly(), TYPO3\CMS\Core\Package\PackageManager\registerPackagesFromConfiguration(), and TYPO3\CMS\Core\Package\PackageManager\scanPackagesInPath().

◆ stripPathSitePrefix()

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

Strip first part of a path, equal to the length of PATH_site

Parameters
string$path
Returns
string

Definition at line 342 of file PathUtility.php.

Referenced by TYPO3\CMS\Backend\Form\FormDataProvider\AbstractItemProvider\addItemsFromFolder(), TYPO3\CMS\Backend\Form\FormDataProvider\AbstractItemProvider\addItemsFromSpecial(), TYPO3\CMS\Core\DataHandling\DataHandler\applyFiltersToValues(), TYPO3\CMS\Backend\Module\ModuleLoader\checkExtensionModule(), TYPO3\CMS\Core\DataHandling\DataHandler\copyRecord_flexFormCallBack(), TYPO3\CMS\Core\Database\ReferenceIndex\createEntryData_fileRels(), TYPO3\CMS\Dbal\Database\DatabaseConnection\debugHandler(), TYPO3\CMS\Core\Utility\DebugUtility\debugTrail(), TYPO3\CMS\Core\Resource\Driver\LocalDriver\determineBaseUrl(), TYPO3\CMS\Core\Localization\Parser\LocallangXmlParser\doParsingFromRootForElement(), TYPO3\CMS\Impexp\Export\export_addFile(), TYPO3\CMS\Core\TypoScript\ExtendedTemplateService\ext_getTSCE_config_image(), TYPO3\CMS\Impexp\Export\fixFileIDsInRelations(), TYPO3\CMS\Core\Localization\Parser\LocallangArrayParser\generateCacheFile(), TYPO3\CMS\Core\Localization\Parser\LocallangArrayParser\generateCacheFileName(), TYPO3\CMS\Core\TypoScript\TemplateService\getFileName(), TYPO3\CMS\Core\Resource\ResourceFactory\getFolderObjectFromCombinedIdentifier(), TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getIconHtml(), TYPO3\CMS\Cshmanual\Domain\Repository\TableManualRepository\getImages(), TYPO3\CMS\Extensionmanager\ViewHelpers\ImageViewHelper\getImageUri(), TYPO3\CMS\Core\Utility\GeneralUtility\getIndpEnv(), TYPO3\CMS\Install\Service\CoreUpdateService\getMessages(), TYPO3\CMS\Backend\View\ModuleMenuView\getModuleIconRelative(), TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository\getModuleIconRelative(), TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility\getRelativePath(), TYPO3\CMS\Cshmanual\Domain\Repository\TableManualRepository\getSeeAlsoLinks(), TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem\getShortcutIcon(), TYPO3\CMS\Aboutmodules\Controller\ModulesController\getSubModuleData(), TYPO3\CMS\Core\Utility\GeneralUtility\logDeprecatedFunction(), TYPO3\CMS\Lowlevel\DoubleFilesCommand\main_autoFix(), TYPO3\CMS\IndexedSearch\Controller\SearchFormController\makeItemTypeIcon(), TYPO3\CMS\IndexedSearch\Controller\SearchController\makeRating(), TYPO3\CMS\Impexp\Import\processSoftReferences_saveFile(), TYPO3\CMS\Impexp\Import\processSoftReferences_saveFile_createRelFile(), TYPO3\CMS\Backend\Utility\BackendUtility\referenceCount(), TYPO3\CMS\Rtehtmlarea\Controller\CustomAttributeController\render_clickenlarge(), TYPO3\CMS\Fluid\ViewHelpers\Uri\ResourceViewHelper\renderStatic(), TYPO3\CMS\Core\Utility\ExtensionManagementUtility\siteRelPath(), and TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility\writeEmConfToFile().