<commit_before><?php
/**
 * @file
 * Contains \Drupal\AppConsole\Command\RouterDebugCommand.
 */

namespace Drupal\AppConsole\Command;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class RouterDebugCommand extends ContainerAwareCommand
{

  protected function configure()
  {
    $this
      ->setName('router:debug')
      ->setDescription('Displays current routes for an application')
      ->addArgument('route-name', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Route names')
    ;
  }

  protected function execute(InputInterface $input, OutputInterface $output)
  {
    $route_name = $input->getArgument('route-name');
    $table = $this->getHelperSet()->get('table');
    $table->setlayout($table::LAYOUT_COMPACT);
    if ($route_name) {
      $this->getRouteByNames($route_name, $output, $table);
    }
    else {
      $this->getAllRoutes($output, $table);
    }
  }

  protected function getAllRoutes($output, $table)
  {
    $rp = $this->getRouteProvider();
    $routes  = $rp->getAllRoutes();

    $table->setHeaders(['Name', 'Path']);
    $table->setlayout($table::LAYOUT_COMPACT);
    foreach ($routes as $route_name => $route) {
      $table->addRow([$route_name, $route->getPath()]);
    }
    $table->render($output);
  }

  protected function getRouteByNames($route_name, $output, $table)
  {
    $rp = $this->getRouteProvider();
    $routes = $rp->getRoutesByNames($route_name);
    $table->setHeaders(['Route name', 'Options']);
    $table->setlayout(TableHelper::LAYOUT_BORDERLESS);

    $rows = [];
    foreach ($routes as $name => $route) {
      $table->addRow(['<info>'.$name.'</info>']);
      $table->addRow([' <comment>+ Pattern</comment>', $route->getPath()]);

      $table->addRow([' <comment>+ Defaults</comment>']);
      $table = $this->addRouteAttributes($route->getDefaults(), $table);

      $table->addRow([' <comment>+ Options</comment>']);
      $table = $this->addRouteAttributes($route->getOptions(), $table);
    }
    $table->render($output);<commit_msg>Update table Layout<commit_after><?php
/**
 * @file
 * Contains \Drupal\AppConsole\Command\RouterDebugCommand.
 */

namespace Drupal\AppConsole\Command;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class RouterDebugCommand extends ContainerAwareCommand
{

  protected function configure()
  {
    $this
      ->setName('router:debug')
      ->setDescription('Displays current routes for an application')
      ->addArgument('route-name', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Route names')
    ;
  }

  protected function execute(InputInterface $input, OutputInterface $output)
  {
    $route_name = $input->getArgument('route-name');
    $table = $this->getHelperSet()->get('table');
    $table->setlayout($table::LAYOUT_COMPACT);
    if ($route_name) {
      $this->getRouteByNames($route_name, $output, $table);
    }
    else {
      $this->getAllRoutes($output, $table);
    }
  }

  protected function getAllRoutes($output, $table)
  {
    $rp = $this->getRouteProvider();
    $routes  = $rp->getAllRoutes();

    $table->setHeaders(['Name', 'Path']);
    $table->setlayout($table::LAYOUT_COMPACT);
    foreach ($routes as $route_name => $route) {
      $table->addRow([$route_name, $route->getPath()]);
    }
    $table->render($output);
  }

  protected function getRouteByNames($route_name, $output, $table)
  {
    $rp = $this->getRouteProvider();
    $routes = $rp->getRoutesByNames($route_name);
    $table->setHeaders(['Route name', 'Options']);
    $table->setlayout($table::LAYOUT_COMPACT);

    $rows = [];
    foreach ($routes as $name => $route) {
      $table->addRow(['<info>'.$name.'</info>']);
      $table->addRow([' <comment>+ Pattern</comment>', $route->getPath()]);

      $table->addRow([' <comment>+ Defaults</comment>']);
      $table = $this->addRouteAttributes($route->getDefaults(), $table);

      $table->addRow([' <comment>+ Options</comment>']);
      $table = $this->addRouteAttributes($route->getOptions(), $table);
    }
    $table->render($output);
{'fraction_non_alphanumeric': 0.18304204062352386, 'fraction_numerical': 0.0, 'mean_word_length': 4.221948212083847, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4872810', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1322, 'n_words': 215}