elephox / files
Elephox files library.
v0.7.0
2022-10-21 16:24 UTC
Requires
- php: ^8.1 <8.3
- elephox/collection: dev-develop
- elephox/mimey: ^4.0
- elephox/stream: dev-develop
- elephox/support: dev-develop
- jetbrains/phpstorm-attributes: ^1.0
- dev-develop
- 0.9.0.x-dev
- 0.8.0.x-dev
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.3
- 0.4.0
- 0.4.0-alpha5
- 0.4.0-alpha4
- 0.4.0-alpha3
- 0.4.0-alpha2
- 0.4.0-alpha1
- 0.3.27
- v0.3.25
- v0.3.24
- v0.3.23
- v0.3.22
- v0.3.21
- v0.3.20
- v0.3.18
- v0.3.17
- v0.3.16
- v0.3.15
- v0.3.14
- v0.3.13
- v0.3.12
- v0.3.11
- v0.3.10
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.1
- dev-release/0.9
- dev-release/0.8
- dev-release/0.7
- dev-release/0.6.0
- dev-16-psr-20-clock
- dev-18-make-servicecollection-more-extensible
- dev-release/0.6
- dev-release/0.5
- dev-release/0.4
- dev-release/0.3
This package is auto-updated.
Last update: 2024-10-30 01:48:28 UTC
README
This module is used by Elephox to provide an abstraction layer for directories and files. It also includes some helpers for file operations and working with paths.
Examples
<?php use Elephox\Files\File; use Elephox\Files\Directory; use Elephox\Files\Path; $file = new File('/var/tmp/file.txt'); $file->exists(); // false $file->writeContents('Hello world!'); $file->exists(); // true $file->contents(); // 'Hello world!' $file->extension(); // 'txt' $newParent = new Directory('/home/user/'); $newFile = $file->moveTo($newParent); $file->exists(); // false $newFile->exists(); // true $newParent->files()->select(fn (File $f) => $f->path())->toArray(); // ['/home/user/file.txt'] $newParent->relativePathTo($file->parent()); // '../../var/tmp' Path::join("/home/user/", "file.txt"); // '/home/user/file.txt' Path::join("/home/user/", "../../var/tmp/file.txt"); // '/home/user/../../var/tmp/file.txt' Path::canonicalize("/home/user\\\\../test\\dir/another//folder"); // '/home/user/../test/dir/another/folder' Path::isRoot("/"); // true Path::isRoot("/home/user"); // false Path::isRoot("C:\\") // true Path::isRoot("C:\\Windows\\System32"); // false Path::isRooted("/home/user"); // true Path::isRooted("home/user"); // false Path::isRooted("C:\\Windows\\System32"); // true Path::isRooted("..\\Users\\user\\"); // false