PHPackages                             diversified-design/viaphp - 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. diversified-design/viaphp

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

diversified-design/viaphp
=========================

PHP 8.3+ utility library for path aliases and arbitrary path joining with cross-platform canonicalization

v1.3.0(4mo ago)01[1 issues](https://github.com/diversified-design/ViaPHP/issues)MITPHPPHP ^8.3

Since Aug 23Pushed 4mo agoCompare

[ Source](https://github.com/diversified-design/ViaPHP)[ Packagist](https://packagist.org/packages/diversified-design/viaphp)[ RSS](/packages/diversified-design-viaphp/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (9)Versions (17)Used By (0)

ViaPHP
======

[](#viaphp)

Via is a path alias management library.

It provides a static class for setting shorthand, dot-notation aliases to paths for easy access throughout your codebase, without hardcoding them all and passing around arrays or constants.

Given your project's full root path, and a hostname/IP, Via gives you access to system root, project root and URL root paths.

e.g.:

```
Via::p('host.data.logs') // '//local.test/data/logs'
Via::p('local.data.logs') // '/Users/me/Projects/foo/data/logs'
Via::p('rel.data.logs') // '/data/logs'

```

Paths are sanitized and canonicalized by Symfony's Filesystem component (`Path::class`), and dot-notation is enabled by

Installation
------------

[](#installation)

`composer require diversified-design/viaphp`

Usage
-----

[](#usage)

### Setting &amp; Assigning

[](#setting--assigning)

**Note:** Internally we use `/` as the project-relative root path for constructing full filesystem and host paths. This package does not provide methods for handling arbitrary relative paths. All paths returned will always be absolute, based on the project root, local root or hosted root.

#### Local Path

[](#local-path)

The absolute local filesystem path of the project, used for absolute filesystem paths.

```
Via::setLocal(path: "/User/me/Projects/foo");

```

In real world usage, this would be populated dynamically, based on the system. I.e.: the local system's full path will be different on local development and various deployment systems.

So you would do something like:

```
Via::setLocal(path: __DIR__); // if you're calling this from the project root.

```

You can retrieve the current local path with:

```
Via::getLocal(); // Returns: '/User/me/Projects/foo'
Via::l();        // Shorthand method - same result
via_local();     // Global function - same result

// With additional path parameters
Via::getLocal('config/app.php');     // Returns: '/User/me/Projects/foo/config/app.php'
Via::l('storage/logs');              // Returns: '/User/me/Projects/foo/storage/logs'
via_local('uploads/images');         // Returns: '/User/me/Projects/foo/uploads/images'

```

#### Host Domain

[](#host-domain)

The domain/hostname/IP addreess, for absolute URL paths

```
Via::setHost(host: "foo.local.test");

```

Here too, you will want to set this dynamically somehow based on the context.

You can retrieve the current host with:

```
Via::getHost();  // Returns: 'foo.local.test'
Via::h();        // Shorthand method - same result
via_host();      // Global function - same result

// With additional path parameters
Via::getHost('api/users');           // Returns: 'foo.local.test/api/users'
Via::h('assets/css');                // Returns: 'foo.local.test/assets/css'
via_host('cdn/images');              // Returns: 'foo.local.test/cdn/images'

```

#### Set Base

[](#set-base)

```
Via::setBase(alias: "data", label: "data");
Via::setBase(alias: "images", label: "images");
Via::setBase(alias: "src", label: "src");

```

#### Set Bases

[](#set-bases)

Set mutliple bases at once with an array (Calls `self::setBase()` internally)

```
Via::setBases(
    [
        [alias => "data", path => "data"],
        [alias => "images", path => "images"],
        [alias => "src", path => "src"]
    ]
);

```

#### Assign to Base

[](#assign-to-base)

Assign a sub-path to a Base

```
Via::assignToBase(alias: "modules", path: "modules", baseAlias: "src" );

```

#### Assign to Bases

[](#assign-to-bases)

Assign multiple sub-paths to Bases with an array (Calls `self::assignToBase()` internally)

```
Via::assignToBases(
    [alias: "caches", path: "caches", baseAlias: "data"],
    [alias: "logs", path: "logs", baseAlias: "data"],
    [alias: "modules", path: "modules", baseAlias: "src"],
    [alias: "frontend_js", path: "frontend/js", baseAlias: "src"]
);

```

#### Init

[](#init)

Set and Assign a whole config of bases and assignments from a given array. (Calls `self::setLocal()`, `self::setHost()`, `self::setBases()` and `self:assignToBases()` internally as needed)

```
Via::init(
    [
        "Local" => "/User/me/Projects/foo",
        "absoluteDomain" => "foo.local.test",
        "bases" => [
            [alias => "data", path => "data"],
            [alias => "images", path => "images"],
            [alias => "src", path => "src"]
        ],
        "assignments": [
            [alias: "caches", path: "caches", baseAlias: "data"],
            [alias: "logs", path: "logs", baseAlias: "data"],
            [alias: "modules", path: "modules", baseAlias: "src"],
            [alias: "frontend_js", path: "frontend/js", baseAlias: "src"]
        ]
    ]
)

```

### Getting

[](#getting)

Paths are accessed using dot-notation, and assembled at retrieval time (lazy loaded).

The accessing method is `Via::get()` but a `Via::p()` (read: "Via path") forwarder is provided for convenient shorthand notation. ( *I use `Via::p()` myself.* )

For even more convenience in templates and view files, a global `via()` function is also available:

```
Via::get('rel.data.logs');  // (string) '/data/logs'
Via::p('rel.data.logs');    // (string) '/data/logs' - same as above
via('rel.data.logs');       // (string) '/data/logs' - global function

Via::p('local.data.logs');  // (string) '/User/me/Projects/foo/data/logs'
Via::p('host.data.logs');   // (string) '://foo.local.test/data/logs'

Via::p('rel.src');          // (string) '/src'
Via::p('local.src');        // (string) '/User/me/Projects/foo/src'
Via::p('host.src');         // (string) '://foo.local.test/src'

Via::p('rel.src.frontend_js');   // (string) '/src/frontend/js'
Via::p('local.src.frontend_js'); // (string) '/User/me/Projects/foo/src/frontend/js'
Via::p('host.src.frontend_js');  // (string) '://foo.local.test/src/frontend/js'

```

#### Dynamic Path Appending

[](#dynamic-path-appending)

Both `get()`, `p()`, and the global `via()` function accept an optional second parameter to append additional path segments:

```
Via::p('rel.data', 'config/settings.json');        // '/data/config/settings.json'
Via::p('local.src', 'utils/helpers.php');          // '/User/me/Projects/foo/src/utils/helpers.php'
via('host.images', 'gallery/photo.jpg');           // '://foo.local.test/images/gallery/photo.jpg'

```

#### Global Functions

[](#global-functions)

For ultimate convenience, especially in templates, four global functions are available:

```
via('rel.data.logs');                    // Path retrieval
via_local();                             // Get local filesystem root
via_host();                              // Get host domain
via_join('/base/path', 'subdir');        // Arbitrary path joining

```

These global functions are automatically available when you include the ViaPHP package via Composer's autoloader.

Path Joining Utility
--------------------

[](#path-joining-utility)

ViaPHP includes a powerful path joining utility that works independently of the configured path system:

### Via::j() Method

[](#viaj-method)

The `Via::j()` method provides arbitrary path joining with cross-platform canonicalization:

```
// Basic path joining
Via::j('/base/path', 'subdir/file.txt');  // → '/base/path/subdir/file.txt'

// Path canonicalization (cleans messy paths)
Via::j('/base/path', '../parent/file.txt');     // → '/base/parent/file.txt'
Via::j('/base/path', './current//file.txt');    // → '/base/path/current/file.txt'

// Cross-platform separator handling
Via::j('/base/path', 'subdir\\file.txt');       // → '/base/path/subdir/file.txt'

// Null and empty handling
Via::j('/base/path', null);  // → '/base/path'
Via::j('/base/path', '');    // → '/base/path'
```

### Global Function: via\_join()

[](#global-function-via_join)

For maximum template convenience, use the global `via_join()` function:

```
// Identical to Via::j() but more concise in templates
$cssPath = via_join('/public/assets', 'css/main.css');
$logFile = via_join('/var/log/app', date('Y-m-d') . '.log');

// Perfect for HTML templates
echo '';
```

**Key Features:**

- **Independent Operation**: Works without any Via configuration
- **Cross-Platform**: Handles various path separators (/, , mixed)
- **Path Canonicalization**: Cleans up messy paths with `..`, `./`, `//`
- **Null Safety**: Gracefully handles null and empty additional paths
- **Symfony Powered**: Uses Symfony Path component for reliable canonicalization

This utility complements the configured path system by providing flexible arbitrary path joining for dynamic path construction scenarios.

---

Implemetation Notes
-------------------

[](#implemetation-notes)

Under the hood we use

- [`symfony/filesystem`](https://symfony.com/doc/current/components/filesystem.html#path-manipulation-utilities)'s [`Path::class`](https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/Filesystem/Path.php) methods for concatenating and cannonicalizing paths when assigning/setting and before returning them.
- [`dflydev/dot-access-data`](https://github.com/dflydev/dflydev-dot-access-data) [`Data` methods](https://github.com/dflydev/dflydev-dot-access-data/blob/main/src/Data.php) for setting an internal representation and parsing and resolving `Via::p()` requests from it.

---

Testing
-------

[](#testing)

This package uses the Pest PHP testing framework.

- ["Writing Tests" Guide](https://pestphp.com/docs/writing-tests)
- [Source](https://github.com/pestphp/pest)
- [Documentation source](https://github.com/pestphp/docs)

Tests are located in `./tests`

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance76

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

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

Recently: every ~42 days

Total

16

Last Release

130d ago

Major Versions

v0.1.3 → v1.0.02025-08-23

### Community

Maintainers

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

---

Top Contributors

[![BorisAnthony](https://avatars.githubusercontent.com/u/964649?v=4)](https://github.com/BorisAnthony "BorisAnthony (27 commits)")

---

Tags

helperpathsutilitiesphp8aliasescross-platformCanonicalizationpath-joining

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/diversified-design-viaphp/health.svg)

```
[![Health](https://phpackages.com/badges/diversified-design-viaphp/health.svg)](https://phpackages.com/packages/diversified-design-viaphp)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[symfony/config

Helps you find, load, combine, autofill and validate configuration values of any kind

4.3k479.6M8.5k](/packages/symfony-config)[drush/drush

Drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt.

2.4k60.6M804](/packages/drush-drush)[symfony/asset-mapper

Maps directories of assets &amp; makes them available in a public directory with versioned filenames.

1678.8M238](/packages/symfony-asset-mapper)[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.5k78.3k90](/packages/pocketmine-pocketmine-mp)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k53](/packages/friendsoftypo3-content-blocks)

PHPackages © 2026

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