PHP Class Piwik\Filesystem

Afficher le fichier Open project: piwik/piwik Class Usage Examples

Méthodes publiques

Méthode Description
checkIfFileSystemIsNFS ( ) : boolean Checks if the filesystem Piwik stores sessions in is NFS or not. This check is done in order to avoid using file based sessions on NFS system, since on such a filesystem file locking can make file based sessions incredibly slow.
clearPhpCaches ( )
copy ( string $source, string $dest, boolean $excludePhp = false ) : true Copies a file from $source to $dest.
copyRecursive ( string $source, string $target, boolean $excludePhp = false ) Copies the contents of a directory recursively from $source to $target.
deleteAllCacheOnUpdate ( $pluginName = false ) Called on Core install, update, plugin enable/disable Will clear all cache that could be affected by the change in configuration being made
deleteFileIfExists ( string $pathToFile ) : boolean Deletes the given file if it exists.
directoryDiff ( $source, $target ) : string[] Computes the difference of directories. Compares $target against $source and returns a relative path to all files and directories in $target that are not present in $source.
getFileSize ( string $pathToFile, string $unit = 'B' ) : float | null Get the size of a file in the specified unit.
getPathToPiwikRoot ( ) : string ending WITHOUT slash
globr ( string $sDir, string $sPattern, integer $nFlags = null ) : array Recursively find pathnames that match a pattern.
isValidFilename ( string $filename ) : boolean Returns true if the string is a valid filename File names that start with a-Z or 0-9 and contain a-Z, 0-9, underscore(_), dash(-), and dot(.) will be accepted.
mkdir ( string $path ) Attempts to create a new directory. All errors are silenced.
realpath ( string $path ) : string Get canonicalized absolute path See http://php.net/realpath
remove ( string $file, boolean $silenceErrors = false ) Remove a file.
sortFilesDescByPathLength ( string[] $files ) : string[] Sort all given paths/filenames by its path length. Long path names will be listed first. This method can be useful if you have for instance a bunch of files/directories to delete. By sorting them by lengh you can make sure to delete all files within the folders before deleting the actual folder.
unlinkRecursive ( string $dir, boolean $deleteRootToo, Closure $beforeUnlink = null ) Recursively deletes a directory.
unlinkTargetFilesNotPresentInSource ( string $source, string $target ) Removes all files and directories that are present in the target directory but are not in the source directory.

Private Methods

Méthode Description
createIndexFilesToPreventDirectoryListing ( $path ) in tmp/ (sub-)folder(s) we create empty index.htm|php files
getChmodForPath ( $path ) : integer
hasPHPExtension ( $file )
havePhpFilesSameContent ( $file1, $file2 )
isPathWithinTmpFolder ( $path ) : boolean
tryToCopyFileAndVerifyItWasCopied ( $source, $dest )

Method Details

checkIfFileSystemIsNFS() public static méthode

Note: In order to figure this out, we try to run the 'df' program. If the 'exec' or 'shell_exec' functions are not available, we can't do the check.
public static checkIfFileSystemIsNFS ( ) : boolean
Résultat boolean True if on an NFS filesystem, false if otherwise or if we can't use shell_exec or exec.

clearPhpCaches() public static méthode

public static clearPhpCaches ( )

copy() public static méthode

Copies a file from $source to $dest.
public static copy ( string $source, string $dest, boolean $excludePhp = false ) : true
$source string A path to a file, eg. './tmp/latest/index.php'. The file must exist.
$dest string A path to a file, eg. './index.php'. The file does not have to exist.
$excludePhp boolean Whether to avoid copying files if the file is related to PHP (includes .php, .tpl, .twig files).
Résultat true

copyRecursive() public static méthode

Copies the contents of a directory recursively from $source to $target.
public static copyRecursive ( string $source, string $target, boolean $excludePhp = false )
$source string A directory or file to copy, eg. './tmp/latest'.
$target string A directory to copy to, eg. '.'.
$excludePhp boolean Whether to avoid copying files if the file is related to PHP (includes .php, .tpl, .twig files).

deleteAllCacheOnUpdate() public static méthode

Called on Core install, update, plugin enable/disable Will clear all cache that could be affected by the change in configuration being made
public static deleteAllCacheOnUpdate ( $pluginName = false )

deleteFileIfExists() public static méthode

Deletes the given file if it exists.
public static deleteFileIfExists ( string $pathToFile ) : boolean
$pathToFile string
Résultat boolean true in case of success or if file does not exist, false otherwise. It might fail in case the file is not writeable.

directoryDiff() public static méthode

Computes the difference of directories. Compares $target against $source and returns a relative path to all files and directories in $target that are not present in $source.
public static directoryDiff ( $source, $target ) : string[]
$source
$target
Résultat string[]

getFileSize() public static méthode

Get the size of a file in the specified unit.
public static getFileSize ( string $pathToFile, string $unit = 'B' ) : float | null
$pathToFile string
$unit string eg 'B' for Byte, 'KB', 'MB', 'GB', 'TB'.
Résultat float | null Returns null if file does not exist or the size of the file in the specified unit

getPathToPiwikRoot() public static méthode

ending WITHOUT slash
public static getPathToPiwikRoot ( ) : string
Résultat string

globr() public static méthode

See {@link http://php.net/manual/en/function.glob.php glob} for more info.
public static globr ( string $sDir, string $sPattern, integer $nFlags = null ) : array
$sDir string directory The directory to glob in.
$sPattern string pattern The pattern to match paths against.
$nFlags integer `glob()` . See {@link http://php.net/manual/en/function.glob.php glob()}.
Résultat array The list of paths that match the pattern.

isValidFilename() public static méthode

File names beginning with anything but a-Z or 0-9 will be rejected (including .htaccess for example). File names containing anything other than above mentioned will also be rejected (file names with spaces won't be accepted).
public static isValidFilename ( string $filename ) : boolean
$filename string
Résultat boolean

mkdir() public static méthode

_Note: This function does **not** create directories recursively._
public static mkdir ( string $path )
$path string The path of the directory to create.

realpath() public static méthode

Get canonicalized absolute path See http://php.net/realpath
public static realpath ( string $path ) : string
$path string
Résultat string canonicalized absolute path

remove() public static méthode

Remove a file.
public static remove ( string $file, boolean $silenceErrors = false )
$file string
$silenceErrors boolean If true, no exception will be thrown in case removing fails.

sortFilesDescByPathLength() public static méthode

Sort all given paths/filenames by its path length. Long path names will be listed first. This method can be useful if you have for instance a bunch of files/directories to delete. By sorting them by lengh you can make sure to delete all files within the folders before deleting the actual folder.
public static sortFilesDescByPathLength ( string[] $files ) : string[]
$files string[]
Résultat string[]

unlinkRecursive() public static méthode

Recursively deletes a directory.
public static unlinkRecursive ( string $dir, boolean $deleteRootToo, Closure $beforeUnlink = null )
$dir string Path of the directory to delete.
$deleteRootToo boolean If true, `$dir` is deleted, otherwise just its contents.
$beforeUnlink Closure An optional closure to execute on a file path before unlinking.

unlinkTargetFilesNotPresentInSource() public static méthode

Removes all files and directories that are present in the target directory but are not in the source directory.
public static unlinkTargetFilesNotPresentInSource ( string $source, string $target )
$source string Path to the source directory
$target string Path to the target