major refactoring under the hood
[pharext/pharext] / src / pharext / Task / Askpass.php
diff --git a/src/pharext/Task/Askpass.php b/src/pharext/Task/Askpass.php
new file mode 100644 (file)
index 0000000..24b22da
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\Task;
+
+/**
+ * Ask password on console
+ */
+class Askpass implements Task
+{
+       /**
+        * @var string
+        */
+       private $prompt;
+
+       /**
+        * @param string $prompt
+        */
+       public function __construct($prompt = "Password:") {
+               $this->prompt = $prompt;
+       }
+
+       /**
+        * @param bool $verbose
+        * @return string
+        */
+       public function run($verbose = false) {
+               system("stty -echo");
+               printf("%s ", $this->prompt);
+               $pass = fgets(STDIN, 1024);
+               printf("\n");
+               system("stty echo");
+               if (substr($pass, -1) == "\n") {
+                       $pass = substr($pass, 0, -1);
+               }
+               return $pass;
+       }
+}
\ No newline at end of file