Esempio n. 1
0
 /**
  * Construct an ASCII table to display services.
  *
  * @param  array $services
  * @return TableHelper
  */
 public function buildServiceTable($services)
 {
     $table = new TableHelper();
     $table->setHeaders($this->buildTableHeaders());
     $table->setRows($this->buildTableRows($services));
     return $table;
 }
Esempio n. 2
0
 public function table(TableHelper $table)
 {
     $table->setLayout(TableHelper::LAYOUT_BORDERLESS);
     $table->setCellHeaderFormat('<info>%s</info>');
     $table->setCellRowFormat('%s');
     $table->render($this);
 }
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);
 }
 /**
  * Display all the mapping information for a single Entity.
  *
  * @param string                 $entityName    Full or partial entity class name
  * @param EntityManagerInterface $entityManager
  * @param OutputInterface        $output
  */
 private function displayEntity($entityName, EntityManagerInterface $entityManager, OutputInterface $output)
 {
     $table = new TableHelper();
     $table->setHeaders(array('Field', 'Value'));
     $metadata = $this->getClassMetadata($entityName, $entityManager);
     array_map(array($table, 'addRow'), array_merge(array($this->formatField('Name', $metadata->name), $this->formatField('Root entity name', $metadata->rootEntityName), $this->formatField('Custom generator definition', $metadata->customGeneratorDefinition), $this->formatField('Custom repository class', $metadata->customRepositoryClassName), $this->formatField('Mapped super class?', $metadata->isMappedSuperclass), $this->formatField('Embedded class?', $metadata->isEmbeddedClass), $this->formatField('Parent classes', $metadata->parentClasses), $this->formatField('Sub classes', $metadata->subClasses), $this->formatField('Embedded classes', $metadata->subClasses), $this->formatField('Named queries', $metadata->namedQueries), $this->formatField('Named native queries', $metadata->namedNativeQueries), $this->formatField('SQL result set mappings', $metadata->sqlResultSetMappings), $this->formatField('Identifier', $metadata->identifier), $this->formatField('Inheritance type', $metadata->inheritanceType), $this->formatField('Discriminator column', $metadata->discriminatorColumn), $this->formatField('Discriminator value', $metadata->discriminatorValue), $this->formatField('Discriminator map', $metadata->discriminatorMap), $this->formatField('Generator type', $metadata->generatorType), $this->formatField('Table', $metadata->table), $this->formatField('Composite identifier?', $metadata->isIdentifierComposite), $this->formatField('Foreign identifier?', $metadata->containsForeignIdentifier), $this->formatField('Sequence generator definition', $metadata->sequenceGeneratorDefinition), $this->formatField('Table generator definition', $metadata->tableGeneratorDefinition), $this->formatField('Change tracking policy', $metadata->changeTrackingPolicy), $this->formatField('Versioned?', $metadata->isVersioned), $this->formatField('Version field', $metadata->versionField), $this->formatField('Read only?', $metadata->isReadOnly), $this->formatEntityListeners($metadata->entityListeners)), array($this->formatField('Association mappings:', '')), $this->formatMappings($metadata->associationMappings), array($this->formatField('Field mappings:', '')), $this->formatMappings($metadata->fieldMappings)));
     $table->render($output);
 }
Esempio n. 5
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. 6
0
 /**
  * Display the results of calls in table format
  *
  * @param  TableHelper     $table
  * @param  mixed           $results
  * @param  OutputInterface $output
  *
  * @return string
  */
 public function displayTable(TableHelper $table, $results, OutputInterface $output)
 {
     $table->setHeaders(['Start Time', 'From', 'To', 'Status', 'Call ID']);
     $rows = $this->buildRows($results);
     if (!empty($rows)) {
         $table->setRows($rows);
     }
     $table->render($output);
 }
Esempio n. 7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->table = $this->getHelperSet()->get('table');
     $list = [];
     foreach ($this->laravel->firewall->report() as $ip) {
         $list[] = [$ip['ip_address'], $ip['whitelisted'] == false ? '' : '    X    ', $ip['whitelisted'] == false ? '    X    ' : ''];
     }
     $this->table->setHeaders(['IP Address', 'Whitelist', 'Blacklist'])->setRows($list);
     $this->table->render($this->getOutput());
 }
Esempio n. 8
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));
 }
 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('');
 }
