Webmozart\Console\UI\Component\Table::setHeaderRow PHP Method

setHeaderRow() public method

Sets the header cells of the table.
public setHeaderRow ( array $row ) : static
$row array The header cells.
return static The current instance.
    public function setHeaderRow(array $row)
    {
        if (null === $this->nbColumns) {
            $this->nbColumns = count($row);
        } elseif (count($row) !== $this->nbColumns) {
            throw new LogicException(sprintf('Expected the header row to contain %s cells, but got %s.', $this->nbColumns, count($row)));
        }
        $this->headerRow = array_values($row);
        return $this;
    }

Usage Example

示例#1
0
 public function handleList(Args $args, IO $io)
 {
     $table = new Table(PuliTableStyle::borderless());
     $table->setHeaderRow(array('Name', 'Class', 'Description'));
     foreach ($this->installerManager->getInstallerDescriptors() as $descriptor) {
         $className = $descriptor->getClassName();
         if (!$args->isOptionSet('long')) {
             $className = StringUtil::getShortClassName($className);
         }
         $parameters = array();
         foreach ($descriptor->getParameters() as $parameterName => $parameter) {
             if (!$parameter->isRequired()) {
                 $parameterName .= '=' . StringUtil::formatValue($parameter->getDefaultValue());
             }
             $parameters[] = $parameterName;
         }
         $description = $descriptor->getDescription();
         if (!empty($parameters)) {
             // non-breaking space
             $description .= ' <c1>(' . implode(", ", $parameters) . ')</c1>';
         }
         $table->addRow(array('<u>' . $descriptor->getName() . '</u>', '<c1>' . $className . '</c1>', $description));
     }
     $table->render($io);
     return 0;
 }
All Usage Examples Of Webmozart\Console\UI\Component\Table::setHeaderRow