1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Brendt\Stitcher\Command; |
4
|
|
|
|
5
|
|
|
use Brendt\Stitcher\Site\Page; |
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 RouterListCommand 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 void |
28
|
|
|
*/ |
29
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
30
|
|
|
$stitcher = Stitcher::create(); |
31
|
|
|
$site = $stitcher->loadSite(); |
32
|
|
|
$filter = $input->getArgument(self::FILTER); |
33
|
|
|
|
34
|
|
|
$output->writeln("Found routes:"); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string $route |
38
|
|
|
* @var Page $page |
39
|
|
|
*/ |
40
|
|
|
foreach ($site as $route => $page) { |
41
|
|
|
if ($filter && strpos($page->getId(), $filter) === false) { |
42
|
|
|
continue; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$output->writeln("- <fg=green>{$page->getId()}</>: {$page->getTemplatePath()}.tpl"); |
46
|
|
|
|
47
|
|
|
foreach ($page->getVariables() as $variable => $value) { |
48
|
|
|
$output->writeln("\t\${$variable}: {$value}"); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|