el7cosmos / dirs
PHP Wrapper for dirs-rs
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Type:php-ext
README
A PHP extension that provides access to platform-specific directory paths by wrapping the Rust dirs-rs crate.
Installation
You can install this extension using Pie:
pie install el7cosmos/dirs
Building from Source
Requirements
- PHP 8.0 or higher
- Rust toolchain
Build
phpize ./configure make
Install
make install
Functions
This extension provides the following functions to retrieve platform-specific directory paths:
Base Directories
home_dir()
: Returns the path to the user's home directorycache_dir()
: Returns the path to the user's cache directoryconfig_dir()
: Returns the path to the user's config directoryconfig_local_dir()
: Returns the path to the user's local config directorydata_dir()
: Returns the path to the user's data directorydata_local_dir()
: Returns the path to the user's local data directoryexecutable_dir()
: Returns the path to the user's executable directorypreference_dir()
: Returns the path to the user's preference directoryruntime_dir()
: Returns the path to the user's runtime directorystate_dir()
: Returns the path to the user's state directory
User Directories
audio_dir()
: Returns the path to the user's audio directorydesktop_dir()
: Returns the path to the user's desktop directorydocument_dir()
: Returns the path to the user's document directorydownload_dir()
: Returns the path to the user's download directoryfont_dir()
: Returns the path to the user's font directorypicture_dir()
: Returns the path to the user's picture directorypublic_dir()
: Returns the path to the user's public directorytemplate_dir()
: Returns the path to the user's template directoryvideo_dir()
: Returns the path to the user's video directory
All functions return either a string containing the path or null
if the directory could not be determined.
Example Usage
<?php // Get user's home directory $home = home_dir(); echo $home; // e.g., "/home/username" // Get downloads directory $downloads = download_dir(); echo $downloads; // e.g., "/home/username/Downloads"
Platform Support
This extension supports the following platforms:
- Linux
- macOS
The behavior on each platform follows the dirs-rs implementation.