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

setRow() public method

Sets a specific row in the table.
public setRow ( integer $index, array $row ) : static
$index integer The row index.
$row array An array of data cells.
return static The current instance.
    public function setRow($index, array $row)
    {
        if (null === $this->nbColumns) {
            $this->nbColumns = count($row);
        } elseif (count($row) !== $this->nbColumns) {
            throw new LogicException(sprintf('Expected the row to contain %s cells, but got %s.', $this->nbColumns, count($row)));
        }
        $this->rows[$index] = array_values($row);
        return $this;
    }

Usage Example

Beispiel #1
0
 /**
  * @expectedException \LogicException
  */
 public function testSetRowFailsIfMissingCells()
 {
     $table = new Table();
     $table->setHeaderRow(array('a', 'b', 'c'));
     $table->setRow(0, array('a', 'b'));
 }