Sets the header cells of the table.
public setHeaderRow ( array $row ) : static | ||
$row | array | The header cells. |
return | static | The current instance. |
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; }
/** * {@inheritdoc} */ public function render(ResultCollection $resultCollection) { $table = new Table(); $table->setHeaderRow(['Global Status', 'Status Code', 'Name', 'Response Time', 'Http Error Log', 'Validator Error Log']); $statusGuesser = new StatusGuesser(); foreach ($resultCollection as $result) { $color = $statusGuesser->isFailed($result) ? 'red' : 'green'; $table->addRow([$statusGuesser->isFailed($result) ? 'FAIL' : 'OK', sprintf('<bg=%s>%s</>', $color, $result->getStatusCode()), $result->getUrl()->getName(), $result->getReponseTime(), sprintf('<bg=red>%s</>', $result->getHandlerError()), sprintf('<bg=red>%s</>', $result->getValidatorError())]); } $table->render($this->io); }
/** * Handles the "config" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handleList(Args $args, IO $io) { $raw = !$args->isOptionSet('parsed'); $userValues = $this->manager->getConfigKeys(false, false, $raw); $effectiveValues = $this->manager->getConfigKeys(true, true, $raw); $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('Config Key', 'User Value', 'Effective Value')); foreach ($effectiveValues as $key => $value) { $table->addRow(array("<c1>{$key}</c1>", array_key_exists($key, $userValues) ? StringUtil::formatValue($userValues[$key], false) : '', StringUtil::formatValue($value, false))); } $table->render($io); return 0; }
public function handleList(Args $args, IO $io) { $table = new Table(PuliTableStyle::borderless()); $servers = $this->serverManager->getServers(); if ($servers->isEmpty()) { $io->writeLine('No servers. Use "puli server --add <name> <document-root>" to add a server.'); return 0; } $table->setHeaderRow(array('Server Name', 'Installer', 'Location', 'URL Format')); foreach ($servers as $server) { $table->addRow(array('<u>' . $server->getName() . '</u>', $server->getInstallerName(), '<c2>' . $server->getDocumentRoot() . '</c2>', '<c1>' . $server->getUrlFormat() . '</c1>')); } $table->render($io); return 0; }
public function handle(Args $args, IO $io, Command $command) { $tabular = Tabular::getInstance(); $dom = new \DOMDocument('1.0'); $dom->load($args->getArgument('xml')); $tableDom = $tabular->tabulate($dom, $args->getArgument('definition')); if ($args->getOption('debug')) { $io->writeLine($tableDom->saveXml()); } $rows = $tableDom->toArray(); $table = new Table(TableStyle::solidBorder()); $table->setHeaderRow(array_keys(reset($rows) ?: array())); foreach ($rows as $row) { $table->addRow($row); } $table->render($io); }
public function handle(Args $args, IO $io, Command $command) { $table = new Table(); $table->setHeaderRow(array('Name', 'Description')); $output = new ConsoleOutput(); $style = new OutputFormatterStyle('white', 'black', array('bold')); if ($args->getArgument('package') == '') { $output->writeln(Cpm\message::USAGE); exit; } $limit = $args->getOption('limit'); $limit_str = $limit ? 'limit ' . $limit : ''; $q = $args->getArgument('package'); $datas = R::findAll('repo', ' name LIKE ? order by download_monthly desc,favers desc,download_total desc' . $limit_str, ['%' . $q . '%']); foreach ($datas as $data) { $output->getFormatter()->setStyle('bold', $style); // $output->writeln('<bold>'.$data->name.'</>'.' '.$data->description); // $output->writeln($data->keywords); $table->addRow(array("(" . $data->favers . ")" . $data->name, $data->description)); } $table->render($io); return 0; }
/** * Prints the binding types in a table. * * @param IO $io The I/O. * @param BindingTypeDescriptor[] $descriptors The type descriptors to print. * @param string $styleTag The tag used to style the output * @param int $indentation The number of spaces to indent. */ private function printTypeTable(IO $io, array $descriptors, $styleTag = null, $indentation = 0) { $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('Type', 'Description', 'Parameters')); $paramTag = $styleTag ?: 'c1'; $typeTag = $styleTag ?: 'u'; foreach ($descriptors as $descriptor) { $type = $descriptor->getType(); $parameters = array(); foreach ($type->getParameters() as $parameter) { $paramString = $parameter->isRequired() ? $parameter->getName() : $parameter->getName() . '=' . StringUtil::formatValue($parameter->getDefaultValue()); $parameters[$parameter->getName()] = "<{$paramTag}>{$paramString}</{$paramTag}>"; } $description = $descriptor->getDescription(); if ($styleTag) { $description = "<{$styleTag}>{$description}</{$styleTag}>"; } ksort($parameters); $table->addRow(array("<{$typeTag}>" . $descriptor->getTypeName() . "</{$typeTag}>", $description, implode("\n", $parameters))); } $table->render($io, $indentation); }
/** * Prints not-loadable packages in a table. * * @param IO $io The I/O. * @param Package[] $packages The not-loadable packages. * @param bool $indent Whether to indent the output. */ private function printNotLoadablePackages(IO $io, array $packages, $indent = false) { $rootDir = $this->packageManager->getContext()->getRootDirectory(); $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('Package Name', 'Error')); ksort($packages); foreach ($packages as $package) { $packageName = $package->getName(); $loadErrors = $package->getLoadErrors(); $errorMessage = ''; foreach ($loadErrors as $loadError) { $errorMessage .= StringUtil::getShortClassName(get_class($loadError)) . ': ' . $loadError->getMessage() . "\n"; } $errorMessage = rtrim($errorMessage); if (!$errorMessage) { $errorMessage = 'Unknown error.'; } // Remove root directory $errorMessage = str_replace($rootDir . '/', '', $errorMessage); $table->addRow(array(sprintf('<bad>%s</bad>', $packageName), sprintf('<bad>%s</bad>', $errorMessage))); } $table->render($io, $indent ? 4 : 0); }
/** * Prints a list of binding descriptors. * * @param IO $io The I/O. * @param BindingDescriptor[] $descriptors The binding descriptors. * @param int $indentation The number of spaces to indent. * @param bool $enabled Whether the binding descriptors * are enabled. If not, the output * is printed in red. */ private function printBindingTable(IO $io, array $descriptors, $indentation = 0, $enabled = true) { $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('UUID', 'Glob', 'Type')); $paramTag = $enabled ? 'c1' : 'bad'; $artifactTag = $enabled ? 'c1' : 'bad'; $typeTag = $enabled ? 'u' : 'bad'; foreach ($descriptors as $descriptor) { $parameters = array(); $binding = $descriptor->getBinding(); foreach ($binding->getParameterValues() as $parameterName => $parameterValue) { $parameters[] = $parameterName . '=' . StringUtil::formatValue($parameterValue); } $uuid = substr($descriptor->getUuid(), 0, 6); if (!$enabled) { $uuid = "<bad>{$uuid}</bad>"; } $paramString = ''; if (!empty($parameters)) { // \xc2\xa0 is a non-breaking space $paramString = " <{$paramTag}>(" . implode(", ", $parameters) . ")</{$paramTag}>"; } if ($binding instanceof ResourceBinding) { $artifact = $binding->getQuery(); } elseif ($binding instanceof ClassBinding) { $artifact = StringUtil::getShortClassName($binding->getClassName()); } else { continue; } $typeString = StringUtil::getShortClassName($binding->getTypeName()); $table->addRow(array($uuid, "<{$artifactTag}>{$artifact}</{$artifactTag}>", "<{$typeTag}>{$typeString}</{$typeTag}>" . $paramString)); } $table->render($io, $indentation); }
/** * @expectedException \LogicException */ public function testSetRowFailsIfMissingCells() { $table = new Table(); $table->setHeaderRow(array('a', 'b', 'c')); $table->setRow(0, array('a', 'b')); }
/** * Prints a list of conflicting path mappings. * * @param IO $io The I/O. * @param PathMapping[] $mappings The path mappings. * @param int $indentation The number of spaces to indent the * output. */ private function printConflictTable(IO $io, array $mappings, $indentation = 0) { /** @var PathConflict[] $conflicts */ $conflicts = array(); $shortPrefix = str_repeat(' ', $indentation); $prefix = str_repeat(' ', $indentation + 4); $printNewline = false; foreach ($mappings as $mapping) { foreach ($mapping->getConflicts() as $conflict) { $conflicts[spl_object_hash($conflict)] = $conflict; } } foreach ($conflicts as $conflict) { if ($printNewline) { $io->writeLine(''); } $io->writeLine(sprintf('%sConflicting path: %s', $shortPrefix, $conflict->getRepositoryPath())); $io->writeLine(''); $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('Package', 'Puli Path', 'Real Path(s)')); foreach ($conflict->getMappings() as $mapping) { $table->addRow(array('<bad>' . $mapping->getContainingPackage()->getName() . '</bad>', '<bad>' . $mapping->getRepositoryPath() . '</bad>', '<bad>' . implode(', ', $mapping->getPathReferences()) . '</bad>')); } $io->writeLine(sprintf('%sMapped by the following mappings:', $prefix)); $io->writeLine(''); $table->render($io, $indentation + 4); $printNewline = true; } }
/** * Prints a list of binding descriptors. * * @param IO $io The I/O. * @param BindingDescriptor[] $descriptors The binding descriptors. * @param int $indentation The number of spaces to indent. * @param bool $enabled Whether the binding descriptors * are enabled. If not, the output * is printed in red. */ private function printBindingTable(IO $io, array $descriptors, $indentation = 0, $enabled = true) { $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('UUID', 'Glob', 'Type')); $paramTag = $enabled ? 'c1' : 'bad'; $queryTag = $enabled ? 'c1' : 'bad'; $typeTag = $enabled ? 'u' : 'bad'; foreach ($descriptors as $descriptor) { $parameters = array(); foreach ($descriptor->getParameterValues() as $parameterName => $value) { $parameters[] = $parameterName . '=' . StringUtil::formatValue($value); } $uuid = substr($descriptor->getUuid(), 0, 6); if (!$enabled) { $uuid = "<bad>{$uuid}</bad>"; } if ($parameters) { // \xc2\xa0 is a non-breaking space $paramString = " <{$paramTag}>(" . implode(", ", $parameters) . ")</{$paramTag}>"; } else { $paramString = ''; } $table->addRow(array($uuid, "<{$queryTag}>{$descriptor->getQuery()}</{$queryTag}>", "<{$typeTag}>{$descriptor->getTypeName()}</{$typeTag}>" . $paramString)); } $table->render($io, $indentation); }
/** * @param PreDispatchEvent $preDispatchEvent */ public function onPreDispatchEvent(PreDispatchEvent $preDispatchEvent) { if ($this->preDispatchHandler) { call_user_func($this->preDispatchHandler, $preDispatchEvent->event(), $this->io); } else { $this->io->writeLine('<c1>------------------------------------------------------------------------</c1>'); $this->io->writeLine('Dispatching <c1>' . $this->eventToString($preDispatchEvent->event()) . '</c1> with:'); $this->io->writeLine(''); $properties = $this->objectToPropertyArray($preDispatchEvent->event()); $table = new Table(TableStyle::asciiBorder()); $table->setHeaderRow(array_keys($properties)); $table->addRow(array_values($properties)); $table->render($this->io); $this->io->writeLine(''); } }