xdg/base-directory

XDG Base Directory 规范的实现

1.2 2023-03-02 08:43 UTC

This package is auto-updated.

Last update: 2024-09-15 13:34:11 UTC


README

codecov

PHP 实现了 XDG Base Directory 规范,为非 Linux 平台提供合理的默认值。

安装

composer require xdg/base-directory

使用

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(...));

查看所有可用的平台方法,请参阅 PlatformInterface

Windows 和 macOS 平台的默认值

在大多数 Unix 平台上,通常已经定义了 XDG 环境变量,但在 Windows 和 macOS 上通常不是这样。

这个库选择偏离规范,并在这些平台上提供合理的默认值。

Windows

在 Windows 上,如果未设置 XDG 环境变量,我们首先尝试找到匹配的 已知文件夹

如果已知文件夹未定义,我们将尝试回退到特定的 Windows 环境变量,然后回退到静态默认值

MacOS