Utils.php
2.6 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
<?php
/**
* @copyright Copyright 2012-2014 Rackspace US, Inc.
See COPYING for licensing information.
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
* @version 1.5.9
* @author Glen Campbell <glen.campbell@rackspace.com>
* @author Jamie Hannaford <jamie.hannaford@rackspace.com>
*/
namespace OpenCloud\Smoke;
/**
* Description of Utils
*
* @link
*/
class Utils
{
/**
* Basic logging function.
*
* @param string $string
*/
public static function log($string)
{
echo $string . PHP_EOL;
}
public static function convertArgsToString(array $args)
{
$format = $args[0];
unset($args[0]);
return vsprintf($format, $args);
}
/**
* A logging function similar to sprintf(). Accepts a format string as a
* first argument, and an array as a second argument to stock the format.
*/
public static function logf()
{
$string = self::convertArgsToString(func_get_args());
return self::log($string);
}
public static function logd()
{
return self::log(PHP_EOL . Enum::DIVIDER);
}
/**
* Outputs help.
*/
public static function help()
{
$output = <<<EOF
Switches:
-D --debug Turn debug mode ON
-H --help Display help message
-A --all Show all possible units to run
-I --include Include a particular unit
-E --exclude Exclude a particular unit
To exclude/include multiple units, either repeat the switch:
php Runner.php -Iautoscale --include="compute"
Or pass in a string delimeted with commas:
php Runner.php -Iautoscale,compute,queues
EOF;
return self::log($output);
}
public static function getEnvVar($name, $prefix = Enum::ENV_PREFIX)
{
if (empty($_ENV)) {
throw new SmokeException(
'Your $_ENV superglobals are empty. Please check your php.ini file.'
);
}
return (!isset($_ENV[$prefix . $name])) ? false : $_ENV[$prefix . $name];
}
public static function getRegion()
{
if (false !== ($region = self::getEnvVar(Enum::ENV_REGION))) {
return $region;
} else {
return Enum::DEFAULT_REGION;
}
}
public static function getIdentityEndpoint()
{
if (false !== ($endpoint = self::getEnvVar(Enum::ENV_IDENTITY_ENDPOINT))) {
return $endpoint;
} else {
return \OpenCloud\Rackspace::US_IDENTITY_ENDPOINT;
}
}
}