PHPackages                             baraja-core/path-resolvers - 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. baraja-core/path-resolvers

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

baraja-core/path-resolvers
==========================

A group of intelligent DI services that provide disk paths to important locations such as tempDir, wwwDir, vendorDir, logDir and other system constants for your applications. Dependency management can be easily solved from one place.

v1.0.2(3y ago)2156.5k4PHPPHP ^8.0CI passing

Since Feb 28Pushed 4mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (8)Versions (6)Used By (4)

🗂️ Path Resolvers
=================

[](#️-path-resolvers)

A group of intelligent DI services that provide disk paths to important locations such as `tempDir`, `wwwDir`, `vendorDir`, `logDir` and other system constants for your applications. Dependency management can be easily solved from one place.

🎯 Key Features
--------------

[](#-key-features)

- **Automatic path detection** - Uses Composer's ClassLoader reflection to automatically detect the vendor directory
- **Zero configuration** - Works out of the box with Nette Framework via DIC extension
- **CLI and Web support** - Properly detects paths in both CLI and web server environments
- **PHAR archive support** - Special handling for applications bundled in PHAR archives
- **Cross-platform compatibility** - Normalizes directory separators for Windows and Unix systems
- **Performance optimized** - Static caching prevents redundant path resolution
- **Customizable** - Override any path via constructor injection or DI configuration
- **Type-safe** - Fully typed with PHP 8.0+ support and PHPStan level 8 compatibility

🏗️ Architecture
---------------

[](#️-architecture)

The package follows a hierarchical resolver pattern where each resolver can depend on others:

```
┌─────────────────────────────────────────────────────────────┐
│                    PathResolverExtension                    │
│                  (Nette DI CompilerExtension)               │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                      VendorResolver                         │
│            (Core resolver - detects vendor dir)             │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                     RootDirResolver                         │
│          (Derives root from vendor - parent dir)            │
└─────────────────────────────────────────────────────────────┘
                              │
              ┌───────────────┼───────────────┐
              ▼               ▼               ▼
┌───────────────────┐ ┌─────────────┐ ┌─────────────┐
│   WwwDirResolver  │ │TempDirResolver│ │LogDirResolver │
│   (www/ or auto)  │ │  (temp/)    │ │   (log/)    │
└───────────────────┘ └─────────────┘ └─────────────┘

```

🧩 Components
------------

[](#-components)

### VendorResolver

[](#vendorresolver)

The core resolver that detects the Composer vendor directory. It uses multiple detection strategies:

1. **Primary method**: Reflects on `Composer\Autoload\ClassLoader` to find its file location
2. **CLI fallback**: For PHAR or system-installed PHP, uses debug backtrace to locate vendor
3. **Error handling**: Throws `RuntimeException` if vendor cannot be detected

```
$vendorResolver = new VendorResolver();
$vendorPath = $vendorResolver->get(); // e.g., "/var/www/project/vendor"
```

### RootDirResolver

[](#rootdirresolver)

Resolves the project root directory by getting the parent directory of vendor. Supports custom path appending.

```
$rootResolver = new RootDirResolver($vendorResolver);
$rootPath = $rootResolver->get();           // e.g., "/var/www/project"
$configPath = $rootResolver->get('config'); // e.g., "/var/www/project/config"
```

### WwwDirResolver

[](#wwwdirresolver)

Resolves the public web directory. Uses intelligent detection:

1. If custom `wwwDir` is provided via constructor, uses that
2. If called from `index.php`, returns its directory
3. Falls back to `{root}/www`

```
$wwwResolver = new WwwDirResolver($rootResolver);
$wwwPath = $wwwResolver->get(); // e.g., "/var/www/project/www"

// Or with custom path
$wwwResolver = new WwwDirResolver($rootResolver, '/custom/public');
```

### TempDirResolver

[](#tempdirresolver)

Resolves the temporary directory. Supports custom paths and directory names.

```
$tempResolver = new TempDirResolver($rootResolver);
$tempPath = $tempResolver->get();          // e.g., "/var/www/project/temp"
$cachePath = $tempResolver->get('cache');  // e.g., "/var/www/project/temp/cache"

// Custom temp directory name
$tempResolver = new TempDirResolver($rootResolver, null, 'tmp');
$tempPath = $tempResolver->get(); // e.g., "/var/www/project/tmp"
```

### LogDirResolver

[](#logdirresolver)

Resolves the log directory. Supports custom paths and directory names.

```
$logResolver = new LogDirResolver($rootResolver);
$logPath = $logResolver->get();           // e.g., "/var/www/project/log"
$errorLog = $logResolver->get('error');   // e.g., "/var/www/project/log/error"

// Custom log directory name
$logResolver = new LogDirResolver($rootResolver, null, 'logs');
$logPath = $logResolver->get(); // e.g., "/var/www/project/logs"
```

📦 Installation
--------------

[](#-installation)

It's best to use [Composer](https://getcomposer.org) for installation, and you can also find the package on [Packagist](https://packagist.org/packages/baraja-core/path-resolvers) and [GitHub](https://github.com/baraja-core/path-resolvers).

To install, simply use the command:

```
$ composer require baraja-core/path-resolvers
```

You can use the package manually by creating an instance of the internal classes, or register a DIC extension to link the services directly to the Nette Framework.

### Requirements

[](#requirements)

- PHP 8.0 or higher
- Nette DI 3.0+ (for DIC integration)
- Composer autoloader

🚀 Basic Usage
-------------

[](#-basic-usage)

### With Nette Framework (Recommended)

[](#with-nette-framework-recommended)

Register the extension in your `config.neon`:

```
extensions:
    pathResolver: Baraja\PathResolver\PathResolverExtension
```

All resolvers are automatically registered as services and can be injected:

```
use Baraja\PathResolvers\Resolvers\TempDirResolver;
use Baraja\PathResolvers\Resolvers\LogDirResolver;

final class MyService
{
    public function __construct(
        private TempDirResolver $tempResolver,
        private LogDirResolver $logResolver,
    ) {
    }

    public function getCacheDir(): string
    {
        return $this->tempResolver->get('cache');
    }

    public function getErrorLogPath(): string
    {
        return $this->logResolver->get('error.log');
    }
}
```

### Standalone Usage (Without Nette)

[](#standalone-usage-without-nette)

You can use the resolvers without the DI extension:

```
use Baraja\PathResolvers\Resolvers\VendorResolver;
use Baraja\PathResolvers\Resolvers\RootDirResolver;
use Baraja\PathResolvers\Resolvers\TempDirResolver;
use Baraja\PathResolvers\Resolvers\LogDirResolver;
use Baraja\PathResolvers\Resolvers\WwwDirResolver;

// Create resolvers manually
$vendorResolver = new VendorResolver();
$rootResolver = new RootDirResolver($vendorResolver);
$tempResolver = new TempDirResolver($rootResolver);
$logResolver = new LogDirResolver($rootResolver);
$wwwResolver = new WwwDirResolver($rootResolver);

// Use them
echo $rootResolver->get();        // /var/www/project
echo $tempResolver->get('cache'); // /var/www/project/temp/cache
echo $logResolver->get();         // /var/www/project/log
echo $wwwResolver->get();         // /var/www/project/www
```

⚙️ Configuration
----------------

[](#️-configuration)

### Custom Paths via DI

[](#custom-paths-via-di)

Override default paths in your Nette configuration:

```
services:
    pathResolver.tempResolver:
        factory: Baraja\PathResolvers\Resolvers\TempDirResolver
        arguments:
            tempDir: %tempDir%
            tempDirName: 'tmp'

    pathResolver.logResolver:
        factory: Baraja\PathResolvers\Resolvers\LogDirResolver
        arguments:
            logDir: %logDir%
            logDirName: 'logs'

    pathResolver.wwwResolver:
        factory: Baraja\PathResolvers\Resolvers\WwwDirResolver
        arguments:
            wwwDir: %wwwDir%
```

### Constructor Parameters

[](#constructor-parameters)

ResolverParameterTypeDefaultDescription`TempDirResolver``tempDir``?string``null`Custom absolute path to temp directory`TempDirResolver``tempDirName``string``'temp'`Directory name relative to root`LogDirResolver``logDir``?string``null`Custom absolute path to log directory`LogDirResolver``logDirName``string``'log'`Directory name relative to root`WwwDirResolver``wwwDir``?string``null`Custom absolute path to www directory💡 Use Cases
-----------

[](#-use-cases)

### Storing Cache Files

[](#storing-cache-files)

```
public function __construct(private TempDirResolver $tempResolver) {}

public function getCacheFile(string $key): string
{
    return $this->tempResolver->get('cache/' . md5($key) . '.cache');
}
```

### Writing Log Files

[](#writing-log-files)

```
public function __construct(private LogDirResolver $logResolver) {}

public function writeLog(string $message): void
{
    $logFile = $this->logResolver->get('app.log');
    file_put_contents($logFile, $message . "\n", FILE_APPEND);
}
```

### Serving Static Files

[](#serving-static-files)

```
public function __construct(private WwwDirResolver $wwwResolver) {}

public function getAssetPath(string $asset): string
{
    return $this->wwwResolver->get() . '/assets/' . $asset;
}
```

### Project Configuration

[](#project-configuration)

```
public function __construct(private RootDirResolver $rootResolver) {}

public function getConfigPath(): string
{
    return $this->rootResolver->get('config/app.neon');
}
```

🔧 Technical Details
-------------------

[](#-technical-details)

### Path Normalization

[](#path-normalization)

All resolvers normalize directory separators using `DIRECTORY_SEPARATOR` for cross-platform compatibility:

- Windows: `C:\project\temp\cache`
- Unix/Linux: `/var/www/project/temp/cache`

### Caching

[](#caching)

The `VendorResolver` uses static caching to prevent redundant filesystem operations:

```
public function get(): string
{
    static $cache;
    return $cache ?? $cache = $this->detect();
}
```

### CLI Detection

[](#cli-detection)

For CLI environments running from PHAR archives or system-installed PHP, the vendor resolver uses debug backtrace as a fallback detection method.

👤 Author
--------

[](#-author)

**Jan Barášek**

📄 License
---------

[](#-license)

`baraja-core/path-resolvers` is licensed under the MIT license. See the [LICENSE](https://github.com/baraja-core/path-resolvers/blob/master/LICENSE) file for more details.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance52

Moderate activity, may be stable

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

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

Total

3

Last Release

1338d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3382204?v=4)[baraja](/maintainers/baraja)[@baraja](https://github.com/baraja)

---

Top Contributors

[![janbarasek](https://avatars.githubusercontent.com/u/4738758?v=4)](https://github.com/janbarasek "janbarasek (12 commits)")

---

Tags

diskdisk-pathsintelligent-di-serviceslogdirnettepathphptempdirvendorvendordirwwwdir

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/baraja-core-path-resolvers/health.svg)

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

###  Alternatives

[contributte/di

Extra contrib to nette/di

465.8M18](/packages/contributte-di)[contributte/event-dispatcher

Best event dispatcher / event manager / event emitter for Nette Framework

292.4M19](/packages/contributte-event-dispatcher)[contributte/menu-control

Menu control for Nette framework

29108.6k1](/packages/contributte-menu-control)[radekdostal/nette-datetimepicker

DatePicker and DateTimePicker input controls for Nette Framework

13272.2k3](/packages/radekdostal-nette-datetimepicker)[carrooi/nette-menu

Menu control for Nette framework

2950.0k1](/packages/carrooi-nette-menu)[bileto/cronner

Simple tool which helps with maintenance of cron tasks.

752.1k](/packages/bileto-cronner)

PHPackages © 2026

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