PHP Класс Piwik\Filesystem

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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 )

Описание методов

checkIfFileSystemIsNFS() публичный статический Метод

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
Результат boolean True if on an NFS filesystem, false if otherwise or if we can't use shell_exec or exec.

clearPhpCaches() публичный статический Метод

public static clearPhpCaches ( )

copy() публичный статический Метод

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).
Результат true

copyRecursive() публичный статический Метод

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() публичный статический Метод

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() публичный статический Метод

Deletes the given file if it exists.
public static deleteFileIfExists ( string $pathToFile ) : boolean
$pathToFile string
Результат 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() публичный статический Метод

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
Результат string[]

getFileSize() публичный статический Метод

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'.
Результат float | null Returns null if file does not exist or the size of the file in the specified unit

getPathToPiwikRoot() публичный статический Метод

ending WITHOUT slash
public static getPathToPiwikRoot ( ) : string
Результат string

globr() публичный статический Метод

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()}.
Результат array The list of paths that match the pattern.

isValidFilename() публичный статический Метод

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
Результат boolean

mkdir() публичный статический Метод

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

realpath() публичный статический Метод

Get canonicalized absolute path See http://php.net/realpath
public static realpath ( string $path ) : string
$path string
Результат string canonicalized absolute path

remove() публичный статический Метод

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() публичный статический Метод

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[]
Результат string[]

unlinkRecursive() публичный статический Метод

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() публичный статический Метод

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