|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Brendt\Stitcher\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Brendt\Stitcher\Stitcher; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
class RouterListCommand extends Command |
|
12
|
|
|
{ |
|
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
|
|
|
if ($filter) { |
|
35
|
|
|
$output->writeln("Available routes (filtered by <fg=green>{$filter}</>):\n"); |
|
36
|
|
|
} else { |
|
37
|
|
|
$output->writeln("Available routes:\n"); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
foreach ($site as $route => $page) { |
|
41
|
|
|
if ($filter && strpos($route, $filter) === false) { |
|
42
|
|
|
continue; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$data = []; |
|
46
|
|
|
|
|
47
|
|
|
if (isset($page['data'])) { |
|
48
|
|
|
$data = array_keys($page['data']); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$line = "- <fg=green>{$route}</>: {$page['template']}.tpl"; |
|
52
|
|
|
|
|
53
|
|
|
if ($data) { |
|
|
|
|
|
|
54
|
|
|
$line .= "\n\t"; |
|
55
|
|
|
$line .= '$' . implode(', $', $data); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$output->writeln($line); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.