Download the PHP package lastdragon-ru/path without Composer
On this page you can find all versions of the php package lastdragon-ru/path. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lastdragon-ru/path
More information about lastdragon-ru/path
Files in lastdragon-ru/path
Package path
Short Description Provides utilities for working with file and directory paths in an object-oriented way for all path types.
License MIT
Homepage https://github.com/LastDragon-ru/php-packages
Informations about the package path
Path
Provides utilities for working with file and directory paths in an object-oriented way for all path types.
[include:artisan]: <lara-asp-documentator:requirements "{$directory}">
Requirements
| Requirement | Constraint | Supported by |
|---|---|---|
| PHP | ^8.5 |
HEAD ⋯ 11.0.0 |
^8.4 |
HEAD ⋯ 9.2.0 |
|
^8.3 |
10.3.0 ⋯ 9.2.0 |
Installation
Motivation
Most similar packages consider file/directory paths as strings. It is work until we need to modify and/or actively work with them. Relative path resolution depends on the type of base path, for example:
/path/to/directory/file.md+../file.txt=/path/to/file.txt/path/to/directory+../file.txt=/path/to/file.txt
The strings (in general case) don't allow us to distinguish the directory path from the file path, and so resolve the path of file.txt correctly. Strings also cannot ensure type safety - there is no way to disallow passing a directory path where only a file path is wanted, and vice versa. To solve all these problems, the package defines FilePath.
The (string) $baseDirectory->resolve($file) is:
The (string) $baseFile->resolve($file) is:
The (string) $baseFile->file('../../file.md') is:
What is supported
The package works only with paths, not with URL/URI/etc, and doesn't interact with OS. The following table shows possible path types.
| Type | Example | Root |
|---|---|---|
Type::Absolute |
/path |
/ |
Type::Relative |
path, ./path, ../path |
|
Type::Home |
~, ~/, ~/path |
~/ |
Type::User |
~username, ~username/path |
~username/ |
Type::Unc |
\\ComputerName\SharedFolder\Resource |
\\ComputerName\SharedFolder |
Type::WindowsAbsolute |
C:\path |
C:\ |
Type::WindowsRelative |
C:path |
C:/<current directory>^1 or C:\^1 |
As a path separator, any/mix of //\ can be used, but in the normalized form all \ will always be converted into /:
The (string) $base->resolve($file) is:
The (string) $win->normalized() is:
Home ~/
OS independent means that unlike e.g. \Symfony\Component\Filesystem\Path the user home directory ~/ will not be replaced to the actual path, moreover paths stated with ~/ will be treatment like absolute paths (because in almost all cases it is an absolute path).
The $home->type is:
The (string) $home->resolve($file) is:
The (string) $home->file('../../../file.md') is:
Windows
Nothing special here except how the relative path resolves^1:
The (string) $base->resolve(new FilePath('C:file.txt')) is:
The (string) $base->resolve(new FilePath('D:file.txt')) is:
Universal Naming Convention (UNC)
In UNC, the root is \\server\share, so relative paths resolve based on it:
The (string) $base->resolve($file) is:
Making path relative
The (string) $base->relative(new FilePath('~/file.txt')) is:
The $base->relative(new FilePath('/file.txt')) is:
Upgrading
Please follow Upgrade Guide.
Contributing
Please use the main repository to report issues, send pull requests, or ask questions.
"\LastDragon_ru\Path\DirectoryPath"
"\LastDragon_ru\Path\FilePath"
"\LastDragon_ru\Path\Type::Absolute"
"\LastDragon_ru\Path\Type::Home"
"\LastDragon_ru\Path\Type::Relative"
"\LastDragon_ru\Path\Type::Unc"
"\LastDragon_ru\Path\Type::User"
"\LastDragon_ru\Path\Type::WindowsAbsolute"
"\LastDragon_ru\Path\Type::WindowsRelative"