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
|
|
|
/** |
17
|
|
|
* @var Stitcher |
18
|
|
|
*/ |
19
|
|
|
private $stitcher; |
20
|
|
|
|
21
|
|
|
public function __construct(string $configPath = './config.yml', array $defaultConfig = []) { |
22
|
|
|
parent::__construct(); |
23
|
|
|
|
24
|
|
|
$this->stitcher = Stitcher::create($configPath, $defaultConfig); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function configure() { |
28
|
|
|
$this->setName('router:list') |
29
|
|
|
->setDescription('Show the available routes') |
30
|
|
|
->setHelp("This command shows the available routes.") |
31
|
|
|
->addArgument(self::FILTER, InputArgument::OPTIONAL, 'Specify a filter'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param InputInterface $input |
36
|
|
|
* @param OutputInterface $output |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
41
|
|
|
$site = $this->stitcher->loadSite(); |
42
|
|
|
$filter = $input->getArgument(self::FILTER); |
43
|
|
|
|
44
|
|
|
$output->writeln("Found routes:"); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string $route |
48
|
|
|
* @var Page $page |
49
|
|
|
*/ |
50
|
|
|
foreach ($site as $route => $page) { |
51
|
|
|
if ($filter && strpos($page->getId(), $filter) === false) { |
52
|
|
|
continue; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$output->writeln("- <fg=green>{$page->getId()}</>: {$page->getTemplatePath()}.tpl"); |
56
|
|
|
|
57
|
|
|
foreach ($page->getVariables() as $variable => $value) { |
58
|
|
|
$output->writeln("\t\${$variable}: {$value}"); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|