PHPackages                             orryv/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. orryv/path

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

orryv/path
==========

PHP library to handle URIs, URLs and paths in a clean way.

v2.0.0(9mo ago)1460PHP

Since Nov 29Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/orryv/path)[ Packagist](https://packagist.org/packages/orryv/path)[ RSS](/packages/orryv-path/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (2)Versions (9)Used By (0)

Path
====

[](#path)

Handles URI, URL, and file/folder paths. There are some @TODOs in the code, but it's working fine.

TODO
====

[](#todo)

- Implement asDot() which resolves to asFile() or asFolder() depending if there is a dot in the last part of the path. helpful for html hrefs.
- Implement preserveEndSlash() properly.
- Implement getNthFolder(), getFirstFolder(), getLastFolder() and find a way to deal with what it returns (accessPath, referencePath, accessURI)
- Other URIs probably parse ? and # when they shouldn't... (so it would be nice to have one method to parse them all, where we only pass the path (and $parseQuery, $parseFragment, and encoding) and it returns the parts)

Usage
=====

[](#usage)

IMPORTANT: all methods are immutable, they return a new instance of the object. (except for get methods, duh.)

```
use Orryv\Path

$path = Path::create('C:/path/to/file.txt');
// OR
$path = Path::create('file:///C:/path/to/file.txt');
// OR
$path = Path::create('https://website.com/path/to/page?query=string#fragment');
// OR (any URI)
$path = Path::create('ftp://path/to/file.txt');

// Return the path
$path->getReferencePath();
$path->getAccessPath();
$path->getAccessURI();

// Navigation
// Make sure to set it as file or as folder first:
$path = $path->asFile();
$path = $path->asFolder();
$path = $path->cd('path/to/another/folder');
```

### Usage with html

[](#usage-with-html)

```
use Orryv\Path
// when you find a href on a page
$url = Path::create('https://website.com/path/to/page?query=string#fragment') // current page
    ->asFile() // set current page as a file
    ->rmQuery() // remove query from the url
    ->rmFragment() // remove fragment from the url
    ->cd('path/to/another/file.jpg'); // href
```

### Usage with a base path

[](#usage-with-a-base-path)

A base path means cd can't go above it.

```
use Orryv\Path

$base_folder = Path::create('C:/path/to/folder')
    ->asFolder();

$path = Path::create('C:/path/to/folder/file.txt')
    ->asFile()
    ->setBasePath($base_folder)
    ->cd('..'); // will throw an error
```

### Encoding

[](#encoding)

In default, system paths are rawurlencoded for AccessURI. URIs (http://, ftp://, etc) are not DECODED. But you can change it if you want.

```
use Orryv\Path
use Orryv\Path\Enums\Encoder;

// This will only affect AccessURI
$path = Path::create('C:/path/to/file#.txt')
    ->asFile()
    ->setEncoding(Encoder::RAWURLENCODE); // this will ENCODE the # when getting AccessURI()

// For URIs (except file://) it will only affect ReferencePath
$path = Path::create('https://website.com/path/to/page?query=string#fragment')
    ->asFile()
    ->setEncoding(Encoder::URLENCODE); // this will DECODE the # when getting ReferencePath()
```

Glossary
========

[](#glossary)

Output types
------------

[](#output-types)

- **AccessPath**: To be used in PHP functions. Used to access a path in PHP file functions, or curl if the input was an URL (or any URI not starting with file://). Examples:

    - `/path/to/unix/file.txt`
    - `C:\path\to\windows\file.txt`
    - `\\\\serverName\path\to\windows\network\share\file.txt`
    - `https://website.com/path/to/page?query=string#fragment`
    - `ftp://path/to/file.txt`
- **AccessURI**: Always returns an URI. Returns the URI of a path, if a file/folder path was given, it will return the file:// URI. Examples:

    - `file:///path/to/unix/file.txt`
    - `file:///C:/path/to/windows/file.txt`
    - `file://serverName/path/to/windows/network/share/file.txt`
    - `https://website.com/path/to/page?query=string#fragment`
    - `ftp://path/to/file.txt`
- **ReferencePath**: Returns the access path but with forward slashes. Used to make paths uniform, it will never have backslashes (windows paths). Examples:

    - `/path/to/unix/file.txt`
    - `C:/path/to/windows/file.txt`
    - `//serverName/path/to/windows/network/share/file.txt`
    - `https://website.com/path/to/page?query=string#fragment`
    - `ftp://path/to/file.txt`

Directory &amp; Files
---------------------

[](#directory--files)

- **Path**: The input `$path` (file or folder.) Must be a ReferencePath. It's like the "working directory" but also applies to files.
- **Root Folder**: The folder at the root of a path. It is the first folder in the path. Examples:

    - `/path/to/unix/file.txt` =&gt; `/`
    - `C:\path\to\windows\file.txt` =&gt; `C:\`
    - `\\\\serverName\path\to\windows\network\share\file.txt` =&gt; `\\\\serverName\`
    - `https://website.com/path/to/page?query=string#fragment` =&gt; `https://website.com/`
    - `ftp://path/to/file.txt` =&gt; `ftp://` OR `ftp://user@host/`
- **Base Path/Folder**: The folder used to indicate where `cd()` can't go above.

Note: While you could asume that relative paths are relative to the Base Folder, IT IS NOT. Relative paths are relative to `$path`. The Base Folder is only used to set a hard limit to the `cd()` method.

Dev
===

[](#dev)

Run tests

```
php ./vendor/bin/phpunit tests/Integration
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance60

Regular maintenance activity

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~87 days

Total

5

Last Release

231d ago

Major Versions

v1.0.1 → v2.0.02025-09-15

v2.0.1.x-dev → v3.x-dev2025-11-14

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/14943012?v=4)[Orry Vandermeulen](/maintainers/orryv)[@orryv](https://github.com/orryv)

---

Top Contributors

[![orryv](https://avatars.githubusercontent.com/u/14943012?v=4)](https://github.com/orryv "orryv (13 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/orryv-path/health.svg)

```
[![Health](https://phpackages.com/badges/orryv-path/health.svg)](https://phpackages.com/packages/orryv-path)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

346132.9M112](/packages/google-cloud-core)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[phpactor/phpactor

PHP refactoring and intellisense tool for text editors

1.9k17.1k1](/packages/phpactor-phpactor)[brianhenryie/strauss

Prefixes dependencies namespaces so they are unique to your plugin

190438.1k36](/packages/brianhenryie-strauss)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
