本文整理汇总了PHP中Symfony\Component\Console\Helper\TableStyle类的典型用法代码示例。如果您正苦于以下问题:PHP TableStyle类的具体用法?PHP TableStyle怎么用?PHP TableStyle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TableStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
/**
*
* {@inheritDoc}
*
* @see \SK\ITCBundle\Service\Table\Adapter\IAdapter::write()
*/
public function write(Table $table, OutputInterface $output)
{
$style = new TableStyle();
$style->setHorizontalBorderChar('<fg=magenta>-</>')->setVerticalBorderChar('<fg=magenta>|</>')->setCrossingChar('<fg=magenta>+</>');
$stable = new STable($output);
$stable->setStyle('default');
$stable->setHeaders($table->getHeaders());
$columns = $table->getColumns();
$colspan = count($columns);
$rows = $table->getRows();
foreach ($rows as $row) {
$rowModificated = [];
foreach ($columns as $iCol => $col) {
if (is_int($iCol)) {
$iCol = $col;
}
if (array_key_exists($iCol, $row)) {
$rowModificated[$iCol] = wordwrap($row[$iCol], $table->getMaxColWidth(), "\n", true);
} else {
$rowModificated[$iCol] = "";
}
}
$stable->addRow($rowModificated);
$stable->addRow(array(new TableSeparator(array('colspan' => $colspan))));
}
$stable->addRow(array(new TableCell("", array('colspan' => $colspan))));
$stable->addRow(array(new TableCell(sprintf("Found %s results.", count($rows)), array('colspan' => $colspan))));
$stable->render();
}
示例2: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$lists = $this->rfcService->getLists([RfcService::IN_VOTING]);
$rfcs = array_pop($lists);
$table = new Table($output);
$voteStyle = new TableStyle();
$voteStyle->setCellRowFormat('<comment>%s</comment>');
$rfcStyle = new TableStyle();
$rfcStyle->setCellRowFormat('<info>%s</info>');
foreach ($rfcs as $i => $rfcDetails) {
$rfcCode = $rfcDetails[1];
// Build RFC
$rfc = $this->rfcService->getRfc($rfcCode);
$table->addRow([$rfcDetails[0]], $rfcStyle);
$table->addRow(new TableSeparator());
foreach ($rfc->getVotes() as $title => $vote) {
$table->addRow([$title], $voteStyle);
array_shift($vote['counts']);
foreach ($vote['counts'] as $key => $total) {
$table->addRow([$key, $total]);
}
}
if ($rfcDetails !== end($rfcs)) {
$table->addRow(new TableSeparator());
}
}
$table->render();
}
示例3: setPaddingFromStyle
/**
* Calculate our padding widths from the specified table style.
* @param TableStyle $style
*/
public function setPaddingFromStyle(TableStyle $style)
{
$verticalBorderLen = strlen(sprintf($style->getBorderFormat(), $style->getVerticalBorderChar()));
$paddingLen = strlen($style->getPaddingChar());
$this->extraPaddingAtBeginningOfLine = 0;
$this->extraPaddingAtEndOfLine = $verticalBorderLen;
$this->paddingInEachCell = $verticalBorderLen + $paddingLen + 1;
}
示例4: declareWinner
private function declareWinner(PokerGame $pokerGame)
{
$style = new TableStyle();
$style->setVerticalBorderChar('<fg=red;bg=black>|</>')->setHorizontalBorderChar('<fg=red;bg=black>-</>');
$winningHand = $pokerGame->getWinner();
$table = new Table($this->output);
$table->setRows([$winningHand]);
$table->render();
}
示例5: table
/**
* {@inheritdoc}
*/
public function table(array $headers, array $rows)
{
$headers = array_map(function ($value) {
return sprintf("<info>%s</info>", $value);
}, $headers);
$styleGuide = new TableStyle();
$styleGuide->setHorizontalBorderChar('-')->setVerticalBorderChar('|')->setCrossingChar('+')->setCellHeaderFormat('%s');
$table = new Table($this);
$table->setHeaders($headers);
$table->setRows($rows);
$table->setStyle($styleGuide);
$table->render();
$this->newLine();
}
示例6: displayTableResults
public function displayTableResults(OutputInterface $output, $object, array $keysOnly = [], $maxWidth = 35, $count = false)
{
$table = new Table($output);
$style = new TableStyle();
$style->setHorizontalBorderChar('<fg=magenta>-</>')->setVerticalBorderChar('<fg=magenta>|</>')->setCrossingChar(' ');
$table->setStyle($style);
if ($object instanceof CollectionAbstract) {
$list = $object->toArray();
} else {
$list = $object;
}
$i = 0;
foreach ($list as $item) {
if (!is_array($item)) {
continue;
}
++$i;
foreach ($item as $key => $value) {
if (!empty($keysOnly) && !in_array($key, $keysOnly, true)) {
unset($item[$key]);
continue;
}
if (is_array($value)) {
$value = json_encode($value);
}
if (is_float($value)) {
$value = number_format($value, 3);
}
$value = str_replace(['["', '"]', '{"', '"', '}'], [], $value);
if (empty($value)) {
$value = '~';
}
$value = substr($value, 0, $maxWidth);
$item[$key] = $value;
}
if (true === $count) {
$item = array_merge(['#' => $i], $item);
}
if (!isset($headers)) {
$headers = array_keys($item);
$table->setHeaders($headers);
}
$table->addRow($item);
}
return $table->render($output);
}
示例7: doExecute
/**
* {@inheritDoc}
*/
protected function doExecute()
{
$table = new Table($this->output);
$table->setHeaders(['Name', 'Description']);
$style = new TableStyle();
$style->setCellHeaderFormat('<fg=red>%s</fg=red>');
$style->setCellRowFormat('<fg=blue>%s</fg=blue>');
$style->setBorderFormat('<fg=yellow>%s</fg=yellow>');
$table->setStyle($style);
/** @type AbstractTask[] $services */
$services = $this->container->get('bldr.registry.task')->findAll();
foreach ($services as $service) {
if ($service instanceof AbstractTask) {
$service->configure();
}
$table->addRow([$service->getName(), $service->getDescription() !== '' ? $service->getDescription() : 'No Description']);
}
$table->render($this->output);
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var FormatterHelper $formatter */
$formatter = $this->getHelper('formatter');
$message = $formatter->formatSection('Section', 'Hello!', 'comment');
$output->writeln($message);
$blockMessage = $formatter->formatBlock(['Good luck!'], 'bg=black;fg=white', true);
$output->writeln($blockMessage);
/** @var ProcessHelper $processHelper */
$processHelper = $this->getHelper('process');
$process = ProcessBuilder::create(['figlet', 'Started!'])->getProcess();
$processHelper->run($output, $process, 'Something went wrong');
$finder = new Finder();
$files = $finder->in(CACHE_PATH)->name('makes*json')->files();
$progressHelper = new ProgressBar($output);
$progressHelper->setEmptyBarCharacter('.');
$progressHelper->setBarCharacter('<comment>+</comment>');
if ($input->getOption('progress')) {
$progressHelper->start($files->count());
}
$table = new Table($output);
$table->setStyle('default');
$style = new TableStyle();
$style->setBorderFormat('<comment>%s</comment>');
$table->setStyle($style);
foreach ($files as $file) {
/** @var SplFileInfo $file */
$makes = json_decode($file->getContents(), true);
$table->setHeaders(['Make Name', 'Models Count']);
foreach ($makes['makes'] as $make) {
$table->addRow([$make['name'], count($make['models'])]);
}
// $table->render($output);
if ($input->getOption('progress')) {
$progressHelper->advance();
}
}
if ($input->getOption('progress')) {
$progressHelper->finish();
$output->writeln('');
}
}
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:42,代码来源:MakesCacheReportCommand.php
示例9: execute
/**
* Execute Command
*
* @param InputInterface $input
* @param OutputInterface $output
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$sections = ['voting' => RfcService::IN_VOTING, 'discussion' => RfcService::DISCUSSION, 'draft' => RfcService::DRAFT, 'accepted' => RfcService::ACCEPTED, 'declined' => RfcService::DECLINED, 'withdrawn' => RfcService::WITHDRAWN, 'inactive' => RfcService::INACTIVE];
$sections = array_intersect_key($sections, array_filter($input->getOptions()));
if (count($sections) === 0 && !$input->getOption('all')) {
$sections[] = RfcService::IN_VOTING;
}
$table = new Table($output);
$titleStyle = new TableStyle();
$titleStyle->setCellRowFormat('<comment>%s</comment>');
$lists = $this->rfcService->getLists($sections);
$table->setHeaders(['RFC', 'RFC Code']);
foreach ($lists as $heading => $list) {
$table->addRow([$heading], $titleStyle);
$table->addRow(new TableSeparator());
foreach ($list as $listing) {
$table->addRow($listing);
}
if ($list !== end($lists)) {
$table->addRow(new TableSeparator());
}
}
$table->render();
}
示例10: doExecute
/**
* {@inheritDoc}
*/
protected function doExecute()
{
/** @type AbstractTask $service */
$service = $this->container->get('bldr.registry.task')->findTaskByType($this->input->getArgument('task'));
$this->output->writeln('');
$this->output->writeln('<fg=green>Task Name</fg=green>: ' . $service->getName());
if ($service->getDescription() !== null) {
$this->output->writeln('<fg=green>Task Description</fg=green>: ' . $service->getDescription());
}
if ($service instanceof AbstractTask) {
$this->output->writeln(['', '<fg=green>Options:</fg=green>']);
$tableHelper = new Table($this->output);
$style = new TableStyle();
$style->setCellHeaderFormat('<fg=red>%s</fg=red>');
$style->setCellRowFormat('<fg=blue>%s</fg=blue>');
$style->setBorderFormat('<fg=yellow>%s</fg=yellow>');
$tableHelper->setStyle($style);
$tableHelper->setHeaders(['Option', 'Description', 'Required', "Default"]);
foreach ($service->getParameterDefinition() as $option) {
$tableHelper->addRow([$option['name'], $option['description'] !== '' ? $option['description'] : 'No Description', $option['required'] ? 'Yes' : 'No', json_encode($option['default'])]);
}
$tableHelper->render();
}
}
示例11: displayErrors
/**
* Display validation errors.
*
* @param Validator $validator The json-schema validator.
* @param OutputInterface $output An OutputInterface instance.
*/
public static function displayErrors(Validator $validator, OutputInterface $output)
{
$table = new Table($output);
$style = new TableStyle();
$style->setCellHeaderFormat('<error>%s</error>');
$style->setHorizontalBorderChar(' ');
$style->setVerticalBorderChar(' ');
$style->setCrossingChar(' ');
$table->setHeaders(['Property', 'Error']);
$table->setRows($validator->getErrors());
$table->setStyle($style);
$table->render();
}
示例12: initStyles
private static function initStyles()
{
$borderless = new TableStyle();
$borderless->setHorizontalBorderChar('=')->setVerticalBorderChar(' ')->setCrossingChar(' ');
$compact = new TableStyle();
$compact->setHorizontalBorderChar('')->setVerticalBorderChar(' ')->setCrossingChar('')->setCellRowContentFormat('%s');
$styleGuide = new TableStyle();
$styleGuide->setHorizontalBorderChar('-')->setVerticalBorderChar(' ')->setCrossingChar(' ')->setCellHeaderFormat('%s');
return array('default' => new TableStyle(), 'borderless' => $borderless, 'compact' => $compact, 'symfony-style-guide' => $styleGuide);
}
示例13: testColumnStyle
public function testColumnStyle()
{
$table = new Table($output = $this->getOutputStream());
$table->setHeaders(array('ISBN', 'Title', 'Author', 'Price'))->setRows(array(array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri', '9.95'), array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25')));
$style = new TableStyle();
$style->setPadType(STR_PAD_LEFT);
$table->setColumnStyle(3, $style);
$table->render();
$expected = <<<TABLE
+---------------+----------------------+-----------------+--------+
| ISBN | Title | Author | Price |
+---------------+----------------------+-----------------+--------+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri | 9.95 |
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | 139.25 |
+---------------+----------------------+-----------------+--------+
TABLE;
$this->assertEquals($expected, $this->getOutputContent($output));
}
示例14: testStyle
public function testStyle()
{
$style = new TableStyle();
$style->setHorizontalBorderChar('.')->setVerticalBorderChar('.')->setCrossingChar('.');
Table::setStyleDefinition('dotfull', $style);
$table = new Table($output = $this->getOutputStream());
$table->setHeaders(array('Foo'))->setRows(array(array('Bar')))->setStyle('dotfull');
$table->render();
$expected = <<<TABLE
.......
. Foo .
.......
. Bar .
.......
TABLE;
$this->assertEquals($expected, $this->getOutputContent($output));
}
示例15: getTable
/**
* Get a Table instance.
*
* Falls back to legacy TableHelper.
*
* @return Table|TableHelper
*/
protected function getTable(OutputInterface $output)
{
if (!class_exists('Symfony\\Component\\Console\\Helper\\Table')) {
return $this->getTableHelper();
}
$style = new TableStyle();
$style->setVerticalBorderChar(' ')->setHorizontalBorderChar('')->setCrossingChar('');
$table = new Table($output);
return $table->setRows(array())->setStyle($style);
}