Skip to content

Commit 7c13418

Browse files
authored
Merge pull request #903 from apple314159/apple314159-routes
Add bakery routes
2 parents c1fc189 + 2fb8367 commit 7c13418

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
use Slim\App;
16+
use Slim\Container;
17+
18+
/**
19+
* Generate a list of a projects routes.
20+
*
21+
* @author Jose Vasconcellos
22+
*/
23+
class RouteListCommand extends BaseCommand
24+
{
25+
/**
26+
* @var string Path to the build/ directory
27+
*/
28+
protected $app;
29+
30+
/**
31+
* {@inheritDoc}
32+
*/
33+
protected function configure()
34+
{
35+
$this->setName("route:list")
36+
->setDescription("Dumps all routes.");
37+
}
38+
39+
/**
40+
* {@inheritDoc}
41+
*/
42+
protected function execute(InputInterface $input, OutputInterface $output)
43+
{
44+
global $app;
45+
46+
$this->ci->settings = $this->ci->config['settings'];
47+
$this->app = new App($this->ci);
48+
$app = $this->app;
49+
50+
$this->io->title("Generate routes");
51+
$routePaths = array_reverse($this->ci->locator->findResources('routes://', true, true));
52+
$routeCount=0;
53+
foreach ($routePaths as $path) {
54+
$routeFiles = glob($path . '/*.php');
55+
foreach ($routeFiles as $routeFile) {
56+
$routeCount += 1;
57+
//$this->io->writeln("<info>$routeFile</info>");
58+
require_once $routeFile;
59+
}
60+
}
61+
62+
$allRoutes = $app->getContainer()->get('router')->getRoutes();
63+
foreach ($allRoutes as $route) {
64+
$p = $route->getPattern();
65+
foreach ($route->getMethods() as $m)
66+
$this->io->writeln($m.' '.$p);
67+
}
68+
69+
$this->io->success("Routes generated from {$routeCount} files!");
70+
}
71+
}

0 commit comments

Comments
 (0)