Skip to content

Commit eba4f39

Browse files
committed
up
1 parent 7953a60 commit eba4f39

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

examples/demo/constants.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Inhere
5+
* Date: 2018/1/10 0010
6+
* Time: 21:23
7+
*/
8+
9+
// Boolean true constants
10+
define('yes', true);
11+
define('ok', true);
12+
define('okay', true);
13+
define('', true);
14+
define('correct', true);
15+
define('👍', true);
16+
17+
// Boolean false constants
18+
define('no', false);
19+
define('not', false);
20+
define('', false);
21+
define('wrong', false);
22+
define('👎', false);
23+
24+
// Constants with a random boolean value
25+
define('maybe', (bool)random_int(0, 1));
26+
define('perhaps', (bool)random_int(0, 1));
27+
define('possibly', (bool)random_int(0, 2));
28+
define('unlikely', random_int(0, 99) < 20);

src/Utils/CliUtil.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,43 @@ public static function exec($command, $logfile = null, $user = null)
6868
return $dummy;
6969
}
7070

71+
/**
72+
* @param string $command
73+
* @return array
74+
*/
75+
public static function executeCommand($command)
76+
{
77+
$descriptors = [
78+
0 => ['pipe', 'r'], // stdin - read channel
79+
1 => ['pipe', 'w'], // stdout - write channel
80+
2 => ['pipe', 'w'], // stdout - error channel
81+
3 => ['pipe', 'r'], // stdin - This is the pipe we can feed the password into
82+
];
83+
84+
$process = proc_open($command, $descriptors, $pipes);
85+
86+
if (!\is_resource($process)) {
87+
die("Can't open resource with proc_open.");
88+
}
89+
90+
// Nothing to push to input.
91+
fclose($pipes[0]);
92+
93+
$output = stream_get_contents($pipes[1]);
94+
fclose($pipes[1]);
95+
96+
$error = stream_get_contents($pipes[2]);
97+
fclose($pipes[2]);
98+
99+
// TODO: Write passphrase in pipes[3].
100+
fclose($pipes[3]);
101+
102+
// Close all pipes before proc_close!
103+
$code = proc_close($process);
104+
105+
return [$output, $error, $code];
106+
}
107+
71108
/**
72109
* Method to execute a command in the sys
73110
* Uses :

0 commit comments

Comments
 (0)