Repository navigation
Expand file tree
/
Copy pathConfig.php
More file actions
175 lines (142 loc) · 4.41 KB
/
Copy pathConfig.php
File metadata and controls
175 lines (142 loc) · 4.41 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
namespace PhpBrew;
use Exception;
use Symfony\Component\Yaml\Yaml;
class Config
{
protected static $currentPhpVersion = null;
public static function getPhpbrewHome()
{
if ($custom = getenv('PHPBREW_HOME')) {
return $custom;
}
if ($home = getenv('HOME')) {
return $home . DIRECTORY_SEPARATOR . '.phpbrew';
}
throw new Exception('Environment variable PHPBREW_HOME or HOME is required');
}
public static function getPhpbrewRoot()
{
if ($root = getenv('PHPBREW_ROOT')) {
return $root;
}
if ($home = getenv('HOME')) {
return $home . DIRECTORY_SEPARATOR . '.phpbrew';
}
throw new Exception('Environment variable PHPBREW_ROOT is required');
}
/**
* Variants is private, so we use HOME path.
*/
public static function getVariantsDir()
{
return self::getPhpbrewHome() . DIRECTORY_SEPARATOR . 'variants';
}
/**
* php(s) could be global, so we use ROOT path.
*/
public static function getBuildDir()
{
return self::getPhpbrewRoot() . DIRECTORY_SEPARATOR . 'build';
}
public static function getDistFilesDir()
{
$dir = self::getPhpbrewRoot() . DIRECTORY_SEPARATOR . 'distfiles';
if (!file_exists($dir)) {
mkdir($dir, 0755, true);
}
return $dir;
}
public static function getPHPReleaseListPath() {
// Release list from php.net
return self::getPhpbrewRoot() . DIRECTORY_SEPARATOR . 'php-releases.json';
}
/**
* A build prefix is the prefix we specified when we install the PHP.
*
* @return string
*/
public static function getBuildPrefix()
{
return self::getPhpbrewRoot() . DIRECTORY_SEPARATOR . 'php';
}
public static function getVersionInstallPrefix($version)
{
return self::getBuildPrefix() . DIRECTORY_SEPARATOR . $version;
}
/**
* XXX: This method should be migrated to PhpBrew\Build class.
*
* @param string $version
*
* @return string
*/
public static function getVersionEtcPath($version)
{
return self::getVersionInstallPrefix($version) . DIRECTORY_SEPARATOR . 'etc';
}
public static function getVersionBinPath($version)
{
return self::getVersionInstallPrefix($version) . DIRECTORY_SEPARATOR . 'bin';
}
public static function getInstalledPhpVersions()
{
$versions = array();
$path = self::getPhpbrewRoot() . DIRECTORY_SEPARATOR . 'php';
if (file_exists($path) && $fp = opendir($path)) {
while (($item = readdir($fp)) !== false) {
if ($item == '.' || $item == '..') {
continue;
}
if (file_exists($path . DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'php')) {
$versions[] = $item;
}
}
closedir($fp);
}
return $versions;
}
/**
* XXX: This method should be migrated to PhpBrew\Build class.
*/
public static function getCurrentPhpConfigScanPath()
{
return self::getCurrentPhpDir() . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'db';
}
public static function getCurrentPhpDir()
{
return self::getPhpbrewRoot() . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR . self::getCurrentPhpName();
}
public static function useSystemPhpVersion()
{
self::$currentPhpVersion = null;
}
public static function setPhpVersion($phpVersion)
{
self::$currentPhpVersion = 'php-'.$phpVersion;
}
public static function getCurrentPhpName()
{
if (self::$currentPhpVersion !== null) {
return self::$currentPhpVersion;
}
return getenv('PHPBREW_PHP');
}
public static function getCurrentPhpBin()
{
return getenv('PHPBREW_PATH');
}
public static function getConfigParam($param = null)
{
$configFile = self::getPhpbrewRoot() . DIRECTORY_SEPARATOR . 'config.yaml';
$yaml = Yaml::parse($configFile);
if (is_array($yaml)) {
if ($param === null) {
return $yaml;
} elseif ($param != null && isset($yaml[$param])) {
return $yaml[$param];
}
}
return array();
}
}