protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $table = new Console\Helper\TableHelper();
     $output->writeln('Cluster overview:');
     $output->writeln('');
     $output->writeln('Nodes:');
     $cluster = $this->elastica->getCluster();
     $table->setHeaders(['name', 'documents', 'node', 'ip', 'port', 'hostname', 'version', 'transport address', 'http address']);
     $nodes = $cluster->getNodes();
     foreach ($nodes as $node) {
         $name = $node->getName();
         $ip = $node->getInfo()->getIp();
         $data = $node->getInfo()->getData();
         $port = $node->getInfo()->getPort();
         $stats = $node->getStats()->get();
         $table->addRow([$data['name'], $stats['indices']['docs']['count'], $name, $ip, $port, $data['hostname'], $data['version'], $data['transport_address'], $data['http_address']]);
     }
     $table->render($output);
     $table->setRows([]);
     /* INFO */
     $info = $this->elastica->request('', 'GET')->getData();
     $table->setHeaders(['name', 'version', 'status', 'ok']);
     $table->addRow([$info['name'], $info['version']['number'], $info['status'], $info['ok']]);
     $table->render($output);
     $table->setRows([]);
     $output->writeln('');
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $statsTable = $this->doExecute($input, $output);
     if (!$statsTable instanceof StatsTable) {
         throw new RuntimeException('StatsTable expected');
     }
     $dumper = null;
     if ($filename = $input->getOption('xls')) {
         $excelDumperOptions = array();
         if (method_exists($this, 'getExcelDumperOptions')) {
             $excelDumperOptions = $this->getExcelDumperOptions();
         }
         $dumper = new ExcelDumper($excelDumperOptions);
     } elseif ($filename = $input->getOption('csv')) {
         $csvDumperOptions = array();
         if (method_exists($this, 'getCSVDumperOptions')) {
             $csvDumperOptions = $this->getCSVDumperOptions();
         }
         $dumper = new CSVDumper($csvDumperOptions);
     } elseif ($filename = $input->getOption('html')) {
         $htmlDumperOptions = array();
         if (method_exists($this, 'getHTMLDumperOptions')) {
             $htmlDumperOptions = $this->getHTMLDumperOptions();
         }
         $dumper = new HTMLDumper($htmlDumperOptions);
     }
     if (null !== $dumper) {
         $contents = $dumper->dump($statsTable);
         if ($filename == '-') {
             $output->write($contents);
         } else {
             file_put_contents($filename, $contents);
         }
     } else {
         $tableHelper = new TableHelper();
         $tableHelper->setHeaders($statsTable->getHeaders());
         // Dump from CSV
         $dumper = new CSVDumper();
         $dumper->enableHeaders(false);
         $dumper->enableAggregation(false);
         $data = $dumper->dump($statsTable);
         $fp = fopen('php://temp', 'rw');
         fwrite($fp, $data);
         fseek($fp, 0, SEEK_SET);
         while ($line = fgetcsv($fp)) {
             $tableHelper->addRow($line);
         }
         if ($statsTable->getAggregations()) {
             $tableHelper->addRow($statsTable->getAggregations());
         }
         $tableHelper->render($output);
     }
 }
Esempio n. 3
0
 /**
  * Execute command
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $registry = PlayerRegistry::getDefaultPlayers();
     $player1 = $input->getArgument('player-x');
     $player2 = $input->getArgument('player-o');
     $count = (int) $input->getOption('games');
     $progress = new ProgressHelper();
     $progress->start($output, $count);
     $stats = [PlayerInterface::SYMBOL_X => 0, PlayerInterface::SYMBOL_O => 0, 'Draw' => 0];
     for ($i = 0; $i < $count; $i++) {
         $game = new Game();
         $game->addPlayer($registry->get($player1, PlayerInterface::SYMBOL_X));
         $game->addPlayer($registry->get($player2), PlayerInterface::SYMBOL_O);
         $winner = $game->autoPlay();
         $stats[$winner ? $winner : 'Draw']++;
         $progress->advance();
     }
     $progress->finish();
     $output->writeln('');
     $output->writeln('Winning statistics');
     $table = new TableHelper();
     $table->setHeaders([$player1, $player2, "Draw"]);
     $table->addRow(array_values($stats));
     $table->render($output);
 }
Esempio n. 4
0
 /**
  * Output available imports
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output An output interface
  */
 protected function listImport(OutputInterface $output)
 {
     $table = new TableHelper();
     foreach ((new ImportQuery())->find() as $import) {
         $table->addRow([$import->getRef(), $import->getTitle(), $import->getDescription()]);
     }
     $table->setHeaders(['Reference', 'Title', 'Description'])->render($output);
 }
