1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Brendt\Stitcher\Command; |
4
|
|
|
|
5
|
|
|
use Brendt\Stitcher\Config; |
6
|
|
|
use Brendt\Stitcher\Stitcher; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
class RoutesCommand extends Command { |
13
|
|
|
|
14
|
|
|
const FILTER = 'filter'; |
15
|
|
|
|
16
|
|
|
protected function configure() { |
17
|
|
|
$this->setName('router:list') |
18
|
|
|
->setDescription('Show the available routes') |
19
|
|
|
->setHelp("This command shows the available routes.") |
20
|
|
|
->addArgument(self::FILTER, InputArgument::OPTIONAL, 'Specify a filter'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param InputInterface $input |
25
|
|
|
* @param OutputInterface $output |
26
|
|
|
* |
27
|
|
|
* @return int|null|void |
28
|
|
|
*/ |
29
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
30
|
|
|
Config::load(); |
31
|
|
|
$stitcher = new Stitcher(); |
32
|
|
|
$site = $stitcher->loadSite(); |
33
|
|
|
$filter = $input->getArgument(self::FILTER); |
34
|
|
|
|
35
|
|
|
if ($filter) { |
36
|
|
|
$output->writeln("Available routes (filtered by <fg=green>{$filter}</>):\n"); |
37
|
|
|
} else { |
38
|
|
|
$output->writeln("Available routes:\n"); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
foreach ($site as $route => $page) { |
42
|
|
|
if ($filter && strpos($route, $filter) === false) { |
43
|
|
|
continue; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$data = []; |
47
|
|
|
|
48
|
|
|
if (isset($page['data'])) { |
49
|
|
|
$data = array_keys($page['data']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$line = "- <fg=green>{$route}</>: {$page['template']}.tpl"; |
53
|
|
|
|
54
|
|
|
if (count($data)) { |
55
|
|
|
$line .= "\n\t"; |
56
|
|
|
$line .= '$' . implode(', $', $data); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$output->writeln($line); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|