Skip to content

Commit 2775c4b

Browse files
authored
Added "routes" command
1 parent b15d8e9 commit 2775c4b

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* UserFrosting (http://www.userfrosting.com)
4+
*
5+
* @link https://github.com/userfrosting/UserFrosting
6+
* @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
7+
*/
8+
namespace UserFrosting\System\Bakery\Command;
9+
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Output\OutputInterface;
12+
use Symfony\Component\Console\Input\InputArgument;
13+
use Symfony\Component\Console\Input\InputOption;
14+
use UserFrosting\System\Bakery\BaseCommand;
15+
16+
use Slim\App;
17+
use Slim\Container;
18+
19+
/**
20+
* Generate a list of a projects routes.
21+
*
22+
* @author Jose Vasconcellos
23+
*/
24+
class Routes extends BaseCommand
25+
{
26+
/**
27+
* @var string Path to the build/ directory
28+
*/
29+
protected $app;
30+
31+
/**
32+
* {@inheritDoc}
33+
*/
34+
protected function configure()
35+
{
36+
$this->setName("routes")
37+
->setDescription("Dumps all routes.");
38+
}
39+
40+
/**
41+
* {@inheritDoc}
42+
*/
43+
protected function execute(InputInterface $input, OutputInterface $output)
44+
{
45+
global $app;
46+
47+
$this->ci->settings = $this->ci->config['settings'];
48+
$this->app = new App($this->ci);
49+
$app = $this->app;
50+
51+
$this->io->title("Generate routes");
52+
$routePaths = array_reverse($this->ci->locator->findResources('routes://', true, true));
53+
$routeDirCount=count($routePaths);
54+
$routeCount=0;
55+
foreach ($routePaths as $path) {
56+
$routeFiles = glob($path . '/*.php');
57+
foreach ($routeFiles as $routeFile) {
58+
$routeCount += 1;
59+
//$this->io->writeln("<info>$routeFile</info>");
60+
require_once $routeFile;
61+
}
62+
}
63+
64+
$allRoutes = $app->getContainer()->get('router')->getRoutes();
65+
foreach ($allRoutes as $route) {
66+
$p = $route->getPattern();
67+
foreach ($route->getMethods() as $m)
68+
$this->io->writeln($m.' '.$p);
69+
}
70+
71+
$this->io->success("Routes generated from {$routeCount} files!");
72+
}
73+
}

0 commit comments

Comments
 (0)