TYPO3 CMS  TYPO3_6-2
TYPO3\CMS\Core\Utility\PathUtility Class Reference
Inheritance diagram for TYPO3\CMS\Core\Utility\PathUtility:
t3lib_utility_Path

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

This file is part of the TYPO3 CMS project.

It is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, either version 2 of the License, or any later version.

For the full copyright and license information, please read the LICENSE.txt file that was distributed with this source code.

The TYPO3 project - inspiring people to share! Class with helper functions for file paths.

Author
Oliver Hader olive.nosp@m.r.ha.nosp@m.der@t.nosp@m.ypo3.nosp@m..org

Definition at line 22 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 250 of file PathUtility.php.

References $result.

Referenced by TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\checkIncludeLines(), 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()

static 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$targetPathcan be "../typo3conf/ext/myext/myfile.js" or "/myfile.js"
Returns
string something like "/mysite/typo3conf/ext/myext/myfile.js"

Definition at line 41 of file PathUtility.php.

References TYPO3\CMS\Core\Utility\PathUtility\dirname(), TYPO3\CMS\Core\Utility\GeneralUtility\getIndpEnv(), and TYPO3\CMS\Core\Utility\GeneralUtility\resolveBackPath().

Referenced by TYPO3\CMS\Frontend\Page\PageGenerator\renderContent().

◆ getCanonicalPath()

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

◆ 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/cms/
  • /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 71 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 31 of file PathUtility.php.

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

Referenced by TYPO3\CMS\Core\Resource\ResourceStorage\getPublicUrl().

◆ 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
boolean

Definition at line 218 of file PathUtility.php.

Referenced by TYPO3\CMS\Install\Service\CoreUpdateService\getMessages(), TYPO3\CMS\Core\Cache\Backend\ClassLoaderBackend\setLinkToPhpFile(), 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 356 of file PathUtility.php.

◆ pathinfo()

static TYPO3\CMS\Core\Utility\PathUtility::pathinfo (   $path,
  $options = NULL 
)
static

◆ 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 144 of file PathUtility.php.

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

◆ 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 335 of file PathUtility.php.

Referenced by TYPO3\CMS\Core\DataHandling\DataHandler\applyFiltersToValues(), TYPO3\CMS\Core\DataHandling\DataHandler\copyRecord_fixRTEmagicImages(), 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\Impexp\ImportExport\export_addFile(), TYPO3\CMS\Core\TypoScript\ExtendedTemplateService\ext_getTSCE_config_image(), TYPO3\CMS\Impexp\ImportExport\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\Extensionmanager\ViewHelpers\ImageViewHelper\getImageUri(), TYPO3\CMS\Core\Utility\GeneralUtility\getIndpEnv(), TYPO3\CMS\Install\Service\CoreUpdateService\getMessages(), TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility\getRelativePath(), TYPO3\CMS\Backend\Toolbar\ShortcutToolbarItem\getShortcutIcon(), TYPO3\CMS\Aboutmodules\Controller\ModulesController\getSubModuleData(), TYPO3\CMS\Recordlist\Browser\ElementBrowser\initCurrentUrl(), TYPO3\CMS\Core\Utility\GeneralUtility\logDeprecatedFunction(), TYPO3\CMS\Backend\Controller\NoDocumentsOpenController\main(), TYPO3\CMS\Lowlevel\DoubleFilesCommand\main_autoFix(), TYPO3\CMS\Cshmanual\Controller\HelpModuleController\make_seeAlso(), TYPO3\CMS\IndexedSearch\Controller\SearchController\makeRating(), TYPO3\CMS\Cshmanual\Controller\HelpModuleController\printImage(), TYPO3\CMS\Impexp\ImportExport\processSoftReferences_saveFile_createRelFile(), TYPO3\CMS\Backend\Utility\BackendUtility\referenceCount(), TYPO3\CMS\Fluid\ViewHelpers\Uri\ResourceViewHelper\render(), TYPO3\CMS\Rtehtmlarea\Controller\CustomAttributeController\render_clickenlarge(), TYPO3\CMS\Backend\Form\FormEngine\renderWizards(), and TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility\writeEmConfToFile().