Exemple #1
0
 /**
  * Returns a standard help output for your program.
  *
  * This method generates a help text as it's commonly known from Unix
  * command line programs. The output will contain the synopsis, your 
  * provided program description and the selected parameter help
  * as also provided by {@link ezcConsoleInput::getHelp()}. The returned
  * string can directly be printed to the console.
  *
  * The $paramGrouping option can be used to group options in the help
  * output. The structure of this array parameter is as follows:
  *
  * <code>
  *  array(
  *      'First section' => array(
  *          'input',
  *          'output'
  *          'overwrite',
  *      ),
  *      'Second section' => array(
  *          'v',
  *          'h',
  *      ),
  *  )
  * </code>
  *
  * As can be seen, short option names are possible as well as long ones.
  * The key of the first array level is the name of the section, which is
  * assigned to an array of options to group under this section. The $params
  * parameter still influences if an option as displayed at all.
  * 
  * @param string $programDesc        The description of your program.
  * @param int $width                 The width to adjust the output text to.
  * @param bool $long                 Set this to true for getting the long 
  *                                   help version.
  * @param array(string) $params Set of option names to generate help 
  *                                   for, default is all.
  * @param array(string=>array(string)) $paramGrouping
  * @return string The generated help text.
  */
 public function getHelpText($programDesc, $width = 80, $long = false, array $params = null, $paramGrouping = null)
 {
     $help = $this->getHelp($long, $params == null ? array() : $params, $paramGrouping);
     // Determine max length of first column text.
     $maxLength = 0;
     foreach ($help as $row) {
         $maxLength = max($maxLength, iconv_strlen($row[0], 'UTF-8'));
     }
     // Width of left column
     $leftColWidth = $maxLength + 2;
     // Width of righ column
     $rightColWidth = $width - $leftColWidth;
     $res = 'Usage: ' . $this->getSynopsis($params) . PHP_EOL;
     $res .= $this->stringTool->wordwrap($programDesc, $width, PHP_EOL);
     $res .= PHP_EOL . PHP_EOL;
     foreach ($help as $row) {
         $rowParts = explode("\n", $this->stringTool->wordwrap($row[1], $rightColWidth));
         $res .= $this->stringTool->strPad($row[0], $leftColWidth, ' ');
         $res .= $rowParts[0] . PHP_EOL;
         // @TODO: Fix function call in loop header
         for ($i = 1; $i < sizeof($rowParts); $i++) {
             $res .= str_repeat(' ', $leftColWidth) . $rowParts[$i] . PHP_EOL;
         }
     }
     return $res;
 }
Exemple #2
0
 /**
  * Generate all values to be replaced in the format string. 
  * 
  * @return void
  */
 protected function generateValues()
 {
     // Bar
     $barFilledSpace = ceil($this->measures['barSpace'] / $this->numSteps * $this->currentStep);
     // Sanitize value if it gets to large by rounding
     $barFilledSpace = $barFilledSpace > $this->measures['barSpace'] ? $this->measures['barSpace'] : $barFilledSpace;
     $bar = $this->stringTool->strPad($this->stringTool->strPad($this->properties['options']->progressChar, $barFilledSpace, $this->properties['options']->barChar, STR_PAD_LEFT), $this->measures['barSpace'], $this->properties['options']->emptyChar, STR_PAD_RIGHT);
     $this->valueMap['bar'] = $bar;
     // Fraction
     $fractionVal = sprintf($this->properties['options']->fractionFormat, ($fractionVal = $this->properties['options']->step * $this->currentStep / $this->max * 100) > 100 ? 100 : $fractionVal);
     $this->valueMap['fraction'] = $this->stringTool->strPad($fractionVal, iconv_strlen(sprintf($this->properties['options']->fractionFormat, 100), 'UTF-8'), ' ', STR_PAD_LEFT);
     // Act / max
     $actVal = sprintf($this->properties['options']->actFormat, ($actVal = $this->currentStep * $this->properties['options']->step) > $this->max ? $this->max : $actVal);
     $this->valueMap['act'] = $this->stringTool->strPad($actVal, iconv_strlen(sprintf($this->properties['options']->actFormat, $this->max), 'UTF-8'), ' ', STR_PAD_LEFT);
     $this->valueMap['max'] = sprintf($this->properties['options']->maxFormat, $this->max);
 }
Exemple #3
0
 /**
  * Generate a single physical row.
  * This method generates the string for a single physical table row.
  * 
  * @param array(string) $cells Cells of the row.
  * @param array(int) $colWidth Calculated columns widths.
  * @param ezcConsoleTableRow $row   The row to generate.
  * @return string The row.
  */
 private function generateRow($cells, $colWidth, $row)
 {
     $rowData = '';
     for ($cell = 0; $cell < count($colWidth); $cell++) {
         $align = $this->determineAlign($row, $cell);
         $format = $this->determineFormat($row, $cell);
         $borderFormat = $this->determineBorderFormat($row);
         $data = isset($cells[$cell]) ? $cells[$cell] : '';
         $rowData .= $this->formatText($this->properties['options']->lineHorizontal, $borderFormat);
         $rowData .= $this->properties['options']->colPadding;
         $rowData .= $this->formatText($this->stringTool->strPad($data, $colWidth[$cell], ' ', $align), $format);
         $rowData .= $this->properties['options']->colPadding;
     }
     $rowData .= $this->formatText($this->properties['options']->lineHorizontal, $row->borderFormat);
     return $rowData;
 }