-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagevalidator.php
More file actions
114 lines (101 loc) · 2.94 KB
/
magevalidator.php
File metadata and controls
114 lines (101 loc) · 2.94 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
<?php
// mage validator, used for performance review project.
// we will try to feet anything to the sinlge php file to
// avoid any dependencies and make deployment easier
/// phpansicolor, from the https://gist.github.com/superbrothers/3431198
echo "MageValidator v.0.0.1\n\n";
echo "PHP Version:\t".Color::set(PHP_VERSION,"green")."\n";
echo "PHP SAPI:\t".Color::set(PHP_SAPI,"green")."\n";
echo "PHP Extensions:\t".Color::set(join(", ", get_loaded_extensions()),"green")."\n";
echo "PHP Opcache:\t".get_php_opcache()."\n";
// find if php opcache is in use
function get_php_opcache(){
if (extension_loaded('Zend OPcache')){
$retval=Color::set("Zend Opcache","green")."\n";
// todo - print settings
return $retval;
}
elseif (extension_loaded('apc')){
$retval=Color::set("APC","green")."\n";
// todo - print settings
return $retval;
}
return Color::set("not found","red");
}
/**
* php-ansi-color
*
* Original
* https://github.com/loopj/commonjs-ansi-color
*
* @code
* <?php
* require_once "ansi-color.php";
*
* use PhpAnsiColor\Color;
*
* // Print the word "Error" to stdout in red
* error_log(Color::set("Error", "red"));
*
* // Print the word "Error" in red and underlined
* error_log(Color::set("Error", "red+underline"));
*
* // Print the word "Success" in bold green, followed by a message
* error_log(Color::set("Success", "green+bold"), "Something was successful!");
* @endcode
*/
// namespace PhpAnsiColor;
class Color
{
protected static $ANSI_CODES = array(
"off" => 0,
"bold" => 1,
"italic" => 3,
"underline" => 4,
"blink" => 5,
"inverse" => 7,
"hidden" => 8,
"black" => 30,
"red" => 31,
"green" => 32,
"yellow" => 33,
"blue" => 34,
"magenta" => 35,
"cyan" => 36,
"white" => 37,
"black_bg" => 40,
"red_bg" => 41,
"green_bg" => 42,
"yellow_bg" => 43,
"blue_bg" => 44,
"magenta_bg" => 45,
"cyan_bg" => 46,
"white_bg" => 47
);
public static function set($str, $color)
{
$color_attrs = explode("+", $color);
$ansi_str = "";
foreach ($color_attrs as $attr) {
$ansi_str .= "\033[" . self::$ANSI_CODES[$attr] . "m";
}
$ansi_str .= $str . "\033[" . self::$ANSI_CODES["off"] . "m";
return $ansi_str;
}
public static function log($message, $color)
{
error_log(self::set($message, $color));
}
public static function replace($full_text, $search_regexp, $color)
{
$new_text = preg_replace_callback(
"/($search_regexp)/",
function ($matches) use ($color) {
return Color::set($matches[1], $color);
},
$full_text
);
return is_null($new_text) ? $full_text : $new_text;
}
}
?>