Download the PHP package baraja-core/path-resolvers without Composer
On this page you can find all versions of the php package baraja-core/path-resolvers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download baraja-core/path-resolvers
More information about baraja-core/path-resolvers
Files in baraja-core/path-resolvers
Package path-resolvers
Short Description 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.
License
Homepage https://github.com/baraja-core/path-resolvers
Informations about the package 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
- 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
The package follows a hierarchical resolver pattern where each resolver can depend on others:
π§© Components
VendorResolver
The core resolver that detects the Composer vendor directory. It uses multiple detection strategies:
- Primary method: Reflects on
Composer\Autoload\ClassLoaderto find its file location - CLI fallback: For PHAR or system-installed PHP, uses debug backtrace to locate vendor
- Error handling: Throws
RuntimeExceptionif vendor cannot be detected
RootDirResolver
Resolves the project root directory by getting the parent directory of vendor. Supports custom path appending.
WwwDirResolver
Resolves the public web directory. Uses intelligent detection:
- If custom
wwwDiris provided via constructor, uses that - If called from
index.php, returns its directory - Falls back to
{root}/www
TempDirResolver
Resolves the temporary directory. Supports custom paths and directory names.
LogDirResolver
Resolves the log directory. Supports custom paths and directory names.
π¦ Installation
It's best to use Composer for installation, and you can also find the package on Packagist and GitHub.
To install, simply use the command:
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
- PHP 8.0 or higher
- Nette DI 3.0+ (for DIC integration)
- Composer autoloader
π Basic Usage
With Nette Framework (Recommended)
Register the extension in your config.neon:
All resolvers are automatically registered as services and can be injected:
Standalone Usage (Without Nette)
You can use the resolvers without the DI extension:
βοΈ Configuration
Custom Paths via DI
Override default paths in your Nette configuration:
Constructor Parameters
| Resolver | Parameter | Type | Default | Description |
|---|---|---|---|---|
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
Storing Cache Files
Writing Log Files
Serving Static Files
Project Configuration
π§ Technical Details
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
The VendorResolver uses static caching to prevent redundant filesystem operations:
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
Jan BarΓ‘Ε‘ek https://baraja.cz
π License
baraja-core/path-resolvers is licensed under the MIT license. See the LICENSE file for more details.