render() public method

Renders the table.
public render ( IO $io, integer $indentation )
$io Webmozart\Console\Api\IO\IO The I/O.
$indentation integer The number of spaces to indent.
 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;
 }
Beispiel #2
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;
 }
Beispiel #4
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 handleList(Args $args, IO $io)
 {
     $table = new Table(TableStyle::borderless());
     $targets = $this->targetManager->getTargets();
     if ($targets->isEmpty()) {
         $io->writeLine('No install targets. Use "puli target add <name> <directory>" to add a target.');
         return 0;
     }
     $defaultTarget = $targets->getDefaultTarget();
     foreach ($targets as $target) {
         $parameters = '';
         foreach ($target->getParameterValues() as $name => $value) {
             $parameters .= "\n<c1>" . $name . '=' . StringUtil::formatValue($value) . '</c1>';
         }
         $table->addRow(array($defaultTarget === $target ? '*' : '', '<u>' . $target->getName() . '</u>', $target->getInstallerName(), '<c2>' . $target->getLocation() . '</c2>' . $parameters, '<c1>' . $target->getUrlFormat() . '</c1>'));
     }
     $table->render($io);
     return 0;
 }
Beispiel #7
0
 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;
 }
Beispiel #8
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);
 }
Beispiel #9
0
 /**
  * Prints the resources in the long style (with the "-l" option).
  *
  * @param IO                 $io        The I/O.
  * @param ResourceCollection $resources The resources.
  */
 private function listLong(IO $io, ResourceCollection $resources)
 {
     $style = TableStyle::borderless();
     $style->setColumnAlignments(array(Alignment::LEFT, Alignment::RIGHT, Alignment::LEFT, Alignment::RIGHT, Alignment::RIGHT, Alignment::LEFT));
     $table = new Table($style);
     $today = new DateTime();
     $currentYear = (int) $today->format('Y');
     foreach ($resources as $resource) {
         // Create date from timestamp. Result is in the UTC timezone.
         $modifiedAt = new DateTime('@' . $resource->getMetadata()->getModificationTime());
         // Set timezone to server timezone.
         $modifiedAt->setTimezone($today->getTimezone());
         $year = (int) $modifiedAt->format('Y');
         $table->addRow(array(StringUtil::getShortClassName(get_class($resource)), $this->formatSize($resource->getMetadata()->getSize()), $modifiedAt->format('M'), $modifiedAt->format('j'), $year < $currentYear ? $year : $modifiedAt->format('H:i'), $this->formatName($resource)));
     }
     $table->render($io);
 }
Beispiel #10
0
 /**
  * Prints the given resources.
  *
  * @param IO       $io      The I/O.
  * @param string[] $matches An array of short resource class names indexed
  *                          by the resource path.
  */
 private function printTable(IO $io, array $matches)
 {
     $table = new Table(TableStyle::borderless());
     foreach ($matches as $path => $shortClass) {
         $table->addRow(array($shortClass, "<c1>{$path}</c1>"));
     }
     $table->render($io);
 }
Beispiel #11
0
 /**
  * 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);
 }
Beispiel #12
0
 /**
  * @param MigrationsStatusCommand $command
  */
 public function migrationsStatus(MigrationsStatusCommand $command)
 {
     try {
         $status = $this->migrator->status();
         $latestMigration = $status->latestMigration();
         $rows = array(array(' Current Version', $latestMigration ? sprintf('<c2>%s (%s)</c2>', $latestMigration->version()->__toString(), $latestMigration->createdAt()->format('Y-m-d H:i:s')) : '<c2>0</c2>'), array(' Latest Version', $status->latestAvailableVersion() ? '<c2>' . $status->latestAvailableVersion()->__toString() . '</c2>' : '<c2>none</c2>'), array(' Next Version', $status->nextAvailableVersion() ? '<c2>' . $status->nextAvailableVersion()->__toString() . '</c2>' : '<c2>none</c2>'), array(' Executed Migrations', '<c2>' . $status->numExecutedMigrations() . '</c2>'), array(' Available Migrations', '<c2>' . $status->numAvailableMigrations() . '</c2>'), array(' New Migrations', '<c2>' . $status->numNewMigrations() . '</c2>'));
         $table = new Table(TableStyle::borderless());
         foreach ($rows as $row) {
             $table->addRow($row);
         }
         $table->render($command->getIo());
     } catch (\Exception $e) {
         $command->getIo()->writeLine('<error>' . $e->getMessage() . '</error>');
     }
 }
