-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigPaths.php
90 lines (77 loc) · 2.01 KB
/
ConfigPaths.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
namespace Itineris\Preflight;
use function WP_CLI\Utils\normalize_path;
use function WP_CLI\Utils\trailingslashit;
class ConfigPaths
{
public const HOOK = 'preflight_config_paths_register';
/**
* Returns the paths to the .toml config files.
*
* @return string[]
*/
public static function all(): array
{
$paths = array_map(function (string $path): string {
return normalize_path($path);
}, apply_filters(self::HOOK, []));
return array_values(
array_filter($paths, function (string $path): bool {
return file_exists($path);
})
);
}
/**
* Register default.toml.
*
* Used in self::HOOK.
*
* @param array $paths The .toml config file paths.
*
* @return string[]
*/
public static function mergeDefaultPath(array $paths): array
{
$paths[] = normalize_path(
dirname(__FILE__, 2) . '/config/default.toml'
);
return $paths;
}
/**
* Register preflight.toml under ABSPATH.
*
* Used in self::HOOK.
*
* @param array $paths The .toml config file paths.
*
* @return string[]
*/
public static function mergeAbsPath(array $paths): array
{
if (defined('ABSPATH')) {
$dir = constant('ABSPATH');
$path = trailingslashit($dir) . 'preflight.toml';
$paths[] = normalize_path($path);
}
return $paths;
}
/**
* Register preflight.toml under PREFLIGHT_DIR.
*
* Used in self::HOOK.
*
* @param array $paths The .toml config file paths.
*
* @return string[]
*/
public static function mergePreflightDir(array $paths): array
{
if (defined('PREFLIGHT_DIR')) {
$dir = constant('PREFLIGHT_DIR');
$path = trailingslashit($dir) . 'preflight.toml';
$paths[] = normalize_path($path);
}
return $paths;
}
}