PHPackages                             dsxack/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. dsxack/path

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

dsxack/path
===========

Path port from nodejs

v1.0.1(11y ago)2371[1 issues](https://github.com/DsXack/path/issues)MITPHP

Since Jan 29Pushed 11y ago1 watchersCompare

[ Source](https://github.com/DsXack/path)[ Packagist](https://packagist.org/packages/dsxack/path)[ RSS](/packages/dsxack-path/feed)WikiDiscussions master Synced 1mo ago

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

Path
====

[](#path)

PHP port Node.js(io.js) [path](https://iojs.org/dist/v1.0.3/doc/api/path.html) library

[![TravisCI](https://camo.githubusercontent.com/51e1c6154e032c9dbd5e3912a62608ddccb6e6b8a07f6330a0e05d92e73d6e50/68747470733a2f2f7472617669732d63692e6f72672f44735861636b2f706174682e737667)](https://travis-ci.org/DsXack/path)[![Coverage Status](https://camo.githubusercontent.com/8cd93496ae074a0c2e7f01c71ca1d53987c402062941d2bde504d6028100a7ae/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f44735861636b2f706174682f62616467652e737667)](https://coveralls.io/r/DsXack/path)[![Latest Stable Version](https://camo.githubusercontent.com/b4ff69fc49a6a255dac31da4592ffae722f091d1e56b8dbb738effd9e85466d3/68747470733a2f2f706f7365722e707567782e6f72672f64737861636b2f706174682f762f737461626c652e737667)](https://packagist.org/packages/dsxack/path)[![Total Downloads](https://camo.githubusercontent.com/add60f56dbd299b679b2fe358b0f2be5439ec5d87bbf22b0d2fdc44e8bb801be/68747470733a2f2f706f7365722e707567782e6f72672f64737861636b2f706174682f646f776e6c6f6164732e737667)](https://packagist.org/packages/dsxack/path)[![License](https://camo.githubusercontent.com/73cbebcc4a464e3f78788b16d0f5f65524bab7eff0e1e313c95752b17b49d8ff/68747470733a2f2f706f7365722e707567782e6f72672f64737861636b2f706174682f6c6963656e73652e737667)](https://packagist.org/packages/dsxack/path)

Usage
=====

[](#usage)

Path::normalize(p)
------------------

[](#pathnormalizep)

Normalize a string path, taking care of `'..'` and `'.'` parts.

When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.

Example:

```
Path::normalize('/foo/bar//baz/asdf/quux/..')
// returns
'/foo/bar/baz/asdf'

```

Path::join(\[path1\]\[, path2\]\[, ...\])
-----------------------------------------

[](#pathjoinpath1-path2-)

Join all arguments together and normalize the resulting path.

Arguments must be strings.

Example:

```
Path::join('/foo', 'bar', 'baz/asdf', 'quux', '..')
// returns
'/foo/bar/baz/asdf'

Path::join('foo', [], 'bar')
// throws exception
TypeError: Arguments to Path::join must be strings

```

Path::resolve(\[from ...\], to)
-------------------------------

[](#pathresolvefrom--to)

Resolves `to` to an absolute path.

If `to` isn't already absolute `from` arguments are prepended in right to left order, until an absolute path is found. If after using all `from` paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory. Non-string `from` arguments are ignored.

Another way to think of it is as a sequence of `cd` commands in a shell.

```
Path::resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile')

```

Is similar to:

```
cd foo/bar
cd /tmp/file/
cd ..
cd a/../subfile
pwd

```

The difference is that the different paths don't need to exist and may also be files.

Examples:

```
Path::resolve('/foo/bar', './baz')
// returns
'/foo/bar/baz'

Path::resolve('/foo/bar', '/tmp/file/')
// returns
'/tmp/file'

Path::resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// if currently in /home/myself/node, it returns
'/home/myself/node/wwwroot/static_files/gif/image.gif'

```

Path::isAbsolute(path)
----------------------

[](#pathisabsolutepath)

Determines whether `path` is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.

Posix examples:

```
Path::isAbsolute('/foo/bar') // true
Path::isAbsolute('/baz/..')  // true
Path::isAbsolute('qux/')     // false
Path::isAbsolute('.')        // false

```

Windows examples:

```
Path::isAbsolute('//server')  // true
Path::isAbsolute('C:/foo/..') // true
Path::isAbsolute('bar\\baz')   // false
Path::isAbsolute('.')         // false

```

Path::relative(from, to)
------------------------

[](#pathrelativefrom-to)

Solve the relative path from `from` to `to`.

At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of `path.resolve`, which means we see that:

```
Path::resolve(from, path.relative(from, to)) == path.resolve(to)

```

Examples:

```
Path::relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb')
// returns
'..\\..\\impl\\bbb'

Path::relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb')
// returns
'../../impl/bbb'

```

Path::dirname(p)
----------------

[](#pathdirnamep)

Return the directory name of a path. Similar to the Unix `dirname` command.

Example:

```
Path::dirname('/foo/bar/baz/asdf/quux')
// returns
'/foo/bar/baz/asdf'

```

Path::basename(p\[, ext\])
--------------------------

[](#pathbasenamep-ext)

Return the last portion of a path. Similar to the Unix `basename` command.

Example:

```
Path::basename('/foo/bar/baz/asdf/quux.html')
// returns
'quux.html'

Path::basename('/foo/bar/baz/asdf/quux.html', '.html')
// returns
'quux'

```

Path::extname(p)
----------------

[](#pathextnamep)

Return the extension of the path, from the last '.' to end of string in the last portion of the path. If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string. Examples:

```
Path::extname('index.html')
// returns
'.html'

Path::extname('index.coffee.md')
// returns
'.md'

Path::extname('index.')
// returns
'.'

Path::extname('index')
// returns
''

```

Path::sep()
-----------

[](#pathsep)

The platform-specific file separator. `'\\'` or `'/'`.

An example on \*nix:

```
explode(Path::sep(), 'foo/bar/baz')
// returns
['foo', 'bar', 'baz']

```

An example on Windows:

```
explode(Path::sep(), 'foo\\bar\\baz')
// returns
['foo', 'bar', 'baz']

```

Path::delimiter()
-----------------

[](#pathdelimiter)

The platform-specific path delimiter, `;` or `':'`.

An example on \*nix:

```
echo getenv('PATH')
// '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'

explode(Path::delimiter(), getenv('PATH'))
// returns
['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']

```

An example on Windows:

```
echo getenv('PATH')
// 'C:\Windows\system32;C:\Windows;C:\Program Files\php\'

explode(Path::delimiter(), getenv('PATH'))
// returns
['C:\Windows\system32', 'C:\Windows', 'C:\Program Files\php\']

```

Path::parse(pathString)
-----------------------

[](#pathparsepathstring)

Returns an object from a path string.

An example on \*nix:

```
Path::parse('/home/user/dir/file.txt')
// returns
[
    "root" => "/",
    "dir" => "/home/user/dir",
    "base" => "file.txt",
    "ext" => ".txt",
    "name" => "file"
]

```

An example on Windows:

```
Path::parse('C:\\path\\dir\\index.html')
// returns
[
    "root" => "C:\",
    "dir" => "C:\path\dir",
    "base" => "index.html",
    "ext" => ".html",
    "name" => "index"
]

```

Path::format(params)
--------------------

[](#pathformatparams)

Returns a path string from an object, the opposite of `Path::parse` above.

```
Path::format([
    "root" => "/",
    "dir" => "/home/user/dir",
    "base" => "file.txt",
    "ext" => ".txt",
    "name" => "file"
])
// returns
'/home/user/dir/file.txt'

```

PosixPath class
---------------

[](#posixpath-class)

Provide access to aforementioned `path` methods but always interact in a posix compatible way.

Win32Path class
---------------

[](#win32path-class)

Provide access to aforementioned `path` methods but always interact in a win32 compatible way.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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 ~0 days

Total

2

Last Release

4128d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e9bb92b01727d4617b781334dd065ceee8bc3431250157b921fc98774ffe6332?d=identicon)[dsxack](/maintainers/dsxack)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[workerman/gateway-worker-for-win

1711.1k2](/packages/workerman-gateway-worker-for-win)

PHPackages © 2026

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