Esempio n. 10
0
 /**
  * Display results in table format.
  *
  * @param $table
  */
 public function displayTable($table)
 {
     $headers = $this->makeHeaders($table[0]);
     $rows = array();
     foreach ($table as $row) {
         $rows[] = (array) $row;
     }
     $this->table = $this->getHelperSet()->get('table');
     $this->table->setHeaders($headers)->setRows($rows);
     $this->table->render($this->getOutput());
 }
Esempio n. 11
0
 /**
  * Renders a table of all errored entities
  */
 public function render()
 {
     $this->output->writeln('');
     $this->output->writeln('<info>Errors:</info>');
     $rows = array();
     foreach ($this->errors as $error) {
         $rows[] = array($error->getEntity(), $error->getResultId(), $error->getMessage());
     }
     $this->tableHelperSet->setHeaders(array('Entity', 'ID', 'Error'))->setRows($rows);
     $this->tableHelperSet->render($this->output);
 }
Esempio n. 12
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $request = new Request(Query::parse($input->getArgument('query')), $input->getArgument('index'), $input->getArgument('host'));
     $output->writeln('<info>Start benchmarking</info>');
     $output->writeln('');
     $result = (new Client($input->getOption('clear')))->execute($request, (int) $input->getOption('count'), $output);
     $output->writeln('');
     $table = new TableHelper();
     $table->setHeaders(['Field', 'Value']);
     $table->addRows($result->toArray());
     $table->render($output);
 }
 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. 14
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. 15
0
 private function listConfig(InputInterface $input, OutputInterface $output)
 {
     $output->writeln(["", "<error>Variables list</error>", ""]);
     $vars = ConfigQuery::create()->orderByName()->find();
     $rows = [];
     /** @var Config $var */
     foreach ($vars as $var) {
         $rows[] = [$var->getName(), $var->getValue(), $var->getSecured() !== 0 ? "yes" : "no", $var->getHidden() !== 0 ? "yes" : "no"];
     }
     $table = new TableHelper();
     $table->setHeaders(['Name', 'Value', 'secured', 'hidden'])->setRows($rows);
     $table->render($output);
 }
Esempio n. 16
0
 /**
  * Writes content to output.
  *
  * @param TableHelper $table
  * @param bool        $decorated
  */
 protected function renderTable(TableHelper $table, $decorated = false)
 {
     if (!$decorated) {
         $table->setCellRowFormat('%s');
         $table->setCellHeaderFormat('%s');
     }
     $table->render($this->output);
 }
Esempio n. 17
0
 /**
  * @param OutputInterface $output
  */
 public function render(OutputInterface $output)
 {
     if (empty($this->issues)) {
         return;
     }
     foreach ($this->issues as $file => $issues) {
         $output->writeln(PHP_EOL . $file);
         $this->tableHelper->setHeaders($this->config['displayed-columns']);
         foreach ($issues as $issue) {
             if (empty($this->config['displayed-columns']['source']) || empty($issue['source'])) {
                 $this->renderIssue($issue);
             } else {
                 $this->renderIssueWithSource($issue);
             }
         }
         $this->tableHelper->render($output);
         $this->tableHelper->setRows(array());
     }
 }
Esempio n. 18
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>');
     }
 }
Esempio n. 20
0
 /** {@inheritdoc} */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $srcHost = $input->getArgument(self::ATTR_HOST);
     $srcPort = $input->getOption(self::OPT_PORT);
     $sort = $input->getOption(self::OPT_SORT);
     $order = $input->getOption(self::OPT_ORDER);
     $noZeros = $input->getOption(self::OPT_NO_ZEROS);
     $columns = ['name' => 'name', 'current-jobs-ready' => 'ready', 'current-jobs-reserved' => 'reserved', 'current-jobs-delayed' => 'delayed', 'current-jobs-buried' => 'buried'];
     $src = new Pheanstalk($srcHost, $srcPort);
     $table = new TableHelper(false);
     $table->setLayout(TableHelper::LAYOUT_BORDERLESS);
     $table->setHeaders($columns);
     $tubeNames = $src->listTubes();
     ksort($tubeNames);
     $data = [];
     foreach ($tubeNames as $tube) {
         /** @var ArrayResponse $response */
         $response = $src->statsTube($tube);
         $tubeData = $response->getArrayCopy();
         $tubeData = array_intersect_key($tubeData, $columns);
         if ($noZeros) {
             foreach ($tubeData as $key => $value) {
                 if ('0' === $value) {
                     $tubeData[$key] = '';
                 }
             }
         }
         $data[] = $tubeData;
     }
     $column = array_search($sort, $columns);
     uasort($data, function (array $a1, array $a2) use($column, $order) {
         return strnatcmp($a1[$column], $a2[$column]) * $order;
     });
     $table->addRows($data);
     $table->render($output);
 }
