Beispiel #1
0
 public function render()
 {
     switch ($this->mode) {
         case Shell::SHELL_SAFE:
             return $this->argument;
         case Shell::SHELL_ARG_MULTIPLE:
             $ret = '';
             if (isset($this->value)) {
                 $sub_conf = isset($this->conf['each']) ? $this->conf['each'] : array('mode' => NULL, 'delimiter' => NULL);
                 $sub_type = $sub_conf['mode'];
                 foreach ((array) $this->value as $part) {
                     $sub = Shell::arg($this->argument, $sub_type, $part, $sub_conf);
                     $tmp = $sub->render();
                     if ($tmp != '') {
                         $ret .= ' ' . $tmp;
                     }
                 }
             }
             return $ret;
         case Shell::SHELL_OPTIONS:
             $output = '';
             foreach ($this->value as $opt) {
                 $tmp = Shell::arg($opt['name'], $opt['mode'] ? $opt['mode'] : Shell::SHELL_ARG_BASIC, $opt['value'], $opt)->render();
                 if ($tmp !== '') {
                     $output .= ' ' . $tmp;
                 }
             }
             return $output;
         case Shell::SHELL_ARG_BOOL_DBL:
             if ($this->value) {
                 return escapeshellarg('--' . $this->argument);
             }
             return '';
         case Shell::SHELL_ARG_BOOL_SGL:
             if ($this->value) {
                 return escapeshellarg('-' . $this->argument);
             }
             return '';
         case Shell::SHELL_ARG_BASIC_DBL:
             if (isset($this->value)) {
                 return escapeshellarg('--' . $this->argument . '=' . $this->value);
             }
             return '';
         case Shell::SHELL_ARG_BASIC_DBL_NOEQUAL:
             if (isset($this->value)) {
                 return escapeshellarg('--' . $this->argument) . ' ' . escapeshellarg($this->value);
             }
             return '';
         case Shell::SHELL_ARG_PAIR_DBL_NOEQUAL:
             if (isset($this->value)) {
                 $ret = escapeshellarg('--' . $this->argument);
                 $delim = isset($this->conf['delimiter']) ? $this->conf['delimiter'] : ':';
                 $parts = explode($delim, $this->value, 2);
                 foreach ($parts as $part) {
                     $ret .= ' ' . escapeshellarg($part);
                 }
                 return $ret;
             }
             return '';
         case Shell::SHELL_ARG_BASIC_SGL:
             if (isset($this->value)) {
                 return escapeshellarg('-' . $this->argument) . ' ' . escapeshellarg($this->value);
             }
             return '';
         case Shell::SHELL_STDERR:
             return '2>' . escapeshellarg($this->value);
         case Shell::SHELL_ARG_BASIC:
         default:
             return escapeshellarg($this->argument);
     }
 }