Skip to content

Latest commit

 

History

History
440 lines (320 loc) · 8.98 KB

File metadata and controls

440 lines (320 loc) · 8.98 KB

fs

  • class fs (php\lib\fs)
  • package std
  • source php/lib/fs.php

Description

File System class.

Class fs


Static Methods

  • fs ::separator() - Return the local filesystem's name-separator character.
  • fs ::pathSeparator() - Return the local filesystem's path-separator character.
  • fs ::valid() - Validate file name.
  • fs ::abs() - Returns absolute real path.
  • fs ::name() - Returns name of the path.
  • fs ::nameNoExt() - Returns name of the path without extension.
  • fs ::pathNoExt() - Returns path without extension.
  • fs ::relativize()
  • fs ::ext() - Returns extension of path.
  • fs ::hasExt() - Check that $path has an extension from the extension set.
  • fs ::parent() - Returns parent directory.
  • fs ::ensureParent() - Checks parent of path and if it is not exists, tries to create parent directory.
  • fs ::normalize() - Normalizes file path for current OS.
  • fs ::exists() - Checks that file is exists.
  • fs ::size() - Returns size of file in bytes.
  • fs ::isFile() - Checks that path is file.
  • fs ::isDir() - Checks that path is directory.
  • fs ::isHidden() - Checks that path is hidden.
  • fs ::time() - Returns last modification time of file or directory.
  • fs ::makeDir() - Creates empty directory (mkdirs) if not exists.
  • fs ::makeFile() - Creates empty file, if file already exists then rewrite it.
  • fs ::delete() - Deletes file or empty directory.
  • fs ::clean() - Deletes all files in path. This method does not delete the $path directory.
  • fs ::scan() - Scans the path with callback or array filter and can returns found list
  • fs ::crc32() - Calculates crc32 sum of file or stream, returns null if it's failed.
  • fs ::hash() - Calculates hash of file or stream.
  • fs ::copy() - Copies $source stream to $dest stream.
  • fs ::move() - Renames or moves a file or empty dir.
  • fs ::rename() - Set name for file, returns true if success.
  • fs ::get() - Reads fully data from source and returns it as binary string.
  • fs ::parseAs() - Read fully data from source, parse as format and return result.
  • fs ::parse() - Read fully data from source, parse as format by extensions and return result.
  • fs ::formatAs() - Write formatted data to source (path).
  • fs ::format() - Write formatted (based on path extension) data to source (path).
  • fs ::match() - Tells if given path matches this matcher's pattern.

Static Methods

separator()

fs::separator(): string

Return the local filesystem's name-separator character.


pathSeparator()

fs::pathSeparator(): string

Return the local filesystem's path-separator character.


valid()

fs::valid(mixed $name): bool

Validate file name.


abs()

fs::abs(mixed $path): string

Returns absolute real path.


name()

fs::name(mixed $path): string

Returns name of the path.


nameNoExt()

fs::nameNoExt(mixed $path): string

Returns name of the path without extension.


pathNoExt()

fs::pathNoExt(string $path): string

Returns path without extension.


relativize()

fs::relativize(string $path, string $basePath): string

ext()

fs::ext(mixed $path): string

Returns extension of path.


hasExt()

fs::hasExt(string $path, string|array $extensions, bool $ignoreCase): bool

Check that $path has an extension from the extension set.


parent()

fs::parent(mixed $path): string

Returns parent directory.


ensureParent()

fs::ensureParent(string $path): bool

Checks parent of path and if it is not exists, tries to create parent directory. See makeDir().


normalize()

fs::normalize(mixed $path): string

Normalizes file path for current OS.


exists()

fs::exists(mixed $path): string

Checks that file is exists.


size()

fs::size(mixed $path): int

Returns size of file in bytes.


isFile()

fs::isFile(mixed $path): bool

Checks that path is file.


isDir()

fs::isDir(mixed $path): bool

Checks that path is directory.


isHidden()

fs::isHidden(mixed $path): bool

Checks that path is hidden.


time()

fs::time(mixed $path): int

Returns last modification time of file or directory.


makeDir()

fs::makeDir(string $path): bool

Creates empty directory (mkdirs) if not exists.


makeFile()

fs::makeFile(mixed $path): bool

Creates empty file, if file already exists then rewrite it.


delete()

fs::delete(mixed $path): bool

Deletes file or empty directory.


clean()

fs::clean(string $path, callable|array $filter): array

Deletes all files in path. This method does not delete the $path directory. Returns array with error, success and skip file list.

Array filter, e.g.: [ namePattern => string (regex), extensions => [...], excludeExtensions => [...], excludeDirs => bool, excludeFiles => bool, excludeHidden => bool,

minSize => int maxSize => int minTime => int, millis maxTime => int, millis

callback => function (File $file, $depth) { } ]


scan()

fs::scan(string $path, callable|array $filter, int $maxDepth, bool $subIsFirst): array

Scans the path with callback or array filter and can returns found list if the callback returns any result or if the callback is null.

Array filter, e.g.: [ namePattern => string (regex), extensions => [...], excludeExtensions => [...], excludeDirs => bool, excludeFiles => bool, excludeHidden => bool,

minSize => int maxSize => int minTime => int, millis maxTime => int, millis

callback => function (File $file, $depth) { } ]


crc32()

fs::crc32(string|Stream $source): int|null

Calculates crc32 sum of file or stream, returns null if it's failed.


hash()

fs::hash(string|Stream $source, string $algo, callable $onProgress): string|null

Calculates hash of file or stream.


copy()

fs::copy(string|File|Stream $source, string|File|Stream $dest, callable $onProgress, int $bufferSize): int

Copies $source stream to $dest stream.


move()

fs::move(string $fromPath, string $toPath): bool

Renames or moves a file or empty dir.


rename()

fs::rename(string $pathToFile, string $newName): bool

Set name for file, returns true if success.


get()

fs::get(string $source, null|string $charset, string $mode): string

Reads fully data from source and returns it as binary string.


parseAs()

fs::parseAs(mixed $path, string $format, int $flags): mixed

Read fully data from source, parse as format and return result.


parse()

fs::parse(mixed $path, int $flags): mixed

Read fully data from source, parse as format by extensions and return result.


formatAs()

fs::formatAs(mixed $path, mixed $value, string $format, int $flags): void

Write formatted data to source (path).


format()

fs::format(mixed $path, mixed $value, int $flags): void

Write formatted (based on path extension) data to source (path).


match()

fs::match(string $path, string $fsPattern): bool

Tells if given path matches this matcher's pattern.