<commit_before><?php
/**
 * Created by PhpStorm.
 * User: janhuang
 * Date: 15/3/18
 * Time: 下午4:32
 * Github: https://www.github.com/janhuang 
 * Coding: https://www.coding.net/janhuang
 * SegmentFault: http://segmentfault.com/u/janhuang
 * Blog: http://segmentfault.com/blog/janhuang
 * Gmail: <EMAIL>
 */

namespace Kernel\Commands;

use Dobee\Console\Commands\Command;
use Dobee\Console\Format\Input;
use Dobee\Console\Format\Output;
use Dobee\Routing\Router;

class RouteDump extends Command
{
    /**
     * @return string
     */
    public function getName()
    {
        return 'route:dump';
    }

    /**
     * @return void|$this
     */
    public function configure()
    {
        $this
            ->setArguments('route', null)
            ->setDescription('Thank for you use routing dump tool.')
        ;
    }

    /**
     * @param Input  $input
     * @param Output $output
     * @return void
     */
    public function execute(Input $input, Output $output)
    {
        $router = \Routes::getRouter();

        $output->writeln('');

        if ('' == $input->get('route')) {
            $this->showRouteCollections($router, $output);
        } else {
            $route = $router->getRoute($input->get('route'));
            $output->write('Route [');
            $output->write('"' . $input->get('route') . '"', Output::STYLE_SUCCESS);
            $output->writeln(']');
            $output->writeln("Name:\t\t" . $route->getName());
            $output->writeln("Group:\t\t" . str_replace('//', '/', $route->getGroup()));
            $output->writeln("Path:\t\t" . $route->getPath());
            $output->writeln("Method:\t\t" . implode(', ', $route->getMethods()));
            $output->writeln("Format:\t\t" . implode(', ', $route->getFormats()));
            $output->writeln("Callback:\t" . (is_callable($route->getCallback()) ? 'Closure' : $route->getCallback()));
            $output->writeln("Defaults:\t" . implode(', ', $route->getDefaults()));
            $output->writeln("Requirements:\t" . implode(', ', $route->getRequirements()));
            $output->writeln("Path-Regex:\t" . $route->getPathRegex());
        }

        $output->writeln('');
    }

    public function showRouteCollections(Router $router, Output $output)
    {
        $length = 30;
        $output->writeln("Name" . str_repeat(' ', 26) . "Method" . str_repeat(' ', 24) . "Group" . str_repeat(' ', 25) . "Path", Output::STYLE_SUCCESS);
        foreach ($router->getCollections() as $name => $route) {
            $method = implode(', ', $route->getMethods());
            $group = str_replace('//', '/', $route->getGroup());
            $group = empty($group) ? '/' : $group;
            $output->writeln(
                $route->getName() . str_repeat(' ', ($length - strlen($route->getName()))) .
                $method . str_repeat(' ', ($length - strlen($method))) .
                $group . str_repeat(' ', ($length - strlen($group))) .
                $route->getPath()
            );
        }
    }
}<commit_msg>fix route dump command double path bug<commit_after><?php
/**
 * Created by PhpStorm.
 * User: janhuang
 * Date: 15/3/18
 * Time: 下午4:32
 * Github: https://www.github.com/janhuang 
 * Coding: https://www.coding.net/janhuang
 * SegmentFault: http://segmentfault.com/u/janhuang
 * Blog: http://segmentfault.com/blog/janhuang
 * Gmail: <EMAIL>
 */

namespace Kernel\Commands;

use Dobee\Console\Commands\Command;
use Dobee\Console\Format\Input;
use Dobee\Console\Format\Output;
use Dobee\Routing\Router;

class RouteDump extends Command
{
    /**
     * @return string
     */
    public function getName()
    {
        return 'route:dump';
    }

    /**
     * @return void|$this
     */
    public function configure()
    {
        $this
            ->setArguments('route', null)
            ->setDescription('Thank for you use routing dump tool.')
        ;
    }

    /**
     * @param Input  $input
     * @param Output $output
     * @return void
     */
    public function execute(Input $input, Output $output)
    {
        $router = \Routes::getRouter();

        $output->writeln('');

        if ('' == $input->get('route')) {
            $this->showRouteCollections($router, $output);
        } else {
            $route = $router->getRoute($input->get('route'));
            $output->write('Route [');
            $output->write('"' . $input->get('route') . '"', Output::STYLE_SUCCESS);
            $output->writeln(']');
            $output->writeln("Name:\t\t" . $route->getName());
            $output->writeln("Group:\t\t" . str_replace('//', '/', $route->getGroup()));
            $output->writeln("Path:\t\t" . $route->getPath());
            $output->writeln("Method:\t\t" . implode(', ', $route->getMethods()));
            $output->writeln("Format:\t\t" . implode(', ', $route->getFormats()));
            $output->writeln("Callback:\t" . (is_callable($route->getCallback()) ? 'Closure' : $route->getCallback()));
            $output->writeln("Defaults:\t" . implode(', ', $route->getDefaults()));
            $output->writeln("Requirements:\t" . implode(', ', $route->getRequirements()));
            $output->writeln("Path-Regex:\t" . $route->getPathRegex());
        }

        $output->writeln('');
    }

    public function showRouteCollections(Router $router, Output $output)
    {
        $length = 30;
        $output->writeln("Name" . str_repeat(' ', 26) . "Method" . str_repeat(' ', 24) . "Group" . str_repeat(' ', 25) . "Path", Output::STYLE_SUCCESS);
        foreach ($router->getCollections() as $name => $route) {
            $method = implode(', ', $route->getMethods());
            $group = str_replace('//', '/', $route->getGroup());
            $group = empty($group) ? '/' : $group;
            $output->writeln(
                $route->getName() . str_repeat(' ', ($length - strlen($route->getName()))) .
                $method . str_repeat(' ', ($length - strlen($method))) .
                str_replace('//', '/', $group . str_repeat(' ', ($length - strlen($group)))) .
                $route->getPath()
            );
        }
    }
}
{'fraction_non_alphanumeric': 0.20281091681647329, 'fraction_numerical': 0.0052296126818107535, 'mean_word_length': 2.2867883995703546, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 85, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '6064365', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1861, 'n_words': 323}