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.

11.1.0(1mo ago)03297MITPHPPHP ^8.4|^8.5

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 today

READMEChangelogDependencies (18)Versions (7)Used By (7)

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 ⋯ 11.0.0``^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").

```
