Commit | Line | Data |
---|---|---|
4bcd4c62 TO |
1 | <?php |
2 | namespace Civi\Setup; | |
3 | ||
4 | class PackageUtil { | |
5 | ||
6 | /** | |
7 | * Locate the civicrm-packages source tree. | |
8 | * | |
9 | * @param string $srcPath | |
10 | * The path to the civicrm-core source tree. | |
11 | * @return string | |
12 | * The path to the civicrm-packages source tree. | |
13 | */ | |
14 | public static function getPath($srcPath) { | |
15 | global $civicrm_paths; | |
16 | ||
17 | $candidates = [ | |
18 | // TODO: Trace the code-path and allow reading $model for packages dir? | |
19 | $civicrm_paths['civicrm.packages']['path'] ?? NULL, | |
20 | implode(DIRECTORY_SEPARATOR, [$srcPath, 'packages']), | |
21 | implode(DIRECTORY_SEPARATOR, [dirname($srcPath), 'civicrm-packages']), | |
22 | ]; | |
23 | ||
24 | foreach ($candidates as $candidate) { | |
25 | if (!empty($candidate) && file_exists($candidate)) { | |
26 | return $candidate; | |
27 | } | |
28 | } | |
29 | ||
30 | throw new \RuntimeException("Failed to locate civicrm-packages"); | |
31 | } | |
32 | ||
33 | } |