1
1
<?php
2
2
// Copyright (C) 2016 Grzegorz Kowalski, see LICENSE file
3
3
4
- function llecho ($ message , $ ansi_color = '31m ' ) {
4
+ function ansi_color ($ R , $ G , $ B , $ bold = false ) {
5
+ return 30 + ($ R ?1 :0 ) + ($ G ?2 :0 ) + ($ B ?3 :0 ) + ($ bold ?40 :0 );
6
+ }
7
+
8
+ function ansi_str ($ message , $ code ) {
9
+ return '[ ' . $ code . 'm ' . $ message . '[0m ' ;
10
+ }
11
+
12
+ // llecho('my message');
13
+ // llech('my bold blue message', ansi_color(0, 0, 1, 1));
14
+ function llecho ($ message , $ ansi_color = '31 ' ) {
5
15
if (strpos (php_uname (), 'Windows 10 ' ) !== false ) {
6
16
system ('powershell "[Text.Encoding]::UTF8.GetString([convert]::FromBase64String(\" '
7
- . base64_encode (' [ ' . $ ansi_color . $ message . ' [0m ' )
17
+ . base64_encode (ansi_str ( $ message, $ ansi_color ) )
8
18
.'\")) ' );
9
19
} else {
10
20
echo "// $ message \n" ;
@@ -32,19 +42,11 @@ function execute_console_app($path, $process_function, $data = null)
32
42
if (is_resource ($ process )) {
33
43
$ return_value = $ process_function ($ data , $ pipes [0 ], $ pipes [1 ], $ pipes [2 ]);
34
44
35
- if (isset ($ pipes [2 ]) and is_resource ($ pipes [2 ])) {
36
- fclose ($ pipes [2 ]);
37
- unset($ pipes [2 ]);
38
- }
39
-
40
- if (isset ($ pipes [1 ]) and is_resource ($ pipes [1 ])) {
41
- fclose ($ pipes [1 ]);
42
- unset($ pipes [1 ]);
43
- }
44
-
45
- if (isset ($ pipes [0 ]) and is_resource ($ pipes [0 ])) {
46
- fclose ($ pipes [0 ]);
47
- unset($ pipes [0 ]);
45
+ foreach ([2 ,1 ,0 ] as $ i ) {
46
+ if (isset ($ pipes [$ i ]) and is_resource ($ pipes [$ i ])) {
47
+ fclose ($ pipes [$ i ]);
48
+ unset($ pipes [$ i ]);
49
+ }
48
50
}
49
51
50
52
$ results = Array (
@@ -112,9 +114,6 @@ function check_syntax($code, $print_error_message = false)
112
114
/* test: $fp = fopen("foo", "w") */
113
115
if (is_resource ($ _ )) llecho ('$_ is a resource of type ' . get_resource_type ($ _ ));
114
116
115
- /* test: $fp = fopen("foo", "w"); fclose($fp); $fp */
116
- if (gettype ($ _ ) == 'resource (closed) ' ) llecho ('$_ is a closed resource ' );
117
-
118
117
/* test: "test" */
119
118
if (is_string ($ _ )) llecho ('$_ is a string of length ' . strlen ($ _ ));
120
119
@@ -129,12 +128,28 @@ function check_syntax($code, $print_error_message = false)
129
128
/* test: null */
130
129
if (is_null ($ _ )) llecho ('$_ is null ' );
131
130
131
+ /* test: array() */
132
+ if (empty ($ _ )) llecho ('$_ is empty ' );
133
+
132
134
/* test: true */
133
135
if (is_bool ($ _ )) llecho ('$_ has boolean value of ' . ($ _ ? 'true ' : 'false ' ));
134
136
135
137
/* test: 0 */
136
138
if (is_numeric ($ _ )) llecho ('$_ has numeric value of ' . $ _ );
137
139
140
+ /* test: array() */
141
+ if (version_compare (phpversion (), '7.1.0 ' , '>= ' )) {
142
+ if (is_iterable ($ _ )) llecho ('$_ is iterable ' );
143
+ }
144
+
145
+ /* test: $fp = fopen("foo", "w"); fclose($fp); $fp */
146
+ if (version_compare (phpversion (), '7.2.0 ' , '>= ' )) {
147
+ if (gettype ($ _ ) == 'resource (closed) ' ) llecho ('$_ is a closed resource ' );
148
+ } else {
149
+ if (gettype ($ _ ) == 'unknown type ' ) llecho ('$_ is a closed resource ' );
150
+ }
151
+
152
+ /* test: array() */
138
153
if (version_compare (phpversion (), '7.3.0 ' , '>= ' )) {
139
154
if (is_countable ($ _ )) llecho ('$_ is countable and has count ' . count ($ _ ));
140
155
}
0 commit comments