Beispiel #13
0
 /**
  * @param IO             $io
  * @param AssetMapping[] $mappings
  * @param bool           $enabled
  */
 private function printMappingTable(IO $io, array $mappings, $enabled = true)
 {
     $table = new Table(TableStyle::borderless());
     $globTag = $enabled ? 'c1' : 'bad';
     $pathTag = $enabled ? 'c2' : 'bad';
     foreach ($mappings as $mapping) {
         $uuid = substr($mapping->getUuid()->toString(), 0, 6);
         $glob = $mapping->getGlob();
         $serverPath = $mapping->getServerPath();
         if (!$enabled) {
             $uuid = "<bad>{$uuid}</bad>";
         }
         $table->addRow(array($uuid, "<{$globTag}>{$glob}</{$globTag}>", "<{$pathTag}>{$serverPath}</{$pathTag}>"));
     }
     $table->render($io, 8);
 }
Beispiel #14
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';
     $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);
 }
Beispiel #15
0
    public function testRenderFormattedCells()
    {
        $table = new Table(TableStyle::asciiBorder());
        $table->setHeaderRow(array('ISBN', 'Title', 'Author'));
        $table->addRows(array(array('<b>99921-58-10-7</b>', 'Divine Comedy', 'Dante Alighieri'), array('<b>9971-5-0210-0</b>', 'A Tale of Two Cities', 'Charles Dickens'), array('<b>960-425-059-0</b>', 'The Lord of the Rings', 'J. R. R. Tolkien'), array('<b>80-902734-1-6</b>', 'And Then There Were None', 'Agatha Christie')));
        $table->render($this->io);
        $expected = <<<'EOF'
+---------------+--------------------------+------------------+
| ISBN          | Title                    | Author           |
+---------------+--------------------------+------------------+
| 99921-58-10-7 | Divine Comedy            | Dante Alighieri  |
| 9971-5-0210-0 | A Tale of Two Cities     | Charles Dickens  |
| 960-425-059-0 | The Lord of the Rings    | J. R. R. Tolkien |
| 80-902734-1-6 | And Then There Were None | Agatha Christie  |
+---------------+--------------------------+------------------+

EOF;
        $this->assertSame($expected, $this->io->fetchOutput());
    }
Beispiel #16
0
 /**
  * @param IO             $io
  * @param AssetMapping[] $mappings
  * @param bool           $enabled
  */
 private function printMappingTable(IO $io, array $mappings, $enabled = true)
 {
     $table = new Table(TableStyle::borderless());
     $globTag = $enabled ? 'c1' : 'bad';
     $pathTag = $enabled ? 'c2' : 'bad';
     foreach ($mappings as $mapping) {
         $uuid = substr($mapping->getUuid()->toString(), 0, 6);
         $glob = $mapping->getGlob();
         $serverPath = $mapping->getServerPath();
         if (!$enabled) {
             $uuid = sprintf('<bad>%s</bad>', $uuid);
         }
         $table->addRow(array($uuid, sprintf('<%s>%s</%s>', $globTag, $glob, $globTag), sprintf('<%s>%s</%s>', $pathTag, $serverPath, $pathTag)));
     }
     $table->render($io, 8);
 }
Beispiel #17
0
 /**
  * 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 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);
 }
Beispiel #19
0
 /**
  * @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('');
     }
 }