24b22da0d4631ce9fcc739db82538c6ecaaf3f36
[pharext/pharext] / src / pharext / Task / Askpass.php
1 <?php
2
3 namespace pharext\Task;
4
5 use pharext\Exception;
6 use pharext\Task;
7
8 /**
9 * Ask password on console
10 */
11 class Askpass implements Task
12 {
13 /**
14 * @var string
15 */
16 private $prompt;
17
18 /**
19 * @param string $prompt
20 */
21 public function __construct($prompt = "Password:") {
22 $this->prompt = $prompt;
23 }
24
25 /**
26 * @param bool $verbose
27 * @return string
28 */
29 public function run($verbose = false) {
30 system("stty -echo");
31 printf("%s ", $this->prompt);
32 $pass = fgets(STDIN, 1024);
33 printf("\n");
34 system("stty echo");
35 if (substr($pass, -1) == "\n") {
36 $pass = substr($pass, 0, -1);
37 }
38 return $pass;
39 }
40 }