Exemplo n.º 1
0
 public static function selectWithKeys(array $options, $prompt = 'SELECT>', LogInterface &$log)
 {
     \apf\validate\String::mustBeString($prompt, 'Given prompt must be a string');
     $amountOfOptions = sizeof($options);
     $len = 0;
     foreach ($options as $key => $opt) {
         $len = strlen($key) > $len ? strlen($key) : $len;
     }
     $len += 3;
     while (TRUE) {
         foreach ($options as $key => $opt) {
             if (is_array($opt)) {
                 if (isset($opt['color'])) {
                     $log->log(sprintf('%s)%s%s', $key, str_repeat(' ', $len), $opt['value']), $type = 0, $opt['color']);
                 }
             } else {
                 $log->info(sprintf('%s)%s%s', $key, str_repeat(' ', $len), $opt));
             }
         }
         $selected = strtolower(trim(self::input($prompt, $log), "\r\n"));
         foreach ($options as $key => $opt) {
             if (strtolower($key) == $selected) {
                 return $key;
             }
         }
     }
 }