PHPackages                             axy/syspaths - 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. axy/syspaths

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

axy/syspaths
============

Specifying paths within the system

0.1.1(10y ago)0431MITPHPPHP &gt;=5.4.0

Since Oct 26Pushed 8y ago1 watchersCompare

[ Source](https://github.com/axypro/syspaths)[ Packagist](https://packagist.org/packages/axy/syspaths)[ Docs](https://github.com/axypro/syspaths)[ RSS](/packages/axy-syspaths/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

axy\\syspaths
=============

[](#axysyspaths)

Specifying paths within the system.

[![Latest Stable Version](https://camo.githubusercontent.com/e8c5dbb91509d554836b667399caea9b9dc9668b0ed77678b265c4e895366dbe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6178792f73797370617468732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/axy/syspaths)[![Minimum PHP Version](https://camo.githubusercontent.com/b52c83f3d45755ebcb1e6863ebb202ab192aaf773424369ffdeedae107f027ef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e342d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Build Status](https://camo.githubusercontent.com/8ff831905dfa48fba64caeafbb9112acc33f22d1e1b372c6b3be948c93874890/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f61787970726f2f73797370617468732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/axypro/syspaths)[![Coverage Status](https://camo.githubusercontent.com/ffc235d4e09599ca801ea08ac001ff7aa997c05c1a76b21b2815c776be681296/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f61787970726f2f73797370617468732f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/axypro/syspaths?branch=master)[![License](https://camo.githubusercontent.com/fcce6bc2d9bee1b6f15f96a4dbeead204e52a0dc4770e3985ec9bf2c9dd24a56/68747470733a2f2f706f7365722e707567782e6f72672f6178792f73797370617468732f6c6963656e7365)](LICENSE)

- The library does not require any dependencies (except composer packages).
- Tested on PHP 5.4+, PHP 7, HHVM (on Linux), PHP 5.5 (on Windows).
- Install: `composer require axy/syspaths`.
- License: [MIT](LICENSE).

### Documentation

[](#documentation)

The library allows to store of the directories structure within a certain system. Inside an application for example.

```
/* App init. __DIR__ is /www/example.loc */
use axy\syspaths\Paths;

$paths = new Paths(__DIR__, [
    'htdocs' => 'www',
    'source' => 'src',
    'templates' => 'templates',
]);

/* Further */

$tplFN = $app->paths->templates.'/default.twig'; // /www/example.loc/templates/default.twig
```

Define paths in one place makes it easy to change the structure.

#### API

[](#api)

The library provides a single class `axy\syspaths\Paths`.

The constructor:

```
Paths::__construct(string $root [, array $patterns]);

```

The only required arguments is `$root` - the root directory of the system.

##### $patterns

[](#patterns)

`$patterns` specifies a list of sub-paths. It can be specified via the constructor (as in the example above). Or by overriding:

```
/**
 * @property-read string $www
 * @property-read string $templates
 */
class MyPaths extends Paths
{
    protected $patterns = [
        'htdocs' => 'www',
        'templates' => 'templates',
    ];
}
```

Now available autocomplete in IDE.

Or you can define the property `$patterns` and also specify the argument of the constructor. In this case these two list recursively merged. For example, define a system class and redefine some paths for tests.

##### Access to paths

[](#access-to-paths)

Via magic methods.

```
$paths->templates; // /www/example.loc/templates
$paths->root; // /www/example.loc

isset($paths->htdocs); // TRUE

$paths->htdocs = 'new-www'; // Exception: Paths is read-only
```

#### Patterns

[](#patterns-1)

```
[
    'www' => 'www',
    'images' => ':www:/i',
    'icons' => ':images:/icons',
    'logo' => ':icons:/logo.gif',
    'tmp' => '/tmp',
]
```

If a path pattern begins with a colon then it is a link to the other path. Such links are processed recursively (circular references are not tracked):

```
$paths->icons; // /www/example.loc/www/i/icons/logo.gif
```

If a path pattern begins with `/` then it is an absolute path:

```
$paths->tmp; // /tmp
```

Other patterns is relative to the root. `www` is equivalent to `:root:/www`.

#### Nested paths

[](#nested-paths)

```
[
    'htdocs' => 'www',
    'templates' => [
        'root' => 'templates',
        'layouts' => 'layouts',
        'admin' => ':layouts:/admin',
        'profile' => ':admin:/profile.twig',
    ],
]
```

An array defines a nested object Paths.

```
$paths->templates->profile; // /www/example.loc/templates/layouts/admin/profile.twig
```

For Paths-objects defined `__toString()`:

```
$paths->templates.'/mails'; // /www/example.loc/templates/mails
```

The nested array must contains the field `root`. It may be link: `'root' => ':htdocs:/templates'`.

The nested array may contains the field `__classname` for the class of the nested path. By defaults it is `axy\syspaths\Paths`.

```
/**
 * @property-read string $htdocs
 * @property-read TemplatesPaths $templates
 */
class MyPaths extends Paths
{
    $patterns = [
        'htdocs' => 'www',
        'templates' => [
            'root' => 'templates',
            '__classname' => 'TemplatesPaths',
        ],
    ]
}

/**
 * @property-read string $layout
 * @property-read string $admin
 * @property-read string $profile
 */
class TemplatesPaths extends Paths
{
    $patterns = [
        'layouts' => 'layouts',
        'admin' => ':layouts:/admin',
        'profile' => ':admin:/profile.twig',
    ];
}
```

Now we have the full auto-complete: `$app->paths->templates->profile`.

Links can consist of several components:

```
[
    'templates' => [
        'root' => 'templates',
        'layouts' => 'layouts',
        'admin' => ':layouts:/admin',
    ],
    'profileTemplate' => ':templates.admin:/profile.twig',
]
```

#### Creating paths

[](#creating-paths)

```
$paths->templates->layouts.'/tpl.twig';
```

Or via the method `create` (or `__invoke`):

```
$paths->create(':templates.layouts:/tpl.twig');
$paths(':templates.layouts:/tpl.twig');
```

```
Paths::create($pattern, $real = false);

```

If specified the second argument `$real` executed `realpath()` for the result. If the path is not exists then returned `NULL`.

#### Exceptions

[](#exceptions)

In the namespace `axy\syspaths\errors`.

- `RequirePatterns` - `$patterns` not defined nor in the property, nor in the constructor.
- `PatternNotFound` - where access via `__get` or in a link form other pattern.
- `InvalidPattern` - not closed link, a nested array is not contains `root`, `__classname` in not exists and etc.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

Total

2

Last Release

3842d ago

### Community

Maintainers

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

---

Top Contributors

[![vasa-c](https://avatars.githubusercontent.com/u/557081?v=4)](https://github.com/vasa-c "vasa-c (16 commits)")

---

Tags

path

### Embed Badge

![Health badge](/badges/axy-syspaths/health.svg)

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

###  Alternatives

[league/uri-components

URI components manipulation library

31932.3M67](/packages/league-uri-components)[matthiasmullie/path-converter

Relative path converter

10229.6M7](/packages/matthiasmullie-path-converter)[sebastianfeldmann/camino

Path management the OO way

176.4M1](/packages/sebastianfeldmann-camino)

PHPackages © 2026

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