Path Classes


The only concrete implementation of RelativePathInterface. In non-root relative paths first component returned by getComponents() is either '.' or '..'.

When resolving relative, windows-ness of the resulting relative will be inherited from the base path.

Available constructors:

new RelativePath(string $path, bool $windows = false);

$windows = false: Unix-like path. Path separators are slashes.

$windows = true: Windows-like path. Path separators are both slashes and backslashes. When exporting a string, backslashes are used.

RelativePath::unix(string $path): self;

Same as new RelativePath($path, windows: false)

RelativePath::windows(string $path): self;

Same as new RelativePath($path, windows: true)

RelativePath::currentOS(string $path): self;

If Windows is detected, create a Windows-like path, otherwise create Unix-like path.


Windows is detected by the DIRECTORY_SEPARATOR constant.

RelativePath::parse(string $path): self;

Alias of currentOS().


A base class for UnixPath and WindowsPath.

No default constructor, only a named constructor is available:

FilesystemPath::parse(string $path, bool $strict = false): self;

If Windows is detected, create a Windows path, otherwise create a Unix path. Strict mode does not allow to have relative components that traverse beyond root.


Windows is detected by the DIRECTORY_SEPARATOR constant.

use Arokettu\Path\FilesystemPath;

// on windows
FilesystemPath::parse('C:\Windows\..\..\..\Users'); // C:\Users
FilesystemPath::parse('C:\Windows\..\..\..\Users' strict: true); // exception


A class for Unix paths. The prefix is '/'

// these are equal
new UnixPath(string $path, bool $strict = false);
UnixPath::parse(string $path, bool $strict = false): self;



Windows usually have much more restrictions on file path than unix-like operating systems like forbidding characters like | and :. The library doesn’t check for that even in strict mode.

A class for Windows paths. makeRelative() returns relatives of the Windows-like type.

Supported paths:

  • DOS-like paths. The classic paths with a drive letter: C:\Path. Both slashes and backslashes are supported as component separators. Relative components are resolved on creation like in most other classes here. The prefix here is a drive letter.

  • UNC paths. Examples:

    • Local paths like \\*\C:\Path. The prefix here is \\*\C:\.

    • Network paths like \\AROKETTUPC\c$. The prefix here is \\AROKETTUPC\.

    UNC paths do not allow forward slashes and relative components.


Relative paths with drive letter like C:Path\Path are valid in Windows but are not supported by the library in any way.

// these are equal
new WindowsPath(string $path, bool $strict = false);
WindowsPath::parse(string $path, bool $strict = false): self;


A class for URL paths. The prefix is scheme + hostname.

// these are equal
new UrlPath(string $path, bool $strict = false);
UrlPath::parse(string $path, bool $strict = false): self;


A class for PHP stream like paths. Examples include php streams like php://temp. It can be useful with libraries that create virtual file systems like adlawson/vfs and mikey179/vfsstream. The prefix is scheme.

// these are equal
new StreamPath(string $path, bool $strict = false);
StreamPath::parse(string $path, bool $strict = false): self;