Piwik\

Filesystem

Contains helper functions that deal with the filesystem.

Methods

The class defines the following methods:

  • mkdir() — Attempts to create a new directory.
  • globr() — Recursively find pathnames that match a pattern.
  • unlinkRecursive() — Recursively deletes a directory.
  • copy() — Copies a file from $source to $dest.
  • copyRecursive() — Copies the contents of a directory recursively from $source to $target.
  • deleteFileIfExists() — Deletes the given file if it exists.

mkdir()

Attempts to create a new directory. All errors are silenced.

Note: This function does not create directories recursively.

Signature

  • It accepts the following parameter(s):
    • $path (string) — The path of the directory to create.
  • It does not return anything or a mixed result.

globr()

Recursively find pathnames that match a pattern.

See glob for more info.

Signature

  • It accepts the following parameter(s):

    • $sDir (string) — directory The directory to glob in.
    • $sPattern (string) — pattern The pattern to match paths against.
    • $nFlags (int) — glob() . See glob().
  • Returns: array — The list of paths that match the pattern.

unlinkRecursive()

Recursively deletes a directory.

Signature

  • It accepts the following parameter(s):
    • $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.
  • It does not return anything or a mixed result.

copy()

Copies a file from $source to $dest.

Signature

  • It accepts the following parameter(s):
    • $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 (bool) — Whether to avoid copying files if the file is related to PHP (includes .php, .tpl, .twig files).
  • It returns a true value.
  • It throws one of the following exceptions:
    • Piwik\Exception\Exception — If the file cannot be copied.

copyRecursive()

Copies the contents of a directory recursively from $source to $target.

Signature

  • It accepts the following parameter(s):
    • $source (string) — A directory or file to copy, eg. './tmp/latest'.
    • $target (string) — A directory to copy to, eg. '.'.
    • $excludePhp (bool) — Whether to avoid copying files if the file is related to PHP (includes .php, .tpl, .twig files).
  • It does not return anything or a mixed result.
  • It throws one of the following exceptions:
    • Piwik\Exception\Exception — If a file cannot be copied.

deleteFileIfExists()

Deletes the given file if it exists.

Signature

  • It accepts the following parameter(s):

    • $pathToFile (string) —
  • Returns: bool — true in case of success or if file does not exist, false otherwise. It might fail in case the file is not writeable.