TYPO3  7.6
Static Public Member Functions | Static Protected Member Functions | List of all members
PathUtility Class Reference

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 dirname (   $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(), 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 StringUtility\beginsWith(), PathUtility\dirname(), elseif, GeneralUtility\getIndpEnv(), and GeneralUtility\resolveBackPath().

Referenced by UriBuilder\buildUri(), BitmapIconProvider\generateMarkup(), SvgIconProvider\generateMarkup(), LoginController\getUriForFileName(), and TaskModuleController\renderListMenu().

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

References elseif.

Referenced by ResourceStorage\addFile(), and BasicFileUtility\is_directory().

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.

References elseif.

Referenced by ResourceFactory\findBestMatchingStorageByLocalPath().

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 ResourceFactory\retrieveFileOrFolderObject().

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 AbstractSpriteHandler\collectTcaSpriteIcons(), ResourceStorage\getPublicUrl(), 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 FileWriter\setLogFile().

static isWindows ( )
staticprotected

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

Returns
bool

Definition at line 365 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(), AbstractSpriteHandler\collectTcaSpriteIcons(), ResourceCompressor\compressCssFile(), ResourceCompressor\compressJsFile(), AbstractFile\getExtension(), AbstractFile\getNameWithoutExtension(), 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(), PackageManager\registerPackagesFromConfiguration(), and PackageManager\scanPackagesInPath().

static stripPathSitePrefix (   $path)
static