Esempio n. 21
0
    public function testRenderMultiByte()
    {
        if (!function_exists('mb_strlen')) {
            $this->markTestSkipped('The "mbstring" extension is not available');
        }
        $table = new TableHelper();
        $table->setHeaders(array('■■'))->setRows(array(array(1234)))->setLayout(TableHelper::LAYOUT_DEFAULT);
        $table->render($output = $this->getOutputStream());
        $expected = <<<TABLE
+------+
| ■■   |
+------+
| 1234 |
+------+

TABLE;
        $this->assertEquals($expected, $this->getOutputContent($output));
    }
Esempio n. 22
0
 /**
  * Set TableHelper properties with Authors
  * 
  * @param \Symfony\Component\Console\Helper\TableHelper $table
  */
 public function authors(TableHelper &$table)
 {
     $fields = array('Name', 'Hands on', 'Link', 'E-mail');
     $authors = array(array('Renato Mendes Figueiredo', 'First Developer', 'http://br.linkedin.com/in/renatomefidf', '*****@*****.**'));
     $table->setHeaders($fields)->setRows($authors);
 }
Esempio n. 23
0
 /**
  * Display the route information on the console.
  *
  * @param  array  $routes
  * @return void
  */
 protected function displayRoutes(array $routes)
 {
     $headers = array('Domain', 'URI', 'Name', 'Action', 'Before Filters', 'After Filters');
     $this->table->setHeaders($headers)->setRows($routes);
     $this->table->render($this->getOutput());
 }
Esempio n. 24
0
    /**
     * @requires extension mbstring
     */
    public function testRenderFullWidthCharacters()
    {
        $table = new TableHelper();
        $table->setHeaders(array('あいうえお'))->setRows(array(array(1234567890)))->setLayout(TableHelper::LAYOUT_DEFAULT);
        $table->render($output = $this->getOutputStream());
        $expected = <<<'TABLE'
+------------+
| あいうえお |
+------------+
| 1234567890 |
+------------+

TABLE;
        $this->assertEquals($expected, $this->getOutputContent($output));
    }
 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. 26
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. 27
0
 /**
  * Display the route information on the console.
  *
  * @param  array  $routes
  * @return void
  */
 protected function displayRoutes(array $routes)
 {
     $this->table->setHeaders($this->headers)->setRows($routes);
     $this->table->render($this->getOutput());
 }
Esempio n. 28
0
 /**
  * @param array $headers
  * @return $this
  */
 public function setHeaders(array $headers)
 {
     $this->headers = array_values($headers);
     parent::setHeaders($headers);
     return $this;
 }
        $selectedProducts = $productCollection->aggregate([['$unwind' => '$groupIds'], ['$match' => ['groupIds' => ['$in' => $variantGroupIds]]], ['$group' => ['_id' => '$normalizedData.' . $identifierCode, 'variant_count' => ['$sum' => 1]]], ['$match' => ['variant_count' => ['$gt' => 1]]]])['result'];
        $productIdentifiers = [];
        foreach ($selectedProducts as $product) {
            $productIdentifiers[] = $product['_id'];
        }
        $products = $container->get('pim_catalog.doctrine.query.product_query_factory')->create()->addFilter($identifierCode, 'IN', $productIdentifiers)->execute();
        break;
    default:
        throw new \LogicException(sprintf('Unknown storage driver %s (supported storage drivers : doctrine/orm and doctrine/mongodb-odm)', $storageDriver));
}
$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();
    public function testRenderFullWidthCharacters()
    {
        if (!function_exists('mb_strwidth')) {
            $this->markTestSkipped('The "mbstring" extension is not available');
        }
        $table = new TableHelper();
        $table->setHeaders(array('あいうえお'))->setRows(array(array(1234567890)))->setLayout(TableHelper::LAYOUT_DEFAULT);
        $table->render($output = $this->getOutputStream());
        $expected = <<<TABLE
+------------+
| あいうえお |
+------------+
| 1234567890 |
+------------+

TABLE;
        $this->assertEquals($expected, $this->getOutputContent($output));
    }