Esempio n. 5
0
 /**
  * @dataProvider testRenderProvider
  */
 public function testRenderAddRowsOneByOne($headers, $rows, $layout, $expected)
 {
     $table = new TableHelper();
     $table->setHeaders($headers)->setLayout($layout);
     foreach ($rows as $row) {
         $table->addRow($row);
     }
     $table->render($output = $this->getOutputStream());
     $this->assertEquals($expected, $this->getOutputContent($output));
 }
Esempio n. 6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     chdir(__DIR__ . '/../..');
     $table = new TableHelper();
     $table->setHeaders(['Vendor name', 'Ahead', 'Permalink']);
     $vendorRows = array_filter(file('vendors.csv'));
     // Filter out empty rows.
     $githubApi = new GithubClient();
     /** @var Repo $repoApi */
     $repoApi = $githubApi->api('repo');
     if ($input->getOption('username')) {
         $password = $input->getOption('password');
         if (!$password) {
             $q = new Question(sprintf('Please enter the GitHub password for user <comment>%s</comment>:', $input->getOption('username')));
             $q->setHidden(true);
             $q->setValidator(function ($value) {
                 if (empty($value)) {
                     throw new \InvalidArgumentException('You must provide a password');
                 }
             });
             $password = $this->getHelper('question')->ask($input, $output, $q);
         }
         $githubApi->authenticate($input->getOption('username'), $password, GithubClient::AUTH_HTTP_PASSWORD);
     }
     foreach ($vendorRows as $vendorRow) {
         list($vendorName, $repoId, $latestCommitHash) = str_getcsv($vendorRow);
         // Repo ID is in the format author-name/repository-name.
         list($repoAuthor, $repoName) = explode('/', $repoId);
         // This provides us with much information, example: http://pastebin.com/raw.php?i=gkmUS9nU
         $headInfo = $repoApi->commits()->compare($repoAuthor, $repoName, $latestCommitHash, 'HEAD');
         $aheadBy = "<comment>Up to date!</comment>";
         $permalink = "";
         if ($headInfo['ahead_by']) {
             $permalink = $headInfo['permalink_url'];
             $additions = array_sum(array_map(function ($files) {
                 return $files['additions'];
             }, $headInfo['files']));
             $deletions = array_sum(array_map(function ($files) {
                 return $files['deletions'];
             }, $headInfo['files']));
             if ($additions) {
                 $additions = "<comment>+{$additions}</comment>";
             }
             if ($deletions) {
                 $deletions = "<info>-{$deletions}</info>";
             }
             $aheadBy = "<info>{$headInfo['ahead_by']}</info> commits ({$additions}/{$deletions})";
         }
         $table->addRow(["{$vendorName} (<info>{$repoId}</info>)", $aheadBy, $permalink]);
     }
     $table->render($output);
 }
