xdg / base-directory
Implementation of the XDG Base Directory Specification
1.2
2023-03-02 08:43 UTC
Requires
- php: >=8.1
- symfony/filesystem: ^5.4||^6.0
- xdg/environment: ^2.0
README
PHP implementation of the XDG Base Directory Specification, with sensible default fallbacks for non-linux platforms.
Installation
composer require xdg/base-directory
Usage
use Xdg\BaseDirectory\XdgBaseDirectory; // we start by instantiating a platform: $platform = XdgBaseDirectory::fromEnvironment(); // get the XDG_CONFIG_HOME directory $configHome = $platform->getConfigHome(); // find the most user-specific existing configuration file: $configPath = $platform->findConfigPath('my-app/config.json', \file_exists(...));
See the PlatformInterface for all available platform methods.
Fallback values for Windows and macOS platforms
While on most Unix platforms, the XDG environment variables are usually defined, this is typically not the case on Windows and macOS.
This library choses to deviate from the spec and provide sensible defaults on those platforms.
Windows
On windows, when an XDG environment variable is not set, we first try to find a matching Known Folder:
If the known folder is not defined, we then try to fall back to a windows-specific environment variable, then fall back to a static default: