Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
コード例 #1
0
ファイル: PuliTableStyle.php プロジェクト: msojda/cli
 /**
  * A borderless style.
  *
  * @return TableStyle The style.
  */
 public static function borderless()
 {
     if (!self::$borderless) {
         $borderStyle = BorderStyle::none();
         $borderStyle->setLineVCChar('  ');
         self::$borderless = new static();
         self::$borderless->setBorderStyle($borderStyle);
         self::$borderless->setHeaderCellStyle(Style::noTag()->bold());
     }
     return clone self::$borderless;
 }
コード例 #2
0
 public function handleList(Args $args, IO $io)
 {
     $table = new Table(TableStyle::borderless());
     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 ($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;
 }
コード例 #3
0
ファイル: Table.php プロジェクト: webmozart/console
 private function renderRows(IO $io, array $rows, array $columnLengths, $excessColumnLength, $indentation)
 {
     $alignments = $this->style->getColumnAlignments(count($columnLengths));
     $borderStyle = $this->style->getBorderStyle();
     $borderColumnLengths = array_map(function ($length) use($excessColumnLength) {
         return $length + $excessColumnLength;
     }, $columnLengths);
     BorderUtil::drawTopBorder($io, $borderStyle, $borderColumnLengths, $indentation);
     if ($this->headerRow) {
         BorderUtil::drawRow($io, $borderStyle, array_shift($rows), $columnLengths, $alignments, $this->style->getHeaderCellFormat(), $this->style->getHeaderCellStyle(), $this->style->getPaddingChar(), $indentation);
         BorderUtil::drawMiddleBorder($io, $borderStyle, $borderColumnLengths, $indentation);
     }
     foreach ($rows as $row) {
         BorderUtil::drawRow($io, $borderStyle, $row, $columnLengths, $alignments, $this->style->getCellFormat(), $this->style->getCellStyle(), $this->style->getPaddingChar(), $indentation);
     }
     BorderUtil::drawBottomBorder($io, $borderStyle, $borderColumnLengths, $indentation);
 }
コード例 #4
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);
 }
コード例 #5
0
 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;
 }
コード例 #6
0
ファイル: LsCommandHandler.php プロジェクト: rejinka/cli
 /**
  * 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);
 }
コード例 #7
0
ファイル: FindCommandHandler.php プロジェクト: rejinka/cli
 /**
  * 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);
 }
コード例 #8
0
ファイル: PublishCommandHandler.php プロジェクト: rejinka/cli
 /**
  * @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);
 }
コード例 #9
0
ファイル: PackageCommandHandler.php プロジェクト: rejinka/cli
 /**
  * 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->getEnvironment()->getRootDirectory();
     $table = new Table(TableStyle::borderless());
     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("<bad>{$packageName}</bad>:", "<bad>{$errorMessage}</bad>"));
     }
     $table->render($io, $indent ? 4 : 0);
 }
コード例 #10
0
ファイル: TableTest.php プロジェクト: webmozart/console
    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());
    }
コード例 #11
0
ファイル: PublishCommandHandler.php プロジェクト: msojda/cli
 /**
  * @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);
 }
コード例 #12
0
ファイル: MigrationsService.php プロジェクト: cubiche/cubiche
 /**
  * @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>');
     }
 }
コード例 #13
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('');
     }
 }