Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.74% |
18 / 19 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
Locator | |
94.74% |
18 / 19 |
|
75.00% |
3 / 4 |
6.01 | |
0.00% |
0 / 1 |
getLocalConfigPath | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getBaseConfigPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getConfigPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPathResolver | |
93.33% |
14 / 15 |
|
0.00% |
0 / 1 |
3.00 |
1 | <?php |
2 | |
3 | /** |
4 | * VuFind Configuration Locator - A static compatibility wrapper around PathResolver |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Config |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org Main Site |
28 | */ |
29 | |
30 | namespace VuFind\Config; |
31 | |
32 | use function defined; |
33 | use function strlen; |
34 | |
35 | /** |
36 | * VuFind Configuration Locator - A static compatibility wrapper around PathResolver |
37 | * |
38 | * @category VuFind |
39 | * @package Config |
40 | * @author Demian Katz <demian.katz@villanova.edu> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org Main Site |
43 | */ |
44 | class Locator |
45 | { |
46 | /** |
47 | * Get the file path to the local configuration file (null if none found). |
48 | * |
49 | * @param string $filename config file name |
50 | * @param ?string $path path relative to VuFind base (optional; use null for |
51 | * default) |
52 | * @param bool $force force method to return path even if file does not |
53 | * exist (default = false, do not force) |
54 | * |
55 | * @return ?string |
56 | * |
57 | * @deprecated Use PathResolver instead |
58 | */ |
59 | public static function getLocalConfigPath( |
60 | $filename, |
61 | $path = null, |
62 | $force = false |
63 | ) { |
64 | return static::getPathResolver() |
65 | ->getLocalConfigPath($filename, $path, $force); |
66 | } |
67 | |
68 | /** |
69 | * Get the file path to the base configuration file. |
70 | * |
71 | * @param string $filename config file name |
72 | * @param ?string $path path relative to VuFind base (optional; use null for |
73 | * default) |
74 | * |
75 | * @return string |
76 | * |
77 | * @deprecated Use PathResolver instead |
78 | */ |
79 | public static function getBaseConfigPath($filename, $path = null) |
80 | { |
81 | return static::getPathResolver()->getBaseConfigPath($filename, $path); |
82 | } |
83 | |
84 | /** |
85 | * Get the file path to a config file. |
86 | * |
87 | * @param string $filename Config file name |
88 | * @param ?string $path Path relative to VuFind base (optional; use null for |
89 | * default) |
90 | * |
91 | * @return string |
92 | * |
93 | * @deprecated Use PathResolver instead |
94 | */ |
95 | public static function getConfigPath($filename, $path = null) |
96 | { |
97 | return static::getPathResolver()->getConfigPath($filename, $path); |
98 | } |
99 | |
100 | /** |
101 | * Get a PathResolver with default configuration file paths |
102 | * |
103 | * @return PathResolver |
104 | */ |
105 | protected static function getPathResolver(): PathResolver |
106 | { |
107 | $localDirs = defined('LOCAL_OVERRIDE_DIR') |
108 | && strlen(trim(LOCAL_OVERRIDE_DIR)) > 0 |
109 | ? [ |
110 | [ |
111 | 'directory' => LOCAL_OVERRIDE_DIR, |
112 | 'defaultConfigSubdir' => PathResolver::DEFAULT_CONFIG_SUBDIR, |
113 | ], |
114 | ] : []; |
115 | return new \VuFind\Config\PathResolver( |
116 | [ |
117 | 'directory' => APPLICATION_PATH, |
118 | 'defaultConfigSubdir' => PathResolver::DEFAULT_CONFIG_SUBDIR, |
119 | ], |
120 | $localDirs |
121 | ); |
122 | } |
123 | } |