TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
PathUtility Class Reference
Inheritance diagram for PathUtility:
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

static basename (   $path)
static
static 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 TypoScriptParser\extractIncludes(), PathUtilityTest\getAbsolutePathOfRelativeReferencedFileOrPathResolvesFileCorrectly(), TypoScriptParser\includeDirectory(), and TypoScriptParser\includeFile().

static 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 40 of file PathUtility.php.

References PathUtility\dirname(), GeneralUtility\getIndpEnv(), and GeneralUtility\resolveBackPath().

Referenced by T3editor\__construct(), Typo3Link\buildJSClassesAnchorArray(), UriBuilder\buildUri(), PageRenderer\computeRequireJsConfig(), ErrorPageController\errorAction(), DatabaseIntegrityView\func_refindex(), BitmapIconProvider\generateInlineMarkup(), BitmapIconProvider\generateMarkup(), SvgIconProvider\generateMarkup(), DocumentTemplate\getBackendFavicon(), RichTextElement\getContentCssFileNames(), ConfigurationStatus\getDeprecationLogFileLink(), RichTextElement\getExternalPlugins(), FormEngineUtility\getIconHtml(), RichTextElement\getRteInitJsCode(), PageRenderer\getStreamlinedFileName(), LoginController\getUriForFileName(), DocumentTemplate\getUriForFileName(), BackendController\includeLegacyBackendItems(), EditDocumentController\openInNewWindowLink(), PageRenderer\processJsFile(), NewRecordController\regularNew(), RichTextElement\render(), T3editorElement\render(), BackendController\render(), TaskModuleController\renderListMenu(), PageRenderer\renderMainJavaScriptLibraries(), IconViewHelper\renderStatic(), AbstractBackendController\resolveResourcePaths(), and RteHtmlAreaApi\writeTemporaryFile().

static getCanonicalPath (   $path)
static

Resolves all dots, slashes and removes spaces after or before a path...

Parameters
string$pathInput string
Returns
string Canonical path, always without trailing slash

Definition at line 277 of file PathUtility.php.

Referenced by ResourceStorage\addFile(), AbstractHierarchicalFilesystemDriver\canonicalizeAndCheckFilePath(), PathUtilityTest\getCanonicalPathCorrectlyCleansPath(), BasicFileUtility\is_directory(), ResourceFactory\retrieveFileOrFolderObject(), and UnitTestCase\tearDown().

static 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 FileWriter\createLogFile(), ResourceFactory\findBestMatchingStorageByLocalPath(), and PathUtilityTest\isCommonPrefixResolvedCorrectly().

static 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 GeneralUtility\fixWindowsFilePath(), and GeneralUtility\isAllowedAbsPath().

Referenced by PathUtilityTest\isRelativePathResolvedCorrectly(), BackendController\loadResourcesForRegisteredNavigationComponents(), ResourceFactory\retrieveFileOrFolderObject(), and ResourceCompressor\returnFileReference().

static 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 PathUtility\dirname().

Referenced by DocumentTemplate\addStyleSheetDirectory(), ResourceStorage\getPublicUrl(), PageRenderer\getStreamlinedFileName(), and Image\getUrl().

static 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 TemplatePaths\ensureAbsolutePath(), and FileWriter\setLogFile().

static 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.

static pathinfo (   $path,
  $options = null 
)
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
int$options
Returns
string|array

Definition at line 208 of file PathUtility.php.

References $GLOBALS.

Referenced by ResourceStorage\checkFileExtensionPermission(), ResourceCompressor\compressCssFile(), ResourceCompressor\compressJsFile(), Indexer\gatherFileInformationArray(), AbstractFile\getExtension(), AbstractFile\getNameWithoutExtension(), FormPersistenceManager\getOrCreateFile(), AbstractDriver\getTemporaryPathForFile(), and ResourceStorage\getUniqueName().

static 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 FileHandlingUtility\createZipFileFromExtension(), PathUtilityTest\isTrailingSeparatorSanitizedCorrectly(), PackageManager\registerPackageDuringRuntime(), and PackageManager\registerPackagesFromConfiguration().