-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathToolkit.php
115 lines (101 loc) · 2.6 KB
/
Toolkit.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
declare(strict_types=1);
namespace EcEuropa\Toolkit;
use Composer\InstalledVersions;
/**
* Provides default Toolkit class.
*/
final class Toolkit
{
/**
* Constant holding the current version.
*/
public const VERSION = '10.17.0';
/**
* The Toolkit repository.
*/
public const REPOSITORY = 'ec-europa/toolkit';
/**
* The Toolkit composer plugin repository.
*/
public const PLUGIN = 'ec-europa/toolkit-composer-plugin';
/**
* Returns the Toolkit root.
*
* @return string
* The Toolkit root.
*/
public static function getToolkitRoot(): string
{
return realpath(InstalledVersions::getInstallPath(self::REPOSITORY));
}
/**
* Returns the Project root.
*
* @return string
* The Project root.
*/
public static function getProjectRoot(): string
{
return realpath(InstalledVersions::getRootPackage()['install_path']);
}
/**
* Returns whether is running in CI/CD environment.
*
* @return bool
* True if running in CI/CD, false otherwise.
*/
public static function isCiCd(): bool
{
$ci = getenv('CI');
return !empty($ci) && ($ci === 'true' || $ci === 'drone');
}
/**
* Returns the NEXTCLOUD user.
*
* @return string
* The NEXTCLOUD user.
*/
public static function getNextcloudUser(): string
{
$user = getenv('NEXTCLOUD_USER');
return !empty($user) && $user !== '${env.NEXTCLOUD_USER}' ? $user : '';
}
/**
* Returns the NEXTCLOUD password.
*
* @return string
* The NEXTCLOUD password.
*/
public static function getNextcloudPass(): string
{
$pass = getenv('NEXTCLOUD_PASS');
return !empty($pass) && $pass !== '${env.NEXTCLOUD_PASS}' ? $pass : '';
}
/**
* Remove un-existing folders from given array.
*
* @param array $files
* The folders to check.
*/
public static function filterFolders(array &$files)
{
$files = array_values(array_filter($files, function ($folder) {
return file_exists($folder);
}));
}
/**
* If given content is a string, it will be exploded by given separator.
*
* @param mixed $data
* If the data is a string it will be exploded by comma.
* @param string $sep
* The separator to explode the string.
*/
public static function ensureArray(mixed &$data, string $sep = ',')
{
if (is_string($data)) {
$data = array_map('trim', explode($sep, $data));
}
}
}