PHPackages                             lastdragon-ru/path - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. lastdragon-ru/path

ActiveLibrary[File &amp; Storage](/categories/file-storage)

lastdragon-ru/path
==================

Provides utilities for working with file and directory paths in an object-oriented way for all path types.

10.3.0(2mo ago)026MITPHPPHP ^8.3|^8.4

Since Jan 17Pushed 1mo agoCompare

[ Source](https://github.com/LastDragon-ru/path)[ Packagist](https://packagist.org/packages/lastdragon-ru/path)[ Docs](https://github.com/LastDragon-ru/php-packages)[ RSS](/packages/lastdragon-ru-path/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (10)Versions (5)Used By (6)

Path
====

[](#path)

Provides utilities for working with file and directory paths in an object-oriented way for all path types.

Requirements
============

[](#requirements)

RequirementConstraintSupported byPHP`^8.5``HEAD``^8.4``HEAD ⋯ 9.2.0``^8.3``10.3.0 ⋯ 9.2.0`Installation
============

[](#installation)

```
composer require lastdragon-ru/path
```

Motivation
==========

[](#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 [`DirectoryPath`](src/DirectoryPath.php "\LastDragon_ru\Path\DirectoryPath") and [`FilePath`](src/FilePath.php "\LastDragon_ru\Path\FilePath").

```
