F
File helpers: read, write, resolve, copy, symlink and mime type.
- listen Registers a callback fired after every read, write, append, copy, move, delete, upload and symlink with (op, path, duration in ms, byte count - 0 where there is no content).
Inspection 6
- exists Whether the file exists.
- isReadable Whether the file can be read.
- isWritable Whether the file can be written to.
- size The size in bytes.
- modified The last modified time as a Unix timestamp.
- clearStat Clears PHP's stat cache for one path, or for everything when no path is given.
Path 6
- name Returns the filename without directory.
- stem Returns the filename without extension.
- extension The extension, without the dot.
- directory The path of the containing directory.
- resolve Returns the first path that resolves to a real file, or empty
- first Returns the first of $paths that is a file, as given (no symlinks resolved), or empty
Methods
F::listen(callable $listener): void
Registers a callback fired after every read, write, append, copy, move, delete, upload and symlink with (op, path, duration in ms, byte count - 0 where there is no content).
Dir::move goes through move too, so a renamed folder is announced.
Parameters (1)
| $listener | callable |
phlat/src/Toolkit/F.php:18
Inspection
F::exists(string $path): bool
Whether the file exists.
Parameters (1)
| $path | string |
Returns bool
phlat/src/Toolkit/F.php:35
F::isReadable(string $path): bool
Whether the file can be read.
Parameters (1)
| $path | string |
Returns bool
phlat/src/Toolkit/F.php:41
F::isWritable(string $path): bool
Whether the file can be written to.
Parameters (1)
| $path | string |
Returns bool
phlat/src/Toolkit/F.php:47
F::size(string $path): int
The size in bytes.
Parameters (1)
| $path | string |
Returns int
phlat/src/Toolkit/F.php:53
F::modified(string $path): int
The last modified time as a Unix timestamp.
Parameters (1)
| $path | string |
Returns int
phlat/src/Toolkit/F.php:59
F::clearStat(?string $path = null): void
Clears PHP's stat cache for one path, or for everything when no path is given.
Parameters (1)
| $path | ?string = null |
phlat/src/Toolkit/F.php:65
Path
F::name(string $path): string
Returns the filename without directory.
Parameters (1)
| $path | string |
Returns string
phlat/src/Toolkit/F.php:76
F::stem(string $path): string
Returns the filename without extension.
Parameters (1)
| $path | string |
Returns string
phlat/src/Toolkit/F.php:82
F::extension(string $path): string
The extension, without the dot.
Parameters (1)
| $path | string |
Returns string
phlat/src/Toolkit/F.php:88
F::directory(string $path): string
The path of the containing directory.
Parameters (1)
| $path | string |
Returns string
phlat/src/Toolkit/F.php:94
F::resolve(string ...$paths): string
Returns the first path that resolves to a real file, or empty
Parameters (1)
| ...$paths | string |
Returns string
phlat/src/Toolkit/F.php:100
F::first(string ...$paths): string
Returns the first of $paths that is a file, as given (no symlinks resolved), or empty
Parameters (1)
| ...$paths | string |
Returns string
phlat/src/Toolkit/F.php:111
Read / Write
F::read(string $path): string
The file's contents.
Parameters (1)
| $path | string |
Returns string
phlat/src/Toolkit/F.php:123
F::send(string $path): void
Streams the file to the output.
Parameters (1)
| $path | string |
phlat/src/Toolkit/F.php:134
F::write(string $path, string $contents): void
Writes $contents to $path, creating the file if it does not exist.
Atomic - readers never see a truncated/partial file mid-write.
Parameters (2)
| $path | string | |
| $contents | string |
phlat/src/Toolkit/F.php:140
F::chmod(string $path, int $mode): bool
Sets a file's permission bits, e.g. 0600 for a private key that must not be group/world-readable.
Parameters (2)
| $path | string | |
| $mode | int |
Returns bool
phlat/src/Toolkit/F.php:154
F::append(string $path, string $contents): void
Appends $contents to $path.
Parameters (2)
| $path | string | |
| $contents | string |
phlat/src/Toolkit/F.php:160
Operations
F::copy(string $source, string $destination): bool
Copies a file.
Parameters (2)
| $source | string | |
| $destination | string |
Returns bool
phlat/src/Toolkit/F.php:171
F::mirror(string $source, string $destination): bool
Copies $source to $destination if $destination is missing or older than $source, creating its directory first.
Parameters (2)
| $source | string | |
| $destination | string |
Returns bool
phlat/src/Toolkit/F.php:181
F::move(string $source, string $destination): bool
Moves or renames a file.
Parameters (2)
| $source | string | |
| $destination | string |
Returns bool
phlat/src/Toolkit/F.php:192
F::delete(string $path): bool
Deletes a file.
Parameters (1)
| $path | string |
Returns bool
phlat/src/Toolkit/F.php:202
F::upload(string $tmp, string $dest): bool
Moves a validated uploaded file to its destination.
Parameters (2)
| $tmp | string | |
| $dest | string |
Returns bool
phlat/src/Toolkit/F.php:212
Symlinks
F::symlink(string $target, string $link): bool
Creates a symlink at $link pointing to $target.
Parameters (2)
| $target | string | |
| $link | string |
Returns bool
phlat/src/Toolkit/F.php:224
F::isLink(string $path): bool
Whether the path is a symlink.
Parameters (1)
| $path | string |
Returns bool
phlat/src/Toolkit/F.php:234
F::readLink(string $path): string
Where a symlink points.
Parameters (1)
| $path | string |
Returns string
phlat/src/Toolkit/F.php:240
Metadata
F::mime(string $path): string
The mime type: by extension for common web files, else read from the contents.
Parameters (1)
| $path | string |
Returns string
phlat/src/Toolkit/F.php:266
F::imageSize(string $path): ?array
Returns [width, height] for an image file, or null if not readable.
Parameters (1)
| $path | string |
Returns ?array
phlat/src/Toolkit/F.php:276