Esempio n. 7
0
 /**
  * @inheritdoc
  */
 public function terminate(ResultCollection $collection, ResultCollection $groupedResults)
 {
     $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true);
     //        $output->write(str_pad("\x0D", 80, "\x20"));
     //        $output->writeln('');
     // overview
     $total = $this->bound->calculate($collection);
     $output->writeln(sprintf('<info>%d</info> files have been analyzed. Read and understand these <info>%s</info> lines of code will take around <info>%s</info>.', sizeof($collection, COUNT_NORMAL), $total->getSum('loc'), $this->formatTime($total->getSum('time'))));
     $output->writeln('<info>Average for each module:</info>');
     $output->writeln('');
     $hasOOP = null !== $total->getSum('instability');
     $table = new TableHelper();
     $table->setHeaders(array_merge(array('Name', 'Complexity', 'Myer Distance', 'Maintainability', 'LLOC', 'Comment weight', 'Vocabulary', 'Volume', 'Bugs', 'Difficulty'), $hasOOP ? array('lcom', 'SysComplexity', 'Instability', 'Abstractness', 'ce', 'ca') : array()))->setLayout(TableHelper::LAYOUT_DEFAULT);
     foreach ($groupedResults as $result) {
         $table->addRow(array_merge(array(str_repeat('  ', $result->getDepth()) . $result->getName(), $this->getRow($result->getBounds(), 'cyclomaticComplexity', 'average', 0), $this->getRow($result->getBounds(), 'myerDistance', 'average', 0), $this->getRow($result->getBounds(), 'maintainabilityIndex', 'average', 0), $this->getRow($result->getBounds(), 'logicalLoc', 'sum', 0), $this->getRow($result->getBounds(), 'commentWeight', 'average', 0), $this->getRow($result->getBounds(), 'vocabulary', 'average', 0), $this->getRow($result->getBounds(), 'volume', 'average', 0), $this->getRow($result->getBounds(), 'bugs', 'sum', 2), $this->getRow($result->getBounds(), 'difficulty', 'average', 0)), $hasOOP ? array($this->getRow($result->getBounds(), 'lcom', 'average', 2), $this->getRow($result->getBounds(), 'rsysc', 'average', 2), $result->getInstability()->getInstability(), $result->getAbstractness()->getAbstractness(), $this->getRow($result->getBounds(), 'efferentCoupling', 'average', 2), $this->getRow($result->getBounds(), 'afferentCoupling', 'average', 2)) : array()));
     }
     $table->render($output);
     return $output->fetch();
 }
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->versionStorage = $this->getContainer()->get('phpcr_migrations.version_storage');
     $this->finder = $this->getContainer()->get('phpcr_migrations.version_finder');
     $versionCollection = $this->finder->getCollection();
     $executedVersions = (array) $this->versionStorage->getPersistedVersions();
     $currentVersion = $this->versionStorage->getCurrentVersion();
     $table = new TableHelper();
     $table->setHeaders(array('', 'Version', 'Date', 'Migrated', 'Path'));
     foreach ($versionCollection->getAllVersions() as $versionName => $versionClass) {
         $reflection = new \ReflectionClass($versionClass);
         $table->addRow(array($versionName == $currentVersion ? '*' : '', $versionName, $this->getDate($versionName), isset($executedVersions[$versionName]) ? '<info>' . $executedVersions[$versionName]['executed']->format('Y-m-d H:i:s') . '</info>' : 'n/a', substr($reflection->getFileName(), strlen(getcwd()) + 1)));
     }
     $table->render($output);
     if ($currentVersion) {
         $output->writeln(sprintf('<info>Current:</info> %s (%s)', $currentVersion, $this->getDate($currentVersion)));
     } else {
         $output->writeln('<info>No migrations have been executed</info>');
     }
 }
 private function processInfo($name, OutputInterface $output)
 {
     $processInfo = $this->supervisor->getProcessInfo($name);
     $tableHelper = new Console\Helper\TableHelper();
     $tableHelper->setHeaders($this->infoHeaders);
     $row = [];
     foreach ($this->infoHeaders as $key) {
         $row[$key] = $processInfo[$key];
     }
     $tableHelper->addRow($row);
     $tableHelper->render($output);
 }
Esempio n. 10
0
 /**
  * @param $issue
  */
 protected function renderIssue($issue)
 {
     $this->tableHelper->addRow(array_intersect_key(array_merge($this->config['displayed-columns'], $issue), $this->config['displayed-columns']));
 }
