Skip to content

Commit cb5a8de

Browse files
committed
feature #5 Add a warning when no routes are defined (fabpot)
This PR was squashed before being merged into the master branch (closes #5). Discussion ---------- Add a warning when no routes are defined ![image](https://user-images.githubusercontent.com/47313/32694414-ebd6fbe8-c6f3-11e7-8ec4-58088685a820.png) Commits ------- 2c2917f simplified some code 31c6606 added a warning when no routes are defined
2 parents afcb4be + 2c2917f commit cb5a8de

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Command/AbstractCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
111111
$params = $this->getParameters();
112112
$this->generator->generate($params, $this->getFiles($params));
113113

114-
$this->io->writeln('');
114+
$this->io->newLine();
115115
$this->io->writeln(' <bg=green;fg=white> </>');
116116
$this->io->writeln(' <bg=green;fg=white> Success! </>');
117117
$this->io->writeln(' <bg=green;fg=white> </>');
118-
$this->io->writeln('');
118+
$this->io->newLine();
119119

120120
$this->writeNextStepsMessage($params, $this->io);
121121
}

src/Command/MakeControllerCommand.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313

1414
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1515
use Symfony\Bundle\MakerBundle\DependencyBuilder;
16+
use Symfony\Bundle\MakerBundle\Generator;
1617
use Symfony\Bundle\MakerBundle\Str;
1718
use Symfony\Bundle\MakerBundle\Validator;
1819
use Symfony\Component\Console\Input\InputArgument;
1920
use Symfony\Component\Console\Input\InputInterface;
2021
use Symfony\Component\Console\Output\OutputInterface;
22+
use Symfony\Component\Routing\RouterInterface;
2123
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
2224

2325
/**
@@ -28,6 +30,15 @@ final class MakeControllerCommand extends AbstractCommand
2830
{
2931
protected static $defaultName = 'make:controller';
3032

33+
private $router;
34+
35+
public function __construct(Generator $generator, RouterInterface $router)
36+
{
37+
$this->router = $router;
38+
39+
parent::__construct($generator);
40+
}
41+
3142
public function configure()
3243
{
3344
$this
@@ -63,6 +74,11 @@ protected function getResultMessage(array $params): string
6374

6475
protected function writeNextStepsMessage(array $params, ConsoleStyle $io)
6576
{
77+
if (!count($this->router->getRouteCollection())) {
78+
$io->text('<error> Warning! </> No routes configuration defined yet.');
79+
$io->text(' You should probably uncomment the annotation routes in <comment>config/routes.yaml</>');
80+
$io->newLine();
81+
}
6682
$io->text('Next: Open your new controller class and add some pages!');
6783
}
6884

0 commit comments

Comments
 (0)