$output = new ConsoleOutput();
if (count($products) > 0) {
    $output->writeln(sprintf('%s products are in more than one variant group. This is not permitted anymore', count($products)));
    $output->writeln('Products in more than one variant group :');
    $lines = [];
    $tableHelper = new TableHelper();
    $tableHelper->setHeaders(['identifier', 'groups']);
    foreach ($products as $product) {
        $line = [];
        $line['identifier'] = (string) $product->getIdentifier();
        $line['groups'] = [];
        foreach ($product->getGroups() as $group) {
            $line['groups'][] = $group->getCode();
        }
        $lines[] = $line;
        $tableHelper->addRow([$line['identifier'], implode(', ', $line['groups'])]);
    }
    $tableHelper->render($output);
    $dialogHelper = new DialogHelper();
    if ($dialogHelper->askConfirmation($output, 'Would you like to generate a csv file to fix all those products ? (Y,n) ')) {
        $tmpFolder = sys_get_temp_dir();
        $filePath = $tmpFolder . '/invalid_product.csv';
        if (!is_writable($tmpFolder)) {
            throw new \Exception(sprintf('The filepath %s is not writable', $filePath));
        }
        $csv = sprintf("%s;groups\n", $identifierCode);
        foreach ($lines as $line) {
            $csv .= sprintf("%s;%s\n", $line['identifier'], implode(',', $line['groups']));
        }
        file_put_contents($filePath, $csv);
        $output->writeln(sprintf('Generated CSV product import : %s', $filePath));
Esempio n. 12
0
 /**
  * {@inheritdoc}
  */
 protected function describeContainerServices(ContainerBuilder $builder, array $options = array())
 {
     $showPrivate = isset($options['show_private']) && $options['show_private'];
     $showTag = isset($options['tag']) ? $options['tag'] : null;
     if ($showPrivate) {
         $label = '<comment>Public</comment> and <comment>private</comment> services';
     } else {
         $label = '<comment>Public</comment> services';
     }
     if ($showTag) {
         $label .= ' with tag <info>' . $options['tag'] . '</info>';
     }
     $this->writeText($this->formatSection('container', $label) . "\n", $options);
     $serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds();
     $maxTags = array();
     foreach ($serviceIds as $key => $serviceId) {
         $definition = $this->resolveServiceDefinition($builder, $serviceId);
         if ($definition instanceof Definition) {
             // filter out private services unless shown explicitly
             if (!$showPrivate && !$definition->isPublic()) {
                 unset($serviceIds[$key]);
                 continue;
             }
             if ($showTag) {
                 $tags = $definition->getTag($showTag);
                 foreach ($tags as $tag) {
                     foreach ($tag as $key => $value) {
                         if (!isset($maxTags[$key])) {
                             $maxTags[$key] = strlen($key);
                         }
                         if (strlen($value) > $maxTags[$key]) {
                             $maxTags[$key] = strlen($value);
                         }
                     }
                 }
             }
         }
     }
     $tagsCount = count($maxTags);
     $tagsNames = array_keys($maxTags);
     $table = new TableHelper();
     $table->setLayout(TableHelper::LAYOUT_COMPACT);
     $table->setHeaders(array_merge(array('Service ID'), $tagsNames, array('Class name')));
     foreach ($this->sortServiceIds($serviceIds) as $serviceId) {
         $definition = $this->resolveServiceDefinition($builder, $serviceId);
         if ($definition instanceof Definition) {
             if ($showTag) {
                 foreach ($definition->getTag($showTag) as $key => $tag) {
                     $tagValues = array();
                     foreach ($tagsNames as $tagName) {
                         $tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : "";
                     }
                     if (0 === $key) {
                         $table->addRow(array_merge(array($serviceId), $tagValues, array($definition->getClass())));
                     } else {
                         $table->addRow(array_merge(array('  "'), $tagValues, array('')));
                     }
                 }
             } else {
                 $table->addRow(array($serviceId, $definition->getClass()));
             }
         } elseif ($definition instanceof Alias) {
             $alias = $definition;
             $table->addRow(array_merge(array($serviceId, sprintf('alias for "%s"', $alias)), $tagsCount ? array_fill(0, $tagsCount, "") : array()));
         } else {
             // we have no information (happens with "service_container")
             $table->addRow(array_merge(array($serviceId, get_class($definition)), $tagsCount ? array_fill(0, $tagsCount, "") : array()));
         }
     }
     $this->renderTable($table);
 }
Esempio n. 13
0
 /**
  * Output available archivers
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output An output interface
  */
 protected function listArchiver(OutputInterface $output)
 {
     $table = new TableHelper();
     $archiverManager = $this->getContainer()->get(RegisterArchiverPass::MANAGER_SERVICE_ID);
     foreach ($archiverManager->getArchivers(true) as $archiver) {
         $table->addRow([$archiver->getId(), $archiver->getName(), $archiver->getExtension(), $archiver->getMimeType()]);
     }
     $table->setHeaders(['Id', 'Name', 'Extension', 'MIME type'])->render($output);
 }
Esempio n. 14
0
 public function addRow(array $row)
 {
     parent::addRow($row);
     $this->numberOfRows++;
 }
Esempio n. 15
0
 /**
  * {@inheritdoc}
  */
 protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = array())
 {
     $event = array_key_exists('event', $options) ? $options['event'] : null;
     $label = 'Registered listeners';
     if (null !== $event) {
         $label .= sprintf(' for event <info>%s</info>', $event);
     } else {
         $label .= ' by event';
     }
     $this->writeText($this->formatSection('event_dispatcher', $label) . "\n", $options);
     $registeredListeners = $eventDispatcher->getListeners($event);
     if (null !== $event) {
         $this->writeText("\n");
         $table = new TableHelper();
         $table->setHeaders(array('Order', 'Callable'));
         foreach ($registeredListeners as $order => $listener) {
             $table->addRow(array(sprintf('#%d', $order + 1), $this->formatCallable($listener)));
         }
         $this->renderTable($table);
     } else {
         ksort($registeredListeners);
         foreach ($registeredListeners as $eventListened => $eventListeners) {
             $this->writeText(sprintf("\n<info>[Event]</info> %s\n", $eventListened), $options);
             $table = new TableHelper();
             $table->setHeaders(array('Order', 'Callable'));
             foreach ($eventListeners as $order => $eventListener) {
                 $table->addRow(array(sprintf('#%d', $order + 1), $this->formatCallable($eventListener)));
             }
             $this->renderTable($table);
         }